Skip to content

Release dev/prod versions off a main branch #656

Release dev/prod versions off a main branch

Release dev/prod versions off a main branch #656

Workflow file for this run

name: Build and test
on:
pull_request:
branches: [ 'develop', 'main' ]
workflow_dispatch:
workflow_call:
inputs:
storeArtifacts:
type: boolean
required: false
default: false
prodRelease:
type: boolean
required: false
default: false
tagName:
type: string
required: false
env:
FLUTTER_VERSION: 3.13.1
JAVA_VERSION: 11.x
DEV_RELEASE: ${{ inputs.prodRelease != 'true' || 'false' }}
PROD_RELEASE: ${{ inputs.prodRelease || 'false' }}
TAG_NAME: ${{ inputs.tagName || 'dev' }}
jobs:
version:
name: Versioning
runs-on: ubuntu-latest
steps:
- name: Determine build version
id: build_version
run: |
BUILD_NO=$((${{ github.run_number }} + 100))
echo "::set-output name=build_no::$BUILD_NO"
- name: Print versioning
run: |
echo "Version: $VERSION"
echo "Run No: $BUILD_NO"
env:
VERSION: ${{ env.TAG_NAME }}
BUILD_NO: ${{ steps.build_version.outputs.build_no }}
outputs:
version: ${{ env.TAG_NAME }}
build_version: ${{ steps.build_version.outputs.build_no }}
build_ios:
name: Build iOS App
runs-on: macos-latest
needs: [version]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Apple certificate and provisioning profile (dev)
if: env.DEV_RELEASE
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: env.PROD_RELEASE
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 Java
uses: actions/setup-java@v2
with:
distribution: "adopt"
java-version: ${{ env.JAVA_VERSION }}
- name: Setup Flutter environment
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: "stable"
- name: Download dependencies
run: flutter pub get
- name: Set URI (prod)
if: env.PROD_RELEASE
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: env.DEV_RELEASE
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: env.PROD_RELEASE
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: env.DEV_RELEASE
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: env.PROD_RELEASE
- name: Build xArchive (dev)
if: env.DEV_RELEASE
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: env.PROD_RELEASE
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: env.DEV_RELEASE
run: xcodebuild -exportArchive -archivePath build-output/app.xcarchive -exportPath build-output/ios -exportOptionsPlist ios/exportOptions.dev.plist
- name: Export ipa (prod)
if: env.PROD_RELEASE
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
with:
name: ios
path: build-output/ios
retention-days: 1
if-no-files-found: error
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/setup-java@v2
with:
distribution: "adopt"
java-version: ${{ env.JAVA_VERSION }}
- name: Setup Flutter environment
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: "stable"
- name: Download dependencies
run: flutter pub get
- name: Set URI (prod)
if: env.PROD_RELEASE
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: env.DEV_RELEASE
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: env.PROD_RELEASE
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
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
- name: Upload test report to Codecov
uses: codecov/[email protected]
with:
flags: unittests
file: coverage/lcov.info