Search code examples
gitgithub-actionsflutter-dependenciesworkflow

My workflow is triggered on push but it is picking wrong branch


i am working on a workflow to build and share ios app to testflight. i have set the trigger point:

on:
  push:
    branches:
      - feature/prod_ios_workflow

but i have noticed this workflow is running on main branch code.

main branch contains the old code and dependencies in the pubspec.yaml file. while feature/prod_ios_workflow branch contains the latest code and dependencies versions.

for instance: the pubspec.yaml file in the feature/prod_ios_workflow branch does not have flutter_localizations package but the pubspec.yaml file in main branch has this dependency.

now i removed that dependency because i was not using it anymore and it was conflicting with other packages.

in my workflow i am doing

flutter clean
flutter pub get

so it fails on flutter pub get stating that flutter_localization packages needs latest version of intl package.

i spent a lot of time to check what is going wrong down there. and eventually i used

- name: Remove flutter_localization
        run: flutter pub remove flutter_localizations

to remove the package for solving this conflict.

now another problem arises when build was being generated.

in feature/prod_ios_workflow branch i have: screenshot:^3.0.0 but in the main branch:

screenshot:^2.1.0

when i upgraded the flutter sdk, i had some errors from the screenshot package, so i also updated the screenshot package from 2.1.0 to 3.0.0 and it solved the issue in my IDE.

so i know why build is failing because latest flutter sdk requires screenshot:^3.0.0

but what i dont get is i am on feature/prod_ios_workflow branch and workflow is supposed to run on the code of this branch. but it is taking the code from main branch.( which is totally insane.)

any help would be highly appreciated.


Solution

  • After spending so much time on this, i found out the cause of the problem.

    - name: Set up git and fetch all history for all branches and tags
            uses: actions/checkout@v4
            with:
              ref: main
    

    I just had to replace the main with feature/prod_ios_workflow like this:

    - name: Set up git and fetch all history for all branches and tags
                uses: actions/checkout@v4
                with:
                  ref: feature/prod_ios_workflow
    

    Or you can simple remove the with part like this:

    - name: Set up git and fetch all history for all branches and tags
                uses: actions/checkout@v4