|
| 1 | +name: Build Android APK & Publish F-Droid Repo |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + pages: write |
| 11 | + id-token: write |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: "build-and-deploy" |
| 15 | + cancel-in-progress: false |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-and-release: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + semver: ${{ steps.gitversion.outputs.semVer }} |
| 22 | + version-code: ${{ steps.version-code.outputs.code }} |
| 23 | + apk-url: ${{ steps.upload-release.outputs.apk-url }} |
| 24 | + apk-hash: ${{ steps.apk-hash.outputs.sha256 }} |
| 25 | + apk-size: ${{ steps.apk-hash.outputs.size }} |
| 26 | + steps: |
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + fetch-depth: 0 # Full history for GitVersion |
| 31 | + |
| 32 | + - name: Setup .NET |
| 33 | + uses: actions/setup-dotnet@v4 |
| 34 | + with: |
| 35 | + dotnet-version: '9.0.x' |
| 36 | + |
| 37 | + - name: Install Android workload |
| 38 | + run: dotnet workload install android |
| 39 | + |
| 40 | + - name: Install GitVersion |
| 41 | + uses: gittools/actions/gitversion/setup@v3.2.1 |
| 42 | + with: |
| 43 | + versionSpec: '6.x' |
| 44 | + |
| 45 | + - name: Determine version |
| 46 | + id: gitversion |
| 47 | + uses: gittools/actions/gitversion/execute@v3.2.1 |
| 48 | + with: |
| 49 | + useConfigFile: false |
| 50 | + |
| 51 | + - name: Display version |
| 52 | + run: | |
| 53 | + echo "SemVer: ${{ steps.gitversion.outputs.semVer }}" |
| 54 | + echo "FullSemVer: ${{ steps.gitversion.outputs.fullSemVer }}" |
| 55 | + echo "Major: ${{ steps.gitversion.outputs.major }}" |
| 56 | + echo "Minor: ${{ steps.gitversion.outputs.minor }}" |
| 57 | + echo "Patch: ${{ steps.gitversion.outputs.patch }}" |
| 58 | + echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.commitsSinceVersionSource }}" |
| 59 | +
|
| 60 | + - name: Calculate version code |
| 61 | + id: version-code |
| 62 | + run: | |
| 63 | + MAJOR=${{ steps.gitversion.outputs.major }} |
| 64 | + MINOR=${{ steps.gitversion.outputs.minor }} |
| 65 | + PATCH=${{ steps.gitversion.outputs.patch }} |
| 66 | + COMMITS=${{ steps.gitversion.outputs.commitsSinceVersionSource }} |
| 67 | + # version code = major*10000 + minor*1000 + patch*100 + commits |
| 68 | + CODE=$(( MAJOR * 10000 + MINOR * 1000 + PATCH * 100 + COMMITS )) |
| 69 | + if [ "$CODE" -lt 1 ]; then CODE=1; fi |
| 70 | + echo "code=$CODE" >> "$GITHUB_OUTPUT" |
| 71 | + echo "Version code: $CODE" |
| 72 | +
|
| 73 | + - name: Decode keystore |
| 74 | + if: env.KEYSTORE_BASE64 != '' |
| 75 | + env: |
| 76 | + KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }} |
| 77 | + run: | |
| 78 | + echo "$KEYSTORE_BASE64" | base64 -d > ${{ github.workspace }}/release.keystore |
| 79 | +
|
| 80 | + - name: Build Android APK |
| 81 | + run: | |
| 82 | + SIGNING_ARGS="" |
| 83 | + if [ -f "${{ github.workspace }}/release.keystore" ]; then |
| 84 | + SIGNING_ARGS="/p:AndroidSigningKeyStore=${{ github.workspace }}/release.keystore /p:AndroidSigningKeyAlias=${{ secrets.ANDROID_KEY_ALIAS }} /p:AndroidSigningStorePass=${{ secrets.ANDROID_KEYSTORE_PASSWORD }} /p:AndroidSigningKeyPass=${{ secrets.ANDROID_KEY_PASSWORD }}" |
| 85 | + fi |
| 86 | + dotnet publish src/RequestTracker.Android/RequestTracker.Android.csproj \ |
| 87 | + -c Release \ |
| 88 | + -f net9.0-android \ |
| 89 | + /p:ApplicationVersion=${{ steps.version-code.outputs.code }} \ |
| 90 | + /p:ApplicationDisplayVersion=${{ steps.gitversion.outputs.semVer }} \ |
| 91 | + $SIGNING_ARGS |
| 92 | +
|
| 93 | + - name: Find and rename APK |
| 94 | + id: find-apk |
| 95 | + run: | |
| 96 | + APK=$(find src/RequestTracker.Android/bin/Release -name "*.apk" | head -1) |
| 97 | + if [ -z "$APK" ]; then |
| 98 | + echo "ERROR: No APK found!" |
| 99 | + find src/RequestTracker.Android/bin/Release -type f |
| 100 | + exit 1 |
| 101 | + fi |
| 102 | + DEST="src/RequestTracker.Android/bin/Release/RequestTracker-${{ steps.gitversion.outputs.semVer }}.apk" |
| 103 | + cp "$APK" "$DEST" |
| 104 | + echo "apk-path=$DEST" >> "$GITHUB_OUTPUT" |
| 105 | + echo "Found APK: $APK -> $DEST" |
| 106 | +
|
| 107 | + - name: Compute APK hash and size |
| 108 | + id: apk-hash |
| 109 | + run: | |
| 110 | + APK="${{ steps.find-apk.outputs.apk-path }}" |
| 111 | + SHA256=$(sha256sum "$APK" | awk '{print $1}') |
| 112 | + SIZE=$(stat -c%s "$APK") |
| 113 | + echo "sha256=$SHA256" >> "$GITHUB_OUTPUT" |
| 114 | + echo "size=$SIZE" >> "$GITHUB_OUTPUT" |
| 115 | + echo "APK SHA-256: $SHA256" |
| 116 | + echo "APK size: $SIZE bytes" |
| 117 | +
|
| 118 | + - name: Create GitHub Release |
| 119 | + id: create-release |
| 120 | + uses: softprops/action-gh-release@v2 |
| 121 | + with: |
| 122 | + tag_name: v${{ steps.gitversion.outputs.semVer }} |
| 123 | + name: RequestTracker v${{ steps.gitversion.outputs.semVer }} |
| 124 | + body: | |
| 125 | + ## RequestTracker v${{ steps.gitversion.outputs.semVer }} |
| 126 | +
|
| 127 | + ### Android APK |
| 128 | + - **Version**: ${{ steps.gitversion.outputs.semVer }} |
| 129 | + - **Version Code**: ${{ steps.version-code.outputs.code }} |
| 130 | + - **SHA-256**: `${{ steps.apk-hash.outputs.sha256 }}` |
| 131 | +
|
| 132 | + ### Install via F-Droid |
| 133 | + Add this repo URL to your F-Droid client: |
| 134 | + ``` |
| 135 | + https://sharpninja.github.io/RequestTracker/fdroid/repo |
| 136 | + ``` |
| 137 | + draft: false |
| 138 | + prerelease: ${{ contains(steps.gitversion.outputs.semVer, '-') }} |
| 139 | + files: ${{ steps.find-apk.outputs.apk-path }} |
| 140 | + |
| 141 | + - name: Get APK release asset URL |
| 142 | + id: upload-release |
| 143 | + run: | |
| 144 | + # Get the direct download URL for the APK asset from the release |
| 145 | + TAG="v${{ steps.gitversion.outputs.semVer }}" |
| 146 | + APK_NAME="RequestTracker-${{ steps.gitversion.outputs.semVer }}.apk" |
| 147 | + APK_URL="https://github.com/${{ github.repository }}/releases/download/${TAG}/${APK_NAME}" |
| 148 | + echo "apk-url=$APK_URL" >> "$GITHUB_OUTPUT" |
| 149 | + echo "APK release URL: $APK_URL" |
| 150 | +
|
| 151 | + deploy-fdroid: |
| 152 | + needs: build-and-release |
| 153 | + runs-on: ubuntu-latest |
| 154 | + environment: |
| 155 | + name: github-pages |
| 156 | + url: ${{ steps.deployment.outputs.page_url }} |
| 157 | + steps: |
| 158 | + - name: Checkout |
| 159 | + uses: actions/checkout@v4 |
| 160 | + |
| 161 | + - name: Setup Python |
| 162 | + uses: actions/setup-python@v5 |
| 163 | + with: |
| 164 | + python-version: '3.12' |
| 165 | + |
| 166 | + - name: Generate F-Droid repo metadata |
| 167 | + run: | |
| 168 | + python .github/scripts/generate_fdroid_repo.py \ |
| 169 | + --version "${{ needs.build-and-release.outputs.semver }}" \ |
| 170 | + --version-code "${{ needs.build-and-release.outputs.version-code }}" \ |
| 171 | + --apk-url "${{ needs.build-and-release.outputs.apk-url }}" \ |
| 172 | + --apk-hash "${{ needs.build-and-release.outputs.apk-hash }}" \ |
| 173 | + --apk-size "${{ needs.build-and-release.outputs.apk-size }}" \ |
| 174 | + --repo-url "https://sharpninja.github.io/RequestTracker/fdroid/repo" \ |
| 175 | + --output-dir docs/fdroid/repo |
| 176 | +
|
| 177 | + - name: Show generated metadata |
| 178 | + run: | |
| 179 | + echo "=== index-v1.json ===" |
| 180 | + cat docs/fdroid/repo/index-v1.json |
| 181 | + echo "" |
| 182 | + echo "=== entry.json ===" |
| 183 | + cat docs/fdroid/repo/entry.json |
| 184 | +
|
| 185 | + - name: Setup Pages |
| 186 | + uses: actions/configure-pages@v5 |
| 187 | + |
| 188 | + - name: Upload Pages artifact |
| 189 | + uses: actions/upload-pages-artifact@v3 |
| 190 | + with: |
| 191 | + path: docs/fdroid |
| 192 | + |
| 193 | + - name: Deploy to GitHub Pages |
| 194 | + id: deployment |
| 195 | + uses: actions/deploy-pages@v4 |
0 commit comments