Skip to content

Commit

Permalink
update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
fremartini committed Oct 12, 2023
1 parent b18b921 commit 67ac44a
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 176 deletions.
48 changes: 48 additions & 0 deletions .github/actions/build_android/action.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/[email protected]
with:
name: android
path: build/app/outputs/bundle/release
retention-days: 1
if-no-files-found: error
83 changes: 83 additions & 0 deletions .github/actions/build_ios/action.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
name: ios
path: build-output/ios
retention-days: 1
if-no-files-found: error
18 changes: 18 additions & 0 deletions .github/actions/setup_flutter_environment/action.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: "stable"

- name: Download dependencies
run: flutter pub get
shell: bash
166 changes: 10 additions & 156 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and test
name: Build application

on:
pull_request:
Expand All @@ -16,18 +16,14 @@ 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
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

Expand Down Expand Up @@ -69,164 +65,22 @@ 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/[email protected]
- name: Build iOS app
uses: ./.github/actions/build_ios
with:
distribution: "adopt"
java-version: ${{ env.JAVA_VERSION }}

- name: Setup Flutter environment
uses: subosito/[email protected]
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/[email protected]
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
runs-on: ubuntu-latest
needs: [version]
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Java
uses: actions/[email protected]
with:
distribution: "adopt"
java-version: ${{ env.JAVA_VERSION }}

- name: Setup Flutter environment
uses: subosito/[email protected]
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/[email protected]
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/[email protected]

- name: Setup Flutter environment
uses: subosito/[email protected]
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/[email protected]
- name: Build Android app
uses: ./.github/actions/build_android
with:
flags: unittests
file: coverage/lcov.info
version: ${{ needs.version.outputs.version }}
Loading

0 comments on commit 67ac44a

Please sign in to comment.