From 59b28bc6cfdcf6e91ee4193bc22cac83b87f5596 Mon Sep 17 00:00:00 2001 From: "Jo G." <1451036+jo-elimu@users.noreply.github.com> Date: Mon, 5 May 2025 16:36:16 +0700 Subject: [PATCH] build: apk signing #324 --- .github/workflows/gradle-release.yml | 96 ++++++++++++++++++++++++++-- README.md | 2 +- 2 files changed, 90 insertions(+), 8 deletions(-) diff --git a/.github/workflows/gradle-release.yml b/.github/workflows/gradle-release.yml index 8828fe30..3fc6c1fe 100644 --- a/.github/workflows/gradle-release.yml +++ b/.github/workflows/gradle-release.yml @@ -16,13 +16,13 @@ jobs: - uses: gradle/gradle-build-action@v3 - name: GitHub Actor - env: - GITHUB_ACTOR: ${{ github.actor }} + env: + GITHUB_ACTOR: ${{ github.actor }} run: echo "$GITHUB_ACTOR" - name: GitHub Triggering Actor - env: - GITHUB_TRIGGERING_ACTOR: ${{ github.triggering_actor }} + env: + GITHUB_TRIGGERING_ACTOR: ${{ github.triggering_actor }} run: echo "$GITHUB_TRIGGERING_ACTOR" - name: Git Config @@ -36,9 +36,10 @@ jobs: - name: Set the new versionName as an environment variable id: get_version_name run: | - ./gradlew getVersionName --quiet --console=plain - VERSION_NAME="$(./gradlew getVersionName --quiet --console=plain)" - echo "::set-output name=version_name::$VERSION_NAME" + ./gradlew app:getVersionName --quiet --console=plain + VERSION_NAME="$(./gradlew app:getVersionName --quiet --console=plain)" + echo "VERSION_NAME $VERSION_NAME" + echo "version_name=$VERSION_NAME" >> $GITHUB_OUTPUT - name: Git Commit run: | @@ -77,3 +78,84 @@ jobs: - name: Git Push run: | git push + outputs: + tagName: ${{ steps.get_version_name.outputs.version_name }} + + release_apk: + needs: create_git_tag + runs-on: ubuntu-latest + steps: + - name: Get the Git Tag name from the previous job + run: echo "tagName ${{ needs.create_git_tag.outputs.tagName }}" + + - name: Checkout refs/tags/${{ needs.create_git_tag.outputs.tagName }} + uses: actions/checkout@v4 + with: + ref: refs/tags/${{ needs.create_git_tag.outputs.tagName }} + + - name: Assemble APK file + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + + - uses: gradle/gradle-build-action@v3 + + - name: Assemble `release` build + run: ./gradlew assembleRelease + + - name: Sign the APK file + uses: r0adkll/sign-android-release@v1 + id: sign_app + with: + releaseDirectory: app/build/outputs/apk/release + signingKeyBase64: ${{ secrets.SIGN_ANDROID_KEY }} + alias: ${{ secrets.SIGN_ANDROID_ALIAS }} + keyStorePassword: ${{ secrets.SIGN_ANDROID_KEY_STORE_PASSWORD }} + keyPassword: ${{ secrets.SIGN_ANDROID_KEY_PASSWORD }} + env: + BUILD_TOOLS_VERSION: "34.0.0" + + - run: echo "signedReleaseFile ${{steps.sign_app.outputs.signedReleaseFile}}" + + - name: Rename signed release file to `ai.elimu.content-provider-${{ needs.create_git_tag.outputs.tagName }}.apk` + run: mv ${{steps.sign_app.outputs.signedReleaseFile}} app/build/outputs/apk/release/ai.elimu.content-provider-${{ needs.create_git_tag.outputs.tagName }}.apk + + - name: Upload the signed APK file to GitHub release + uses: softprops/action-gh-release@v2 + with: + tag_name: '${{ needs.create_git_tag.outputs.tagName }}' + files: app/build/outputs/apk/release/ai.elimu.content-provider-${{ needs.create_git_tag.outputs.tagName }}.apk + env: + GITHUB_TOKEN: ${{ github.token }} + + - name: Prepare the APK file URL + id: prepare_apk_file_url + run: | + echo "tagName ${{ needs.create_git_tag.outputs.tagName }}" + APK_FILE_URL="https://github.com/elimu-ai/content-provider/releases/download/${{ needs.create_git_tag.outputs.tagName }}/ai.elimu.content-provider-${{ needs.create_git_tag.outputs.tagName }}.apk" + echo "APK_FILE_URL $APK_FILE_URL" + echo "apk_file_url=$APK_FILE_URL" >> $GITHUB_OUTPUT + outputs: + apkFileUrl: ${{ steps.prepare_apk_file_url.outputs.apk_file_url }} + + notify_webapp_api: + needs: [ create_git_tag, release_apk ] + strategy: + matrix: + language_code: [ eng, hin, tgl, tha, vie ] + runs-on: ubuntu-latest + steps: + - name: Get the Git Tag name from previous job + run: echo "tagName ${{ needs.create_git_tag.outputs.tagName }}" + + - name: Get the APK file URL from previous job + run: echo "apkFileUrl ${{ needs.release_apk.outputs.apkFileUrl }}" + + - name: Send HTTP request to `${{ matrix.language_code }}.elimu.ai` + uses: fjogeleit/http-request-action@v1 + with: + url: http://${{ matrix.language_code }}.elimu.ai/rest/v2/applications/ai.elimu.content_provider/application-versions/${{ needs.create_git_tag.outputs.tagName }} + method: PUT + data: '{"fileUrl": "${{ needs.release_apk.outputs.apkFileUrl }}"}' + customHeaders: '{"Content-Type": "application/json"}' diff --git a/README.md b/README.md index b0f769aa..79b0f52a 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ To perform a release, follow these steps: 1. Merge your PR into the `main` branch 1. Wait for the ["Gradle Release"](https://github.com/elimu-ai/content-provider/actions/workflows/gradle-release.yml) workflow to complete -1. Ensure that the new release version appears at https://jitpack.io/#ai.elimu/content-provider with "Status: ok" +1. Ensure that the new release version appears at https://github.com/elimu-ai/content-provider/releases > [!IMPORTANT] > After you publish a new release, remember to also bump the version in all Android app repos that depend on the `utils` library: