subosito / flutter-action

Flutter environment for use in GitHub Actions. It works on Linux, Windows, and macOS.
MIT License
2.21k stars 197 forks source link

Using Flutter within other GitHub Action does not work #320

Open Friesenjung opened 1 month ago

Friesenjung commented 1 month ago

Hello there,

I am trying to set up the GitHub Action pipeline to check our codebase through flutter test with coverage and flutter analyze.

Within the Workflow I want to use SonarQube. I have installed the SonarQube Flutter Plugin. My yml file looks like the following:

sonar-scanner: needs: [ flutter-analysis ] runs-on: ubuntu-latest steps:

  • uses: actions/checkout@v4
  • name: Set up Flutter SDK uses: subosito/flutter-action@v2 with: channel: stable flutter-version-file: pubspec.yaml
  • name: Download Test Results uses: actions/download-artifact@v4 with: name: test-results.json
  • name: Download Coverage Results uses: actions/download-artifact@v4 with: name: coverage.LCOV
  • uses: dart-lang/setup-dart@v1
  • name: SonarQube Scan uses: sonarsource/sonarqube-scan-action@v2.1.0 env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }}
  • name: SonarQube Quality Gate check id: sonarqube-quality-gate-check uses: sonarsource/sonarqube-quality-gate-action@master

    Force to fail step after specific time.

    timeout-minutes: 1
    env:
      SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
      SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }}

During the SonarQube execution a get an error, saying that command flutter cannot be found: org.buildobjects.process.StartupException: Could not startup process 'flutter analyze --no-fatal-warnings --no-fatal-infos'. ... Caused by: java.io.IOException: Cannot run program "flutter" (in directory "/github/workspace"): error=2, No such file or directory

It seems that the command flutter is not installed as it would be installed if I am running the installation on a native server. My question is, is there anything I can do to make the flutter command available to SonarQube using this action? Thanks in advance!

yurikoles commented 1 month ago

It seems like the flutter binary is pruned from PATH by subsequent actions. Could you please try to move Flutter setup action to the bottom, just before the latest one?

In order to debug, you may run: echo $PATH on each step and type -a flutter in each step after setting up the Flutter.

Friesenjung commented 1 month ago

Thanks for the quick answer. This is the output directly after the "Set Up Flutter SDK": 0s

Run echo $PATH

/home/runner/.pub-cache/bin:/opt/hostedtoolcache/flutter/stable-3.22.2-x64/bin/cache/dart-sdk/bin:/opt/hostedtoolcache/flutter/stable-3.22.2-x64/bin:/snap/bin:/home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin 1s Run type -a flutter flutter is /opt/hostedtoolcache/flutter/stable-3.22.2-x64/bin/flutter

Which indicates for me, that everything is fine. The exact same output is printed after the Sonarqube Action when running it with continue-on-error: true.

This is my new yml file:

sonar-scanner: needs: [ flutter-analysis ] runs-on: ubuntu-latest steps:

  • uses: actions/checkout@v4
  • name: Download Test Results uses: actions/download-artifact@v4 with: name: test-results.json
  • name: Download Coverage Results uses: actions/download-artifact@v4 with: name: coverage.LCOV
  • name: Set up Flutter SDK uses: subosito/flutter-action@v2 with: channel: stable flutter-version-file: pubspec.yaml
  • run: echo $PATH
  • run: type -a flutter
  • name: SonarQube Scan uses: sonarsource/sonarqube-scan-action@v2.1.0 env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }} continue-on-error: true
  • run: echo $PATH
  • run: type -a flutter
  • name: SonarQube Quality Gate check id: sonarqube-quality-gate-check uses: sonarsource/sonarqube-quality-gate-action@master

    Force to fail step after specific time.

    timeout-minutes: 1
    env:
      SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
      SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }}
Friesenjung commented 1 month ago

I found out that the sonarqube Github Action is running within a container. That might be the reason why it cannot access the flutter command outside of the container. For example I cannot access the directory /github/workspace which is the directory where sonarqube is looking for flutter. Any ideas who I can make it available within the container?