Android Release #9
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 Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag_name: | |
| description: 'Tag name (e.g: 1.0.0)' | |
| required: true | |
| type: string | |
| release_name: | |
| description: 'Release name (e.g: Release 1.0.0)' | |
| required: true | |
| type: string | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| environment: Release | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| cache: 'gradle' | |
| - name: Build Release APK | |
| run: ./gradlew assembleRelease | |
| - name: Sign and Align APK | |
| env: | |
| SIGNING_KEY: ${{ secrets.SIGNING_KEY }} | |
| ALIAS: ${{ secrets.ALIAS }} | |
| KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
| run: | | |
| # 1. Find build tools | |
| BUILD_TOOLS_PATH=$ANDROID_HOME/build-tools/36.0.0 | |
| # 2. Decode keystore from the env variable | |
| echo "$SIGNING_KEY" | base64 -d > release.jks | |
| # 3. Align the APK | |
| $BUILD_TOOLS_PATH/zipalign -v 4 app/build/outputs/apk/release/app-release-unsigned.apk aligned.apk | |
| # 4. Sign the APK using env variables | |
| $BUILD_TOOLS_PATH/apksigner sign --ks release.jks \ | |
| --ks-key-alias "$ALIAS" \ | |
| --ks-pass pass:"$KEY_PASSWORD" \ | |
| --key-pass pass:"$KEY_PASSWORD" \ | |
| --out OpenPillReminder-${{ github.event.inputs.tag_name }}.apk \ | |
| aligned.apk | |
| # 5. Cleanup | |
| rm release.jks aligned.apk | |
| - name: Generate APK Hash | |
| id: generate_hash | |
| run: | | |
| sha256=$(sha256sum OpenPillReminder-${{ github.event.inputs.tag_name }}.apk | awk '{ print $1 }') | |
| echo "apk_sha=$sha256" >> $GITHUB_OUTPUT | |
| echo "SHA-256 Hash of APK: $sha256" | |
| - name: Create Draft Release with APK | |
| uses: softprops/action-gh-release@v3 | |
| with: | |
| tag_name: ${{ github.event.inputs.tag_name }} | |
| name: ${{ github.event.inputs.release_name }} | |
| draft: true | |
| files: OpenPillReminder-${{ github.event.inputs.tag_name }}.apk | |
| body: | | |
| <!-- Write changelog here --> | |
| --- | |
| ### Security Verification | |
| **APK SHA-256 Hash:** `${{ steps.generate_hash.outputs.apk_sha }}` | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |