Build the local-only plant care app (phases 0 and 1) #2
This file contains hidden or 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: Android | |
| # main -> rolling "preview" pre-release with an arm64 APK (stable download URL) | |
| # v* -> versioned release with a universal APK + AAB for Google Play | |
| on: | |
| push: | |
| branches: [main] | |
| tags: ['v*'] | |
| paths-ignore: ['**.md'] | |
| workflow_dispatch: | |
| concurrency: | |
| group: android-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 60 | |
| env: | |
| IS_RELEASE: ${{ startsWith(github.ref, 'refs/tags/v') }} | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: actions/setup-node@v7 | |
| with: | |
| node-version: lts/* | |
| cache: npm | |
| - uses: actions/setup-java@v6 | |
| with: | |
| distribution: zulu | |
| java-version: '17' | |
| - uses: gradle/actions/setup-gradle@v6 | |
| - run: npm ci | |
| - name: Typecheck, lint and test | |
| run: | | |
| npx tsc --noEmit | |
| npx expo lint | |
| npm test -- --ci | |
| - name: Check tag matches app.json version | |
| if: env.IS_RELEASE == 'true' | |
| run: | | |
| VERSION=$(node -p "require('./app.json').expo.version") | |
| if [ "v$VERSION" != "$GITHUB_REF_NAME" ]; then | |
| echo "::error::Tag $GITHUB_REF_NAME does not match app.json version ($VERSION)" | |
| exit 1 | |
| fi | |
| - name: Set Android versionCode to the run number | |
| run: | | |
| node -e " | |
| const fs = require('fs'); | |
| const config = JSON.parse(fs.readFileSync('app.json', 'utf8')); | |
| config.expo.android.versionCode = Number(process.env.GITHUB_RUN_NUMBER); | |
| fs.writeFileSync('app.json', JSON.stringify(config, null, 2)); | |
| " | |
| - run: npx expo prebuild --platform android --no-install | |
| - name: Decode upload keystore | |
| env: | |
| KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }} | |
| run: | | |
| if [ -z "$KEYSTORE_BASE64" ]; then | |
| echo "::error::Missing ANDROID_KEYSTORE_BASE64 secret" | |
| exit 1 | |
| fi | |
| echo "$KEYSTORE_BASE64" | base64 --decode > "$RUNNER_TEMP/upload.jks" | |
| - name: Build | |
| working-directory: android | |
| env: | |
| ORG_GRADLE_PROJECT_PLANTULE_UPLOAD_STORE_FILE: ${{ runner.temp }}/upload.jks | |
| ORG_GRADLE_PROJECT_PLANTULE_UPLOAD_STORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }} | |
| ORG_GRADLE_PROJECT_PLANTULE_UPLOAD_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }} | |
| ORG_GRADLE_PROJECT_PLANTULE_UPLOAD_KEY_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }} | |
| run: | | |
| if [ "$IS_RELEASE" = "true" ]; then | |
| ./gradlew app:assembleRelease app:bundleRelease | |
| else | |
| ./gradlew app:assembleRelease -PreactNativeArchitectures=arm64-v8a | |
| fi | |
| - name: Publish preview release | |
| if: env.IS_RELEASE != 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| cp android/app/build/outputs/apk/release/app-release.apk plantule-preview.apk | |
| gh release delete preview --cleanup-tag --yes || true | |
| gh release create preview plantule-preview.apk \ | |
| --prerelease \ | |
| --target "$GITHUB_SHA" \ | |
| --title "Preview (main)" \ | |
| --notes "Build #$GITHUB_RUN_NUMBER from ${GITHUB_SHA::7}" | |
| - name: Publish versioned release | |
| if: env.IS_RELEASE == 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| cp android/app/build/outputs/apk/release/app-release.apk "plantule-$GITHUB_REF_NAME.apk" | |
| cp android/app/build/outputs/bundle/release/app-release.aab "plantule-$GITHUB_REF_NAME.aab" | |
| gh release create "$GITHUB_REF_NAME" \ | |
| "plantule-$GITHUB_REF_NAME.apk" \ | |
| "plantule-$GITHUB_REF_NAME.aab" \ | |
| --title "$GITHUB_REF_NAME" \ | |
| --generate-notes |