|
| 1 | +name: APK Release Draft |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + app_name: |
| 7 | + description: 'App Name' |
| 8 | + required: true |
| 9 | + default: 'SensorServer' |
| 10 | + tag_name: |
| 11 | + description: 'Tag Name' |
| 12 | + required: true |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-release: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@v3 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Decode Keystore |
| 28 | + id: decode_keystore |
| 29 | + uses: timheuer/base64-to-file@v1 |
| 30 | + with: |
| 31 | + fileName: "keystore" |
| 32 | + encodedString: ${{ secrets.ANDROID_KEYSTORE_BASE_64 }} |
| 33 | + |
| 34 | + - name: Set up Java |
| 35 | + uses: actions/setup-java@v3 |
| 36 | + with: |
| 37 | + distribution: 'temurin' |
| 38 | + java-version: '21' |
| 39 | + |
| 40 | + - name: Grant execute permission to gradlew |
| 41 | + run: chmod +x ./gradlew |
| 42 | + |
| 43 | + - name: Build APK |
| 44 | + run: | |
| 45 | + ./gradlew assembleRelease \ |
| 46 | + -Pandroid.injected.signing.store.file=${{ steps.decode_keystore.outputs.filePath }} \ |
| 47 | + -Pandroid.injected.signing.store.password=${{ secrets.ANDROID_KEYSTORE_STORE_PASSWORD }} \ |
| 48 | + -Pandroid.injected.signing.key.alias=${{ secrets.ANDROID_KEYSTORE_ALIAS }} \ |
| 49 | + -Pandroid.injected.signing.key.password=${{ secrets.ANDROID_KEYSTORE_PASSWORD }} |
| 50 | +
|
| 51 | + - name: Rename APK |
| 52 | + run: | |
| 53 | + mv app/build/outputs/apk/release/app-release.apk "${{ github.event.inputs.app_name }}-${{ github.event.inputs.tag_name }}.apk" |
| 54 | + echo "renamed_apk=${{ github.event.inputs.app_name }}-${{ github.event.inputs.tag_name }}.apk" >> $GITHUB_ENV |
| 55 | +
|
| 56 | + # It uses `continue-on-error: true` so the job won't fail if it breaks |
| 57 | + - name: Get commit messages since last tag |
| 58 | + id: release_notes |
| 59 | + continue-on-error: true |
| 60 | + run: | |
| 61 | + git fetch --tags |
| 62 | + LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 63 | + if [ -z "$LAST_TAG" ]; then |
| 64 | + git log --pretty=format:"%s %h" > changelog.txt |
| 65 | + else |
| 66 | + git log ${LAST_TAG}..HEAD --pretty=format:"%s %h" > changelog.txt |
| 67 | + fi |
| 68 | + |
| 69 | +
|
| 70 | + # If previous step failed |
| 71 | + - name: Ensure changelog.txt exists |
| 72 | + if: failure() |
| 73 | + run: echo "unable to find commits from last tag" > changelog.txt |
| 74 | + |
| 75 | + |
| 76 | + - name: Upload APK Artifact |
| 77 | + uses: actions/upload-artifact@v4 |
| 78 | + with: |
| 79 | + name: ${{ github.event.inputs.app_name }}-${{ github.event.inputs.tag_name }} |
| 80 | + path: ${{ env.renamed_apk }} |
| 81 | + |
| 82 | + - name: Create Release Draft |
| 83 | + uses: ncipollo/release-action@v1 |
| 84 | + with: |
| 85 | + artifacts: ${{ env.renamed_apk }} |
| 86 | + tag: ${{ github.event.inputs.tag_name }} |
| 87 | + draft: true |
| 88 | + name: ${{ github.event.inputs.tag_name }} |
| 89 | + prerelease: false |
| 90 | + bodyFile: changelog.txt |
0 commit comments