Merge pull request #1 from formigas/formigas_github_actions-changes-156 #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Continuous Integration | |
permissions: | |
checks: write | |
pull-requests: write | |
on: | |
push: | |
branches: [develop, staging, master, main] | |
pull_request: | |
env: | |
FLUTTER_VERSION: "3.24.2" | |
jobs: | |
validate: | |
name: Validate | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: ${{ env.FLUTTER_VERSION }} | |
cache: true | |
- name: Format | |
run: dart format -o none --set-exit-if-changed lib/ test/ | |
- name: Build runner | |
run: dart run build_runner build --delete-conflicting-outputs | |
- name: Analyze | |
run: flutter analyze --fatal-infos --fatal-warnings | |
determine-flavor: | |
name: Determine Flavor | |
runs-on: ubuntu-latest | |
outputs: | |
flavor: ${{ steps.set-flavor.outputs.flavor }} | |
steps: | |
- name: Determine Flavor | |
id: set-flavor | |
run: | | |
if [[ "${{ github.ref }}" == "refs/heads/master" || "${{ github.ref }}" == "refs/heads/main" ]]; then | |
echo "flavor=production" >> $GITHUB_OUTPUT | |
elif [[ "${{ github.ref }}" == "refs/heads/staging" ]]; then | |
echo "flavor=staging" >> $GITHUB_OUTPUT | |
else | |
echo "flavor=development" >> $GITHUB_OUTPUT | |
fi | |
build_ios: | |
name: Build iOS ${{ needs.determine-flavor.outputs.flavor }} | |
needs: determine-flavor | |
runs-on: macos-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: ${{ env.FLUTTER_VERSION }} | |
cache: true | |
- name: Clean | |
run: flutter clean | |
- name: Build runner | |
run: dart run build_runner build --delete-conflicting-outputs | |
- name: Build | |
run: flutter build ios --no-codesign --release --flavor ${{ needs.determine-flavor.outputs.flavor }} -t lib/main_${{ needs.determine-flavor.outputs.flavor }}.dart | |
build_android: | |
name: Build Android ${{ needs.determine-flavor.outputs.flavor }} | |
needs: determine-flavor | |
runs-on: ubuntu-latest | |
env: | |
KEYSTORE_FILENAME: upload-keystore.jks | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: ${{ env.FLUTTER_VERSION }} | |
cache: true | |
- name: Setup Keystore | |
run: echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 --decode > ./android/app/${{ env.KEYSTORE_FILENAME }} | |
- name: Clean | |
run: flutter clean | |
- name: Build runner | |
run: dart run build_runner build --delete-conflicting-outputs | |
- name: Build | |
run: flutter build appbundle --release --flavor ${{ needs.determine-flavor.outputs.flavor }} -t lib/main_${{ needs.determine-flavor.outputs.flavor }}.dart | |
env: | |
ANDROID_KEYSTORE_PATH: ${{ env.KEYSTORE_FILENAME }} | |
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }} | |
ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD }} | |
ANDROID_KEYSTORE_ALIAS: ${{ vars.ANDROID_KEYSTORE_ALIAS }} | |
test: | |
name: Test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: ${{ env.FLUTTER_VERSION }} | |
cache: true | |
- name: Install lcov | |
run: | | |
sudo apt-get update | |
sudo apt-get -y install lcov | |
- name: Clean | |
run: flutter clean | |
- name: Build runner | |
run: dart run build_runner build --delete-conflicting-outputs | |
- name: Run tests | |
run: flutter test --coverage --file-reporter json:test_results.json | |
- name: Remove generated files from coverage | |
run: lcov --remove coverage/lcov.info '**.g.dart' -o coverage/clean_lcov.info | |
- name: Publish test results | |
uses: dorny/[email protected] | |
if: success() || failure() | |
with: | |
name: Unit tests report | |
path: test_results.json | |
reporter: flutter-json | |
max-annotations: 50 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish coverage report | |
uses: zgosalvez/github-actions-report-lcov@v3 | |
with: | |
coverage-files: coverage/clean_lcov.info | |
minimum-coverage: 50 | |
artifact-name: code-coverage-report | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
update-comment: true | |
additional-message: Remember that you want to write high quality tests, so you can sleep well at night! |