From 67ac44a63eeb280a8cc77eb0c24afd9f3d736dac Mon Sep 17 00:00:00 2001 From: fremartini Date: Thu, 12 Oct 2023 17:29:01 +0200 Subject: [PATCH] update workflow --- .github/actions/build_android/action.yml | 48 +++++ .github/actions/build_ios/action.yml | 83 +++++++++ .../setup_flutter_environment/action.yml | 18 ++ .github/workflows/build.yml | 166 ++---------------- .github/workflows/release.yml | 28 +-- .github/workflows/test.yml | 34 ++++ 6 files changed, 201 insertions(+), 176 deletions(-) create mode 100644 .github/actions/build_android/action.yml create mode 100644 .github/actions/build_ios/action.yml create mode 100644 .github/actions/setup_flutter_environment/action.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/actions/build_android/action.yml b/.github/actions/build_android/action.yml new file mode 100644 index 000000000..1295a6057 --- /dev/null +++ b/.github/actions/build_android/action.yml @@ -0,0 +1,48 @@ +name: Build Android app +description: Build and upload Android app +inputs: + version: + required: true + description: "App version" + build_version: + required: true + description: "Build version" + +runs: + using: "composite" + steps: + - name: Setup Flutter environment + uses: ./.github/actions/setup_flutter_environment + + - name: Replace target URI in Production + if: github.ref_name == 'production' + run: sed -i 's/.env.develop/.env.production/' lib/env/env.dart + + - name: Generate code + run: dart run build_runner build + + - name: Build apk (dev) + if: github.ref_name != 'production' + run: flutter build apk --flavor development --release --build-name ${{ inputs.version }} --build-number ${{ inputs.build_version }} --target lib/main_development.dart + + - name: Build appbundle (prod) + if: ${{ github.ref_name == 'production'}} + run: flutter build appbundle --release --flavor production --build-name ${{ inputs.version }} --build-number ${{ inputs.build_version }} --target lib/main_production.dart + + - name: Upload Android build (dev) + if: ${{ !!inputs.storeArtifacts && github.ref_name != 'production'}} + uses: actions/upload-artifact@v3.0.0 + with: + name: android + path: build/app/outputs/flutter-apk + retention-days: 1 + if-no-files-found: error + + - name: Upload Android build (prod) + if: ${{ !!inputs.storeArtifacts && github.ref_name == 'production'}} + uses: actions/upload-artifact@v3.0.0 + with: + name: android + path: build/app/outputs/bundle/release + retention-days: 1 + if-no-files-found: error diff --git a/.github/actions/build_ios/action.yml b/.github/actions/build_ios/action.yml new file mode 100644 index 000000000..7bf083006 --- /dev/null +++ b/.github/actions/build_ios/action.yml @@ -0,0 +1,83 @@ +name: Build iOS app +description: Build and upload iOS app +inputs: + version: + required: true + description: "App version" + build_version: + required: true + description: "Build version" + +runs: + using: "composite" + steps: + - name: Install Apple certificate and provisioning profile (dev) + if: github.ref_name != 'production' + run: .github/scripts/setup-certs.command + env: + APPLE_IOS_SIGNING_CERT: ${{ secrets.APPLE_IOS_SIGNING_CERTIFICATE_DEVELOPMENT }} + APPLE_IOS_SIGNING_CERT_PW: ${{ secrets.APPLE_IOS_SIGNING_CERTIFICATE_DEVELOPMENT_PASSWORD }} + APPLE_IOS_PROVISIONING_PROFILE: ${{ secrets.APPLE_IOS_PROVISIONING_PROFILE_DEVELOPMENT }} + APPLE_KEYCHAIN_PW: ${{ secrets.APPLE_KEYCHAIN_PW }} + + - name: Install Apple certificate and provisioning profile (prod) + if: github.ref_name == 'production' + run: .github/scripts/setup-certs.command + env: + APPLE_IOS_SIGNING_CERT: ${{ secrets.APPLE_IOS_SIGNING_CERT_PROD }} + APPLE_IOS_SIGNING_CERT_PW: ${{ secrets.APPLE_IOS_SIGNING_CERT_PW }} + APPLE_IOS_PROVISIONING_PROFILE: ${{ secrets.APPLE_IOS_PROVISIONING_PROFILE_PROD }} + APPLE_KEYCHAIN_PW: ${{ secrets.APPLE_KEYCHAIN_PW }} + + - name: Setup Flutter environment + uses: ./.github/actions/setup_flutter_environment + + - name: Set URI (prod) + if: github.ref_name == 'production' + run: sed -i '' 's/.env.develop/.env.production/' lib/env/env.dart + + - name: Generate code + run: dart run build_runner build + + - name: Build iOS (dev) + if: github.ref_name != 'production' + run: flutter build ios --flavor development --release --no-codesign --build-name ${{ inputs.version }} --build-number ${{ inputs.build_version }} --target lib/main_development.dart + + - name: Build iOS (prod) + if: github.ref_name == 'production' + run: flutter build ios --flavor production --release --no-codesign --build-name ${{ inputs.version }} --build-number ${{ inputs.build_version }} --target lib/main_production.dart + + - name: Build resolve Swift dependencies (dev) + if: github.ref_name != 'production' + run: xcodebuild -resolvePackageDependencies -workspace ios/Runner.xcworkspace -scheme development -configuration Release-development + + - name: Build resolve Swift dependencies (prod) + run: xcodebuild -resolvePackageDependencies -workspace ios/Runner.xcworkspace -scheme production -configuration Release-production + if: github.ref_name == 'production' + + - name: Build xArchive (dev) + if: github.ref_name != 'production' + run: | + xcodebuild -workspace ios/Runner.xcworkspace -scheme development -configuration Release-development DEVELOPMENT_TEAM=Y5U9T77F2K -sdk 'iphoneos' -destination 'generic/platform=iOS' -archivePath build-output/app.xcarchive PROVISIONING_PROFILE_SPECIFIER="development" clean archive CODE_SIGN_IDENTITY="iPhone Developer" + + - name: Build xArchive (prod) + if: github.ref_name == 'production' + run: | + xcodebuild -workspace ios/Runner.xcworkspace -scheme production -configuration Release-production DEVELOPMENT_TEAM=Y5U9T77F2K -sdk 'iphoneos' -destination 'generic/platform=iOS' -archivePath build-output/app.xcarchive PROVISIONING_PROFILE_SPECIFIER="githubactions-prod" clean archive CODE_SIGN_IDENTITY="Apple Distribution" + + - name: Export ipa (dev) + if: github.ref_name != 'production' + run: xcodebuild -exportArchive -archivePath build-output/app.xcarchive -exportPath build-output/ios -exportOptionsPlist ios/exportOptions.dev.plist + + - name: Export ipa (prod) + if: github.ref_name == 'production' + run: xcodebuild -exportArchive -archivePath build-output/app.xcarchive -exportPath build-output/ios -exportOptionsPlist ios/exportOptions.prod.plist + + - name: Upload iOS build + if: ${{ inputs.storeArtifacts }} + uses: actions/upload-artifact@v3.0.0 + with: + name: ios + path: build-output/ios + retention-days: 1 + if-no-files-found: error \ No newline at end of file diff --git a/.github/actions/setup_flutter_environment/action.yml b/.github/actions/setup_flutter_environment/action.yml new file mode 100644 index 000000000..5170e8083 --- /dev/null +++ b/.github/actions/setup_flutter_environment/action.yml @@ -0,0 +1,18 @@ +name: Setup Flutter environment +description: Setup the Flutter environment + +env: + FLUTTER_VERSION: 3.13.7 + +runs: + using: "composite" + steps: + - name: Setup Flutter environment + uses: subosito/flutter-action@v2.8.0 + with: + flutter-version: ${{ env.FLUTTER_VERSION }} + channel: "stable" + + - name: Download dependencies + run: flutter pub get + shell: bash \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2d9ecdb3c..6ddbc5d95 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build and test +name: Build application on: pull_request: @@ -16,10 +16,6 @@ on: description: "Version used for Git tag" value: ${{ jobs.version.outputs.version_tag }} -env: - FLUTTER_VERSION: 3.13.1 - JAVA_VERSION: 11.x - jobs: version: name: Versioning @@ -27,7 +23,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 @@ -69,84 +65,12 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 - - - name: Install Apple certificate and provisioning profile (dev) - if: github.ref_name != 'production' - run: .github/scripts/setup-certs.command - env: - APPLE_IOS_SIGNING_CERT: ${{ secrets.APPLE_IOS_SIGNING_CERTIFICATE_DEVELOPMENT }} - APPLE_IOS_SIGNING_CERT_PW: ${{ secrets.APPLE_IOS_SIGNING_CERTIFICATE_DEVELOPMENT_PASSWORD }} - APPLE_IOS_PROVISIONING_PROFILE: ${{ secrets.APPLE_IOS_PROVISIONING_PROFILE_DEVELOPMENT }} - APPLE_KEYCHAIN_PW: ${{ secrets.APPLE_KEYCHAIN_PW }} - - - name: Install Apple certificate and provisioning profile (prod) - if: github.ref_name == 'production' - run: .github/scripts/setup-certs.command - env: - APPLE_IOS_SIGNING_CERT: ${{ secrets.APPLE_IOS_SIGNING_CERT_PROD }} - APPLE_IOS_SIGNING_CERT_PW: ${{ secrets.APPLE_IOS_SIGNING_CERT_PW }} - APPLE_IOS_PROVISIONING_PROFILE: ${{ secrets.APPLE_IOS_PROVISIONING_PROFILE_PROD }} - APPLE_KEYCHAIN_PW: ${{ secrets.APPLE_KEYCHAIN_PW }} + uses: actions/checkout@v3 - - name: Setup Java - uses: actions/setup-java@v2.4.0 + - name: Build iOS app + uses: ./.github/actions/build_ios with: - distribution: "adopt" - java-version: ${{ env.JAVA_VERSION }} - - - name: Setup Flutter environment - uses: subosito/flutter-action@v2.3.0 - with: - flutter-version: ${{ env.FLUTTER_VERSION }} - channel: "stable" - - - name: Download dependencies - run: flutter pub get - - - name: Set URI (prod) - if: github.ref_name == 'production' - run: sed -i '' 's/.env.develop/.env.production/' lib/env/env.dart - - - name: Generate code - run: dart run build_runner build - - - name: Build iOS (dev) - if: github.ref_name != 'production' - run: flutter build ios --flavor development --release --no-codesign --build-name ${{ needs.version.outputs.version }} --build-number ${{ needs.version.outputs.build_version }} --target lib/main_development.dart - - name: Build iOS (prod) - if: github.ref_name == 'production' - run: flutter build ios --flavor production --release --no-codesign --build-name ${{ needs.version.outputs.version }} --build-number ${{ needs.version.outputs.build_version }} --target lib/main_production.dart - - name: Build resolve Swift dependencies (dev) - if: github.ref_name != 'production' - run: xcodebuild -resolvePackageDependencies -workspace ios/Runner.xcworkspace -scheme development -configuration Release-development - - name: Build resolve Swift dependencies (prod) - run: xcodebuild -resolvePackageDependencies -workspace ios/Runner.xcworkspace -scheme production -configuration Release-production - if: github.ref_name == 'production' - - name: Build xArchive (dev) - if: github.ref_name != 'production' - run: | - xcodebuild -workspace ios/Runner.xcworkspace -scheme development -configuration Release-development DEVELOPMENT_TEAM=Y5U9T77F2K -sdk 'iphoneos' -destination 'generic/platform=iOS' -archivePath build-output/app.xcarchive PROVISIONING_PROFILE_SPECIFIER="development" clean archive CODE_SIGN_IDENTITY="iPhone Developer" - - name: Build xArchive (prod) - if: github.ref_name == 'production' - run: | - xcodebuild -workspace ios/Runner.xcworkspace -scheme production -configuration Release-production DEVELOPMENT_TEAM=Y5U9T77F2K -sdk 'iphoneos' -destination 'generic/platform=iOS' -archivePath build-output/app.xcarchive PROVISIONING_PROFILE_SPECIFIER="githubactions-prod" clean archive CODE_SIGN_IDENTITY="Apple Distribution" - - name: Export ipa (dev) - if: github.ref_name != 'production' - run: xcodebuild -exportArchive -archivePath build-output/app.xcarchive -exportPath build-output/ios -exportOptionsPlist ios/exportOptions.dev.plist - - - name: Export ipa (prod) - if: github.ref_name == 'production' - run: xcodebuild -exportArchive -archivePath build-output/app.xcarchive -exportPath build-output/ios -exportOptionsPlist ios/exportOptions.prod.plist - - - name: Upload iOS build - if: ${{ inputs.storeArtifacts }} - uses: actions/upload-artifact@v3.0.0 - with: - name: ios - path: build-output/ios - retention-days: 1 - if-no-files-found: error + version: ${{ needs.version.outputs.version }} build_android: name: Build Android App @@ -154,79 +78,9 @@ jobs: needs: [version] steps: - name: Checkout code - uses: actions/checkout@v2 - - - name: Setup Java - uses: actions/setup-java@v2.4.0 - with: - distribution: "adopt" - java-version: ${{ env.JAVA_VERSION }} - - - name: Setup Flutter environment - uses: subosito/flutter-action@v2.3.0 - with: - flutter-version: ${{ env.FLUTTER_VERSION }} - channel: "stable" - - - name: Download dependencies - run: flutter pub get - - - name: Set URI (prod) - if: github.ref_name == 'production' - run: sed -i 's/.env.develop/.env.production/' lib/env/env.dart - - - name: Generate code - run: dart run build_runner build - - - name: Build appbundle (dev) - if: github.ref_name != 'production' - run: flutter build apk --flavor development --release --build-name ${{ needs.version.outputs.version }} --build-number ${{ needs.version.outputs.build_version }} --target lib/main_development.dart - - name: Build appbundle (prod) - if: github.ref_name == 'production' - run: flutter build apk --flavor production --release --dart-define=IS_PROD=true --build-name ${{ needs.version.outputs.version }} --build-number ${{ needs.version.outputs.build_version }} --target lib/main_production.dart - - name: Upload Android build - if: ${{ inputs.storeArtifacts }} - uses: actions/upload-artifact@v3.0.0 - with: - name: android - path: build/app/outputs/flutter-apk - retention-days: 1 - if-no-files-found: error - - test: - name: Test Flutter app - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2.4.0 - - - name: Setup Flutter environment - uses: subosito/flutter-action@v1.5.3 - with: - flutter-version: ${{ env.FLUTTER_VERSION }} - channel: "stable" - - - name: Download dependencies - run: flutter pub get - - - name: Generate code - run: dart run build_runner build - - - name: Check formatting - run: dart format --set-exit-if-changed lib/ - - - name: Static Analysis - run: flutter analyze - - - name: Run Code Metrics - run: dart run dart_code_metrics:metrics --reporter=github lib - - - name: Run tests - run: flutter test --coverage + uses: actions/checkout@v3 - - name: Upload test report to Codecov - uses: codecov/codecov-action@v2.1.0 + - name: Build Android app + uses: ./.github/actions/build_android with: - flags: unittests - file: coverage/lcov.info + version: ${{ needs.version.outputs.version }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9255b7d52..386990ba5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,21 +3,9 @@ name: Release Coffeecard App on: push: branches: [develop, production] - paths: - - android/** - - assets/** - - ios/** - - lib/** - - openapi/** - - .metadata - - .github/workflows/** - - pubspec.lock - - pubspec.yml - - .env.develop - - .env.production jobs: - build_and_test: + build: uses: ./.github/workflows/build.yml with: storeArtifacts: true @@ -26,7 +14,7 @@ jobs: dev_upload_ios: name: Upload iOS build to Firebase App Distribution runs-on: ubuntu-latest - needs: [build_and_test] + needs: [build] if: github.ref_name == 'develop' steps: @@ -45,7 +33,7 @@ jobs: dev_upload_android: name: Upload Android build to Firebase App Distribution runs-on: ubuntu-latest - needs: [build_and_test] + needs: [build] if: github.ref_name == 'develop' steps: @@ -64,7 +52,7 @@ jobs: prod_release_ios: name: Upload iOS build to App Store connect runs-on: macos-latest - needs: [build_and_test] + needs: [build] if: github.ref_name == 'production' steps: @@ -82,7 +70,7 @@ jobs: prod_release_android: name: Upload Android build to Play Store runs-on: ubuntu-latest - needs: [build_and_test] + needs: [build] if: github.ref_name == 'production' steps: @@ -111,13 +99,13 @@ jobs: tag: name: Git Tag version runs-on: ubuntu-latest - needs: [build_and_test, prod_release_ios, prod_release_android] + needs: [build, prod_release_ios, prod_release_android] if: ${{ needs.prod_release_ios.result == 'success' && needs.prod_release_android.result == 'success' }} steps: - name: Checkout code uses: actions/checkout@v2 - - name: Git Tag ${{ needs.build_and_test.outputs.version_tag }} + - name: Git Tag ${{ needs.build.outputs.version_tag }} uses: anothrNick/github-tag-action@1.36.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CUSTOM_TAG: ${{ needs.build_and_test.outputs.version_tag }} + CUSTOM_TAG: ${{ needs.build.outputs.version_tag }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..4e352aef3 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,34 @@ +name: Test + +on: + pull_request: + branches: [production, develop] + +jobs: + build-and-test: + name: Build and test Flutter app + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2.4.0 + + - name: Setup Flutter environment + uses: ./.github/actions/setup_flutter_environment + + - name: Generate code + run: dart run build_runner build + + - name: Check formatting + run: dart format --set-exit-if-changed lib/ + + - name: Static Analysis + run: flutter analyze + + - name: Run tests + run: flutter test --coverage + + - name: Upload test report to Codecov + uses: codecov/codecov-action@v2.1.0 + with: + flags: unittests + file: coverage/lcov.info \ No newline at end of file