|
| 1 | +name: Build APK |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - "*" |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout Repo |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Setup Java |
| 22 | + uses: actions/setup-java@v4 |
| 23 | + with: |
| 24 | + distribution: "temurin" |
| 25 | + java-version: "17" |
| 26 | + |
| 27 | + - name: Setup Android SDK |
| 28 | + uses: android-actions/setup-android@v3 |
| 29 | + |
| 30 | + - name: Setup Gradle |
| 31 | + uses: gradle/actions/setup-gradle@v4 |
| 32 | + |
| 33 | + - name: Decode Keystore |
| 34 | + run: echo "${{ secrets.KEYSTORE_B64 }}" | base64 -d > app/keystore.jks |
| 35 | + env: |
| 36 | + KEYSTORE_B64: ${{ secrets.KEYSTORE_B64 }} |
| 37 | + |
| 38 | + - name: Validate Keystore |
| 39 | + run: | |
| 40 | + md5=$(md5sum app/keystore.jks | awk '{print $1}') |
| 41 | + echo "Keystore MD5: $md5" |
| 42 | + if [ "$md5" != "9a8b86ee3370d37b2c8792ede9ff448a" ]; then |
| 43 | + echo "Keystore MD5 mismatch!" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Make gradlew executable |
| 48 | + run: chmod +x ./gradlew |
| 49 | + |
| 50 | + - name: Build Debug APK |
| 51 | + run: ./gradlew assembleDebug |
| 52 | + |
| 53 | + - name: Build Release APK |
| 54 | + run: ./gradlew assembleRelease -PstorePassword=${{ secrets.STORE_PASSWORD }} -PkeyPassword=${{ secrets.KEY_PASSWORD }} -PkeyAlias=${{ secrets.KEY_ALIAS }} |
| 55 | + |
| 56 | + - name: Upload Debug APK |
| 57 | + if: success() |
| 58 | + uses: actions/upload-artifact@v4 |
| 59 | + with: |
| 60 | + name: ko-debug-apk |
| 61 | + path: app/build/outputs/apk/debug/*.apk |
| 62 | + |
| 63 | + - name: Upload Release APK |
| 64 | + if: success() |
| 65 | + uses: actions/upload-artifact@v4 |
| 66 | + with: |
| 67 | + name: ko-release-apk |
| 68 | + path: app/build/outputs/apk/release/*.apk |
| 69 | + |
| 70 | + - name: Prepare Release Assets and Metadata |
| 71 | + if: success() |
| 72 | + id: release-prep |
| 73 | + run: | |
| 74 | + release_dir="$GITHUB_WORKSPACE/release_staging" |
| 75 | + mkdir -p "$release_dir" |
| 76 | +
|
| 77 | + cp app/build/outputs/apk/debug/*.apk "$release_dir/Ko-debug.apk" |
| 78 | + cp app/build/outputs/apk/release/*.apk "$release_dir/Ko-release.apk" |
| 79 | +
|
| 80 | + version=$(grep '^version=' version.properties | cut -d'=' -f2) |
| 81 | + if [ -z "$version" ]; then |
| 82 | + echo "Failed to get version from version.properties" |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | + echo "Version: $version" |
| 86 | +
|
| 87 | + sha256_debug=$(sha256sum "$release_dir/Ko-debug.apk" | awk '{print $1}') |
| 88 | + sha256_release=$(sha256sum "$release_dir/Ko-release.apk" | awk '{print $1}') |
| 89 | + echo "SHA256 debug: $sha256_debug" |
| 90 | + echo "SHA256 release: $sha256_release" |
| 91 | +
|
| 92 | + build_date=$(date -u +"%Y-%m-%d %H:%M:%S UTC") |
| 93 | + echo "Build Date: $build_date" |
| 94 | +
|
| 95 | + commit_hash_full=$(git rev-parse HEAD) |
| 96 | + commit_hash_short=$(git rev-parse --short=7 HEAD) |
| 97 | + commit_message=$(git log -1 --pretty=%B) |
| 98 | + if [ -z "$commit_message" ]; then |
| 99 | + commit_message="(No commit message provided)" |
| 100 | + fi |
| 101 | + echo "Commit message: '$commit_message'" |
| 102 | +
|
| 103 | + commit_title=$(echo "$commit_message" | head -n1) |
| 104 | + commit_body=$(echo "$commit_message" | tail -n +2 | grep -v '^$') |
| 105 | +
|
| 106 | + metadata_path="$release_dir/Ko.metadata.txt" |
| 107 | + { |
| 108 | + echo "Build Timestamp: $build_date" |
| 109 | + echo "Commit: $commit_hash_full" |
| 110 | + echo "SHA256 debug: $sha256_debug" |
| 111 | + echo "SHA256 release: $sha256_release" |
| 112 | + echo "Version: $version" |
| 113 | + echo "Commit Message:" |
| 114 | + echo "$commit_message" |
| 115 | + } > "$metadata_path" |
| 116 | +
|
| 117 | + release_notes_path="$release_dir/release_notes.md" |
| 118 | + { |
| 119 | + echo "Ko v$version" |
| 120 | + echo "" |
| 121 | + echo "Build Date: $build_date" |
| 122 | + echo "SHA256 debug: $sha256_debug (Ko-debug.apk)" |
| 123 | + echo "SHA256 release: $sha256_release (Ko-release.apk)" |
| 124 | + echo "" |
| 125 | + echo "Changes" |
| 126 | + echo "" |
| 127 | + echo "Built from commit: [$commit_hash_short](https://github.com/DarkPhilosophy/Ko/commit/$commit_hash_full)" |
| 128 | + echo "Commit message:" |
| 129 | + echo "## $commit_title" |
| 130 | + if [ -n "$commit_body" ]; then |
| 131 | + echo "$commit_body" | sed 's/^/- /' |
| 132 | + fi |
| 133 | + echo "" |
| 134 | + } > "$release_notes_path" |
| 135 | +
|
| 136 | + echo "version=$version" >> $GITHUB_OUTPUT |
| 137 | + echo "assets_path=$release_dir" >> $GITHUB_OUTPUT |
| 138 | + echo "release_notes_path=$release_notes_path" >> $GITHUB_OUTPUT |
| 139 | +
|
| 140 | + - name: Upload Build Artifact (for debugging/retention) |
| 141 | + if: success() |
| 142 | + uses: actions/upload-artifact@v4 |
| 143 | + with: |
| 144 | + name: Ko-Build-${{ steps.release-prep.outputs.version || github.run_number }} |
| 145 | + path: ${{ steps.release-prep.outputs.assets_path }}/ |
| 146 | + if-no-files-found: warn |
| 147 | + retention-days: 7 |
| 148 | + |
| 149 | + - name: Create Release on Tag |
| 150 | + if: startsWith(github.ref, 'refs/tags/v') |
| 151 | + uses: softprops/action-gh-release@v2 |
| 152 | + with: |
| 153 | + name: Release - Ko v${{ steps.release-prep.outputs.version }} |
| 154 | + tag_name: ${{ github.ref_name }} |
| 155 | + body_path: ${{ steps.release-prep.outputs.release_notes_path }} |
| 156 | + files: | |
| 157 | + ${{ steps.release-prep.outputs.assets_path }}/Ko-debug.apk |
| 158 | + ${{ steps.release-prep.outputs.assets_path }}/Ko-release.apk |
| 159 | + ${{ steps.release-prep.outputs.assets_path }}/Ko.metadata.txt |
| 160 | + draft: false |
| 161 | + prerelease: false |
| 162 | + env: |
| 163 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 164 | + |
| 165 | + - name: Create GitHub Release on 'main' branch |
| 166 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 167 | + uses: softprops/action-gh-release@v2 |
| 168 | + with: |
| 169 | + name: Release - Ko v${{ steps.release-prep.outputs.version }} |
| 170 | + tag_name: v${{ steps.release-prep.outputs.version }} |
| 171 | + body_path: ${{ steps.release-prep.outputs.release_notes_path }} |
| 172 | + files: | |
| 173 | + ${{ steps.release-prep.outputs.assets_path }}/Ko-debug.apk |
| 174 | + ${{ steps.release-prep.outputs.assets_path }}/Ko-release.apk |
| 175 | + ${{ steps.release-prep.outputs.assets_path }}/Ko.metadata.txt |
| 176 | + draft: false |
| 177 | + prerelease: false |
| 178 | + env: |
| 179 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments