Search code examples
fluttergithub-actionssubdirectory

How would I setup github actions for a flutter project in a subdirectory


I am working on github actions for ci/cd in flutter. The code is a subdirectory to the main repository folder. How would I run the github action in the subdirectory.

I am making use of the subosito flutter action

      - uses: subosito/flutter-action@v2
        with:
          channel: 'stable'
      - run: flutter pub get
      - run: flutter test
      - run: flutter build appbundle

Solution

  • Solution 1

    run accepts a keyword named working-directory. Just set it to the subdirectory and you're good to go. It's going to be something like this:

          - run: flutter pub get
            working-directory: your_subdirectory
          - run: flutter test
            working-directory: your_subdirectory
          - run: flutter build appbundle
            working-directory: your_subdirectory
    

    Solution 2

    It's also possible to set it per job (jobs.<job_id>.defaults.run) like so:

    jobs:
      job1:
        runs-on: ubuntu-latest
        defaults:
          run:
            working-directory: your_subdirectory
    

    Solution 3

    You can also use defaults.run to set the default directory globally (for all jobs) as the subdirectory you expect. This way you'd remove a lot of repetition.

    defaults:
      run:
        working-directory: your_subdirectory