Build Release #23
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: Build Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| versionName: | |
| required: true | |
| description: This release's version name | |
| default: "1.0.0" | |
| versionCode: | |
| required: true | |
| description: This release's version code | |
| default: "1000" | |
| permissions: | |
| contents: write | |
| env: | |
| JAVA_VERSION: 17 | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: ${{ env.JAVA_VERSION }} | |
| distribution: temurin | |
| cache: gradle | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@v2 | |
| - name: Set Version | |
| uses: chkfung/android-version-actions@v1.1 | |
| with: | |
| gradlePath: app/build.gradle.kts | |
| versionCode: ${{ github.event.inputs.versionCode }} | |
| versionName: ${{ github.event.inputs.versionName }} | |
| - name: Commit Version Bump (if changed) | |
| run: | | |
| git config user.email "actions@github.com" | |
| git config user.name "GitHub Actions" | |
| git add app/build.gradle.kts | |
| if git diff --cached --quiet; then | |
| echo "No version change." | |
| else | |
| git commit -m "chore: bump version to ${{ github.event.inputs.versionName }} (${{ github.event.inputs.versionCode }})" | |
| git push | |
| fi | |
| - name: Prepare Keystore | |
| run: | | |
| echo "${{ secrets.KEYSTORE }}" | base64 -d > signing-key.jks | |
| ls -l signing-key.jks | |
| - name: Build Universal APKs | |
| env: | |
| KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} | |
| KEY_ALIAS: ${{ secrets.KEY_ALIAS }} | |
| KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
| GRADLE_OPTS: -Dorg.gradle.daemon=false | |
| run: | | |
| ./gradlew packageDebugUniversalApk packageReleaseUniversalApk \ | |
| -Pandroid.injected.signing.store.file=$GITHUB_WORKSPACE/signing-key.jks \ | |
| -Pandroid.injected.signing.store.password="$KEYSTORE_PASSWORD" \ | |
| -Pandroid.injected.signing.key.alias="$KEY_ALIAS" \ | |
| -Pandroid.injected.signing.key.password="$KEY_PASSWORD" | |
| - name: Collect APKs | |
| run: | | |
| mkdir dist | |
| mv app/build/outputs/apk_from_bundle/debug/app-debug-universal.apk dist/app-debug.apk | |
| mv app/build/outputs/apk_from_bundle/release/app-release-universal.apk dist/app-release.apk | |
| ls -l dist | |
| - name: Upload APK Artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-apks | |
| path: dist/*.apk | |
| if-no-files-found: error | |
| - name: Create Tag and Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| tag=${{ github.event.inputs.versionCode }} | |
| if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then | |
| echo "Tag $tag already exists, skipping creation." | |
| else | |
| git tag "$tag" | |
| git push origin "$tag" | |
| fi | |
| gh release view "$tag" >/dev/null 2>&1 || gh release create "$tag" \ | |
| --title "${{ github.event.inputs.versionName }}" \ | |
| --generate-notes \ | |
| dist/app-debug.apk dist/app-release.apk |