Fix profile #227
Workflow file for this run
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: Flutter App CI/CD | |
on: | |
workflow_call: | |
inputs: | |
externall_call: | |
description: 'To distinguish workflow_call from regular events' | |
type: boolean | |
required: false | |
default: true | |
version: | |
description: 'Version of the release' | |
type: string | |
required: true | |
create-executables: | |
description: 'Create executables' | |
type: boolean | |
required: true | |
secrets: | |
ANDROID_KEYSTORE: | |
required: true | |
description: 'Android keystore' | |
ANDROID_KEY_PROPERTIES: | |
required: true | |
description: 'Android key properties' | |
PRODUCTION_CREDENTIAL_FILE: | |
required: true | |
description: 'Production credential file' | |
MAPBOX_DOWNLOADS_TOKEN: | |
required: true | |
description: 'Mapbox downloads token' | |
MAPBOX_PUBLIC_ACCESS_TOKEN: | |
required: true | |
description: 'Mapbox public access token' | |
pull_request: | |
branches: | |
- main | |
paths: | |
- 'packages/app/**' | |
- '.github/workflows/app.yml' | |
env: | |
CI: true | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: packages/app | |
permissions: | |
contents: write | |
env: | |
AAB_PATH: packages/app/build/app/outputs/bundle/release/app-release.aab | |
KEYSTORE_PATH: android/upload-keystore.jks | |
KEY_PROPS_PATH: android/key.properties | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- uses: actions/setup-java@v4 | |
with: | |
distribution: 'corretto' | |
java-version: '17' | |
- name: Cache Flutter dependencies | |
uses: actions/cache@v4 | |
with: | |
path: /opt/hostedtoolcache/flutter | |
key: flutter-install-cache | |
- name: Set up Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
channel: stable | |
- name: Install dependencies | |
run: flutter pub get | |
- name: Analyze code | |
run: flutter analyze | |
- name: Run tests | |
run: flutter test | |
- name: Decode Android keystore | |
if: inputs.create-executables | |
run: echo "${{ secrets.ANDROID_KEYSTORE }}" | base64 --decode > ${{ env.KEYSTORE_PATH }} | |
- name: Copy keystore | |
if: inputs.create-executables | |
run: cp ${{ env.KEYSTORE_PATH }} android/app/upload-keystore.jks | |
- name: Decode Android key properties | |
if: inputs.create-executables | |
run: echo "${{ secrets.ANDROID_KEY_PROPERTIES }}" | base64 --decode > ${{ env.KEY_PROPS_PATH }} | |
- name: Create gradle directory | |
if: inputs.create-executables | |
run: mkdir -p ~/.gradle | |
- name: Add Mapbox Download Token | |
if: inputs.create-executables | |
run: echo "MAPBOX_DOWNLOADS_TOKEN=${{ secrets.MAPBOX_DOWNLOADS_TOKEN }}" >> ~/.gradle/gradle.properties | |
- name: Build APK | |
if: inputs.create-executables | |
run: | | |
flutter build apk \ | |
--release \ | |
--bundle-sksl-path flutter.sksl.json \ | |
--build-name=${{ inputs.version }} \ | |
--build-number=$(echo ${{ inputs.version }} | tr -d .) \ | |
--dart-define=PUBLIC_ACCESS_TOKEN=${{ secrets.MAPBOX_PUBLIC_ACCESS_TOKEN }} | |
# - name: Create build directory | |
# if: inputs.create-executables | |
# run: mkdir -p build/app/outputs/flutter-apk | |
# | |
# - name: Create fake APK | |
# if: inputs.create-executables | |
# run: touch build/app/outputs/flutter-apk/app-release.apk | |
- name: Rename APK | |
if: inputs.create-executables | |
run: mv build/app/outputs/flutter-apk/app-release.apk hollybike-Android-${{ inputs.version }}.apk | |
- name: Upload APK to artifacts | |
if: inputs.create-executables | |
uses: actions/upload-artifact@v4 | |
with: | |
name: HollyBike-${{ inputs.version }}-Android | |
path: packages/app/hollybike-Android-${{ inputs.version }}.apk | |
retention-days: 1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
deploy: | |
name: Deploy | |
if: ${{ inputs.externall_call }} | |
runs-on: ubuntu-latest | |
needs: build | |
defaults: | |
run: | |
working-directory: packages/app | |
env: | |
AAB_PATH: packages/app/build/app/outputs/bundle/release/app-release.aab | |
KEYSTORE_PATH: android/upload-keystore.jks | |
KEY_PROPS_PATH: android/key.properties | |
SERVICE_ACCOUNT_PATH: store_credentials.json | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- uses: actions/setup-java@v4 | |
with: | |
distribution: 'corretto' | |
java-version: '17' | |
- name: Cache Flutter dependencies | |
uses: actions/cache@v4 | |
with: | |
path: /opt/hostedtoolcache/flutter | |
key: flutter-install-cache | |
- name: Set up Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
channel: stable | |
- name: Install dependencies | |
run: flutter pub get | |
- name: Decode Android keystore | |
run: echo "${{ secrets.ANDROID_KEYSTORE }}" | base64 --decode > ${{ env.KEYSTORE_PATH }} | |
- name: Copy keystore | |
run: cp ${{ env.KEYSTORE_PATH }} android/app/upload-keystore.jks | |
- name: Decode Android key properties | |
run: echo "${{ secrets.ANDROID_KEY_PROPERTIES }}" | base64 --decode > ${{ env.KEY_PROPS_PATH }} | |
- name: Decode Android Service Account | |
run: echo "${{ secrets.PRODUCTION_CREDENTIAL_FILE }}" | base64 --decode > ${{ env.SERVICE_ACCOUNT_PATH }} | |
- name: Create gradle directory | |
run: mkdir -p ~/.gradle | |
- name: Add Mapbox Download Token | |
run: echo "MAPBOX_DOWNLOADS_TOKEN=${{ secrets.MAPBOX_DOWNLOADS_TOKEN }}" >> ~/.gradle/gradle.properties | |
- name: Build app bundle | |
run: | | |
flutter build appbundle \ | |
--release \ | |
--bundle-sksl-path flutter.sksl.json \ | |
--build-name=${{ inputs.version }} \ | |
--build-number=$(echo ${{ inputs.version }} | tr -d .) \ | |
--dart-define=PUBLIC_ACCESS_TOKEN=${{ secrets.MAPBOX_PUBLIC_ACCESS_TOKEN }} | |
- name: Deploy to Play Store (Internal testing) | |
uses: r0adkll/upload-google-play@v1 | |
with: | |
serviceAccountJson: packages/app/${{ env.SERVICE_ACCOUNT_PATH }} | |
packageName: com.hollybike.hollybike | |
releaseFiles: ${{ env.AAB_PATH }} | |
status: draft | |
track: internal | |