subosito / flutter-action

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

Cannot run on self-hosted runner #48

Closed inm-certi closed 4 years ago

inm-certi commented 4 years ago

I have been using this workflow for a while without problems.

Today I tried to switch to "self-hosted" runner and faced a problem with the flutter installation:

> Run flutter pub get
Running "flutter pub get" in mobile_app...                      
The current Flutter SDK version is 0.0.0-unknown.

Has anyone faced this issue?

Here is my full workflow:

# This is a basic workflow to help you get started with Actions

name: Flutter CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  push:
    paths: [ dev/mobile_app/**, .github/** ]
    branches: [ master, develop ]
  pull_request:
    paths: [ dev/mobile_app/**, .github/** ]
    branches: [ master, develop ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # Workflow lint
  flutter-test-lint:
    name: Flutter Test & Lint
    runs-on: self-hosted
    # Do not run this job on PR from develop to master.
    if: github.head_ref != 'develop' || github.base_ref != 'master'
    steps:
      - name: Checkout source code
        uses: actions/checkout@v2

      - name: Install Flutter
        uses: subosito/flutter-action@v1
        with:
          flutter-version: '1.12.13+hotfix.9'

      - name: Pub get
        working-directory: dev/mobile_app
        run: flutter pub get

      - name: Lint
        uses: kitek/dartanalyzer-annotations-action@v1.1
        env:
          GITHUB_TOKEN: ${{ github.token }}
        with:
          check_name: 'Flutter Test & Lint'
          commit_sha: ${{ github.event.pull_request.head.sha }}
          working-directory: dev/mobile_app

      - name: Test
        working-directory: dev/mobile_app
        run: flutter test

  ##############################################################################
  #             FLUTTER BUILD DEVELOPMENT - ONLY IF NOT ON MASTER              #
  ##############################################################################
  flutter-dev-build:
    name: Flutter Build Development
    needs: flutter-test-lint
    runs-on: self-hosted
    # Run this job on push to develop, PR to develop or PR to master.
    if: github.ref == 'refs/heads/develop' || github.base_ref == 'develop' || github.base_ref == 'master'
    steps:
      - name: Checkout source code
        uses: actions/checkout@v2

      - name: Install Flutter
        uses: subosito/flutter-action@v1
        with:
          flutter-version: '1.12.13+hotfix.9'

      - name: Pub get
        working-directory: dev/mobile_app
        run: flutter pub get

      - name: Setup Development Android Keys
        working-directory: dev/mobile_app
        run: |
          echo "${{ secrets.ANDROID_DEBUG_KEYSTORE }}" | base64 --decode > android/app/key.jks
          echo "${{ secrets.ANDROID_KEYSTORE_PROPERTIES }}" | base64 --decode > android/key.properties
          echo "${{ secrets.ANDROID_FIREBASE_JSON_DEV }}" | base64 --decode > android/app/google-services.json

      - name: Fix build number
        env:
          NUM: ${{ github.run_number }}
        run: echo ::set-env name=BUILD_NUMBER::$(($NUM+500))

      - name: Build Patient DEV APK
        working-directory: dev/mobile_app
        run: flutter build apk --release --flavor patient_dev -t lib/main_patient.dart --build-number $BUILD_NUMBER

      - name: Upload build Patient DEV APK
        uses: actions/upload-artifact@v1
        with:
          name: patient_dev.apk
          path: dev/mobile_app/build/app/outputs/apk/patient_dev/release/app-patient_dev-release.apk

      - name: Build Sampler DEV APK
        working-directory: dev/mobile_app
        run: flutter build apk --release --flavor sampler_dev -t lib/main_sampler.dart --build-number $BUILD_NUMBER

      - name: Upload build Sampler DEV APK
        uses: actions/upload-artifact@v1
        with:
          name: sampler_dev.apk
          path: dev/mobile_app/build/app/outputs/apk/sampler_dev/release/app-sampler_dev-release.apk

  ##############################################################################
  #              FLUTTER BUILD PRODUCTION - ONLY ON MASTER                     #
  ##############################################################################
  flutter-prod-build:
    name: Flutter Build Production
    needs: flutter-test-lint
    runs-on: self-hosted
    # Run only in push to master.
    if: github.event_name == 'push' && github.ref == 'refs/heads/master'
    steps:
      - name: Checkout source code
        uses: actions/checkout@v2

      - name: Install Flutter
        uses: subosito/flutter-action@v1
        with:
          flutter-version: '1.12.13+hotfix.9'

      - name: Pub get
        working-directory: dev/mobile_app
        run: flutter pub get

      - name: Setup Production Android Keys
        working-directory: dev/mobile_app
        run: |
          echo "${{ secrets.ANDROID_RELEASE_KEYSTORE }}" | base64 --decode > android/app/key.jks
          echo "${{ secrets.ANDROID_KEYSTORE_PROPERTIES }}" | base64 --decode > android/key.properties
          echo "${{ secrets.ANDROID_FIREBASE_JSON_PROD }}" | base64 --decode > android/app/google-services.json

      - name: Fix build number
        env:
          NUM: ${{ github.run_number }}
        run: echo ::set-env name=BUILD_NUMBER::$(($NUM+500))

      - name: Build Patient PROD APK
        working-directory: dev/mobile_app
        run: flutter build apk --release --flavor patient_prod -t lib/main_patient.dart --build-number $BUILD_NUMBER

      - name: Upload build Patient PROD APK
        uses: actions/upload-artifact@v1
        with:
          name: patient_prod.apk
          path: dev/mobile_app/build/app/outputs/apk/patient_prod/release/app-patient_prod-release.apk

      - name: Build Sampler PROD APK
        working-directory: dev/mobile_app
        run: flutter build apk --release --flavor sampler_prod -t lib/main_sampler.dart --build-number $BUILD_NUMBER

      - name: Upload build Sampler PROD APK
        uses: actions/upload-artifact@v1
        with:
          name: sampler_prod.apk
          path: dev/mobile_app/build/app/outputs/apk/sampler_prod/release/app-sampler_prod-release.apk

      - name: Build Patient AppBundle
        working-directory: dev/mobile_app
        run: flutter build appbundle --release --flavor patient_prod -t lib/main_patient.dart --build-number $BUILD_NUMBER

      - name: Upload build Patient AppBundle
        uses: actions/upload-artifact@v1
        with:
          name: patient_prod.aab
          path: dev/mobile_app/build/app/outputs/bundle/patient_prodRelease/app-patient_prod-release.aab

      - name: Build Sampler AppBundle
        working-directory: dev/mobile_app
        run: flutter build appbundle --release --flavor sampler_prod -t lib/main_sampler.dart --build-number $BUILD_NUMBER

      - name: Upload build Sampler AppBundle
        uses: actions/upload-artifact@v1
        with:
          name: sampler_prod.aab
          path: dev/mobile_app/build/app/outputs/bundle/sampler_prodRelease/app-sampler_prod-release.aab
inm-certi commented 4 years ago

We have figured the problem. It was the git version.

Flutter requires git version >= 2.0, and the server was running git 1.8.3.1.

Flutter requirements:

    bash.
    curl.
    Git version >= 2.0
    mkdir.
    rm.
    unzip.
    which.
    xz-utils.