|
| 1 | +name: Android Play Closed Testing Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + android_version_code: |
| 7 | + description: Must be greater than every Android version code already uploaded to Google Play. |
| 8 | + required: true |
| 9 | + type: number |
| 10 | + release_notes: |
| 11 | + description: Optional Google Play release notes for en-US. |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + |
| 18 | +jobs: |
| 19 | + deploy_closed_testing: |
| 20 | + name: Build and upload closed testing release |
| 21 | + runs-on: ubuntu-latest |
| 22 | + environment: staging |
| 23 | + env: |
| 24 | + ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }} |
| 25 | + ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }} |
| 26 | + ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }} |
| 27 | + REST_API_URL: ${{ vars.REST_API_URL }} |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Validate workflow inputs |
| 31 | + env: |
| 32 | + ANDROID_VERSION_CODE: ${{ inputs.android_version_code }} |
| 33 | + ANDROID_GOOGLE_SERVICES_JSON_B64: ${{ secrets.ANDROID_GOOGLE_SERVICES_JSON_B64 }} |
| 34 | + ANDROID_UPLOAD_KEYSTORE_B64: ${{ secrets.ANDROID_UPLOAD_KEYSTORE_B64 }} |
| 35 | + GOOGLE_PLAY_SERVICE_ACCOUNT_JSON: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON }} |
| 36 | + run: | |
| 37 | + case "$GITHUB_REF" in |
| 38 | + refs/heads/release/*|refs/heads/hotfix/*) |
| 39 | + ;; |
| 40 | + *) |
| 41 | + echo "Android Play Closed Testing Deploy must be run from a release/** or hotfix/** branch." >&2 |
| 42 | + exit 1 |
| 43 | + ;; |
| 44 | + esac |
| 45 | +
|
| 46 | + if ! [[ "$ANDROID_VERSION_CODE" =~ ^[1-9][0-9]*$ ]]; then |
| 47 | + echo "android_version_code must be a positive integer." >&2 |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | +
|
| 51 | + missing=0 |
| 52 | + for name in \ |
| 53 | + ANDROID_GOOGLE_SERVICES_JSON_B64 \ |
| 54 | + ANDROID_UPLOAD_KEYSTORE_B64 \ |
| 55 | + ANDROID_KEYSTORE_PASSWORD \ |
| 56 | + ANDROID_KEY_ALIAS \ |
| 57 | + ANDROID_KEY_PASSWORD \ |
| 58 | + GOOGLE_PLAY_SERVICE_ACCOUNT_JSON \ |
| 59 | + REST_API_URL |
| 60 | + do |
| 61 | + if [ -z "${!name}" ]; then |
| 62 | + echo "$name is required for Android Play closed testing deploy." >&2 |
| 63 | + missing=1 |
| 64 | + fi |
| 65 | + done |
| 66 | + exit "$missing" |
| 67 | +
|
| 68 | + - uses: actions/checkout@v4 |
| 69 | + |
| 70 | + - uses: actions/setup-java@v4 |
| 71 | + with: |
| 72 | + distribution: temurin |
| 73 | + java-version: "17" |
| 74 | + |
| 75 | + - uses: subosito/flutter-action@v2 |
| 76 | + with: |
| 77 | + flutter-version: "3.32.6" |
| 78 | + channel: stable |
| 79 | + cache: true |
| 80 | + |
| 81 | + - name: Set Android keystore path |
| 82 | + run: echo "ANDROID_KEYSTORE_PATH=$RUNNER_TEMP/ontime-upload.jks" >> "$GITHUB_ENV" |
| 83 | + |
| 84 | + - name: Install native test dependencies |
| 85 | + run: sudo apt-get update && sudo apt-get install -y sqlite3 libsqlite3-dev |
| 86 | + |
| 87 | + - name: Decode Android Firebase config |
| 88 | + env: |
| 89 | + ANDROID_GOOGLE_SERVICES_JSON_B64: ${{ secrets.ANDROID_GOOGLE_SERVICES_JSON_B64 }} |
| 90 | + run: | |
| 91 | + mkdir -p android/app/src/release |
| 92 | + printf '%s' "$ANDROID_GOOGLE_SERVICES_JSON_B64" | base64 --decode > android/app/src/release/google-services.json |
| 93 | + test -s android/app/src/release/google-services.json |
| 94 | +
|
| 95 | + - name: Decode Android upload keystore |
| 96 | + env: |
| 97 | + ANDROID_UPLOAD_KEYSTORE_B64: ${{ secrets.ANDROID_UPLOAD_KEYSTORE_B64 }} |
| 98 | + run: | |
| 99 | + printf '%s' "$ANDROID_UPLOAD_KEYSTORE_B64" | base64 --decode > "$ANDROID_KEYSTORE_PATH" |
| 100 | + chmod 600 "$ANDROID_KEYSTORE_PATH" |
| 101 | + test -s "$ANDROID_KEYSTORE_PATH" |
| 102 | +
|
| 103 | + - name: Install Flutter packages |
| 104 | + run: flutter pub get |
| 105 | + |
| 106 | + - name: Run code generation |
| 107 | + run: dart run build_runner build --delete-conflicting-outputs |
| 108 | + |
| 109 | + - name: Verify generated files are current |
| 110 | + run: git diff --exit-code |
| 111 | + |
| 112 | + - name: Analyze |
| 113 | + run: flutter analyze |
| 114 | + |
| 115 | + - name: Test |
| 116 | + run: flutter test |
| 117 | + |
| 118 | + - name: Derive Android build name |
| 119 | + run: | |
| 120 | + app_version="$(sed -n 's/^version: *//p' pubspec.yaml | head -n 1)" |
| 121 | + build_name="${app_version%%+*}" |
| 122 | + if [ -z "$build_name" ]; then |
| 123 | + echo "Unable to derive Android build name from pubspec.yaml version." >&2 |
| 124 | + exit 1 |
| 125 | + fi |
| 126 | + echo "ANDROID_BUILD_NAME=$build_name" >> "$GITHUB_ENV" |
| 127 | +
|
| 128 | + - name: Build Android app bundle |
| 129 | + run: | |
| 130 | + flutter build appbundle --release \ |
| 131 | + --build-name="$ANDROID_BUILD_NAME" \ |
| 132 | + --build-number="${{ inputs.android_version_code }}" \ |
| 133 | + --dart-define=ENV=staging \ |
| 134 | + --dart-define=REST_API_URL="$REST_API_URL" |
| 135 | +
|
| 136 | + - name: Prepare Play release notes |
| 137 | + if: ${{ inputs.release_notes != '' }} |
| 138 | + env: |
| 139 | + RELEASE_NOTES: ${{ inputs.release_notes }} |
| 140 | + run: | |
| 141 | + mkdir -p distribution/whatsnew |
| 142 | + printf '%s\n' "$RELEASE_NOTES" > distribution/whatsnew/whatsnew-en-US |
| 143 | +
|
| 144 | + - name: Upload signed app bundle artifact |
| 145 | + uses: actions/upload-artifact@v4 |
| 146 | + with: |
| 147 | + name: ontime-android-closed-testing-aab |
| 148 | + path: build/app/outputs/bundle/release/app-release.aab |
| 149 | + if-no-files-found: error |
| 150 | + retention-days: 14 |
| 151 | + |
| 152 | + - name: Upload closed testing release with release notes |
| 153 | + if: ${{ inputs.release_notes != '' }} |
| 154 | + uses: r0adkll/upload-google-play@v1 |
| 155 | + with: |
| 156 | + serviceAccountJsonPlainText: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON }} |
| 157 | + packageName: club.devkor.ontime |
| 158 | + releaseFiles: build/app/outputs/bundle/release/app-release.aab |
| 159 | + tracks: alpha |
| 160 | + status: completed |
| 161 | + whatsNewDirectory: distribution/whatsnew |
| 162 | + |
| 163 | + - name: Upload closed testing release |
| 164 | + if: ${{ inputs.release_notes == '' }} |
| 165 | + uses: r0adkll/upload-google-play@v1 |
| 166 | + with: |
| 167 | + serviceAccountJsonPlainText: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON }} |
| 168 | + packageName: club.devkor.ontime |
| 169 | + releaseFiles: build/app/outputs/bundle/release/app-release.aab |
| 170 | + tracks: alpha |
| 171 | + status: completed |
0 commit comments