name: Android Release (static debug key) # Same flow as android-release.yml, but the APK is signed with a static debug key instead of the # release keystore. The key is created on the first run, committed to CollabTableAndroid/signing/, and # reused by every later run, so builds from this workflow can update each other in place. It is for # test builds only: the release keystore is secret and this key is not. on: workflow_dispatch: inputs: bump_type: description: 'Version bump type' required: true default: 'patch' type: choice options: - patch - minor - major changelog: description: 'Changelog for this release (leave blank to auto-generate from commits)' required: false type: string # The first run creates the key and pushes it. Queue runs so that a later run sees the key instead of # creating a second one. concurrency: group: android-release-static-debug cancel-in-progress: false jobs: release: name: Bump version, build & release (static debug key) runs-on: ubuntu-latest permissions: contents: write env: # Android debug keystore conventions (password "android", alias "androiddebugkey"). STATIC_KEYSTORE: CollabTableAndroid/signing/static-debug.jks STATIC_STORE_PASSWORD: android STATIC_KEY_ALIAS: androiddebugkey STATIC_KEY_PASSWORD: android steps: - name: Checkout uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} fetch-depth: 0 # Java comes first: the key is checked with keytool before anything is pushed. - name: Set up JDK 21 uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '21' cache: 'gradle' # A key is generated only when the repository has never held one. If the file was committed # before but is now missing, the run stops: a new key would change the certificate and break # in-place updates for every installed copy. - name: Prepare static debug key shell: bash run: | set -euo pipefail if [ -f "$STATIC_KEYSTORE" ]; then echo "Reusing the static debug key in $STATIC_KEYSTORE" elif [ -n "$(git log --all --format=%H -- "$STATIC_KEYSTORE")" ]; then echo "::error::$STATIC_KEYSTORE exists in the repository history but not on this branch. Restore it (merge or cherry-pick) instead of generating a new key." exit 1 else mkdir -p "$(dirname "$STATIC_KEYSTORE")" keytool -genkeypair -noprompt \ -keystore "$STATIC_KEYSTORE" \ -storetype PKCS12 \ -storepass:env STATIC_STORE_PASSWORD \ -keypass:env STATIC_KEY_PASSWORD \ -alias "$STATIC_KEY_ALIAS" \ -keyalg RSA -keysize 2048 -validity 10000 \ -dname "CN=Android Debug,O=Android,C=US" git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add "$STATIC_KEYSTORE" git commit -m "chore(android): add static debug signing key" git push echo "Created the static debug key and pushed it to the repository." fi FINGERPRINT=$(keytool -list -v -keystore "$STATIC_KEYSTORE" -storepass:env STATIC_STORE_PASSWORD \ -alias "$STATIC_KEY_ALIAS" | sed -n 's/^[[:space:]]*SHA256: //p') echo "::notice::Static debug certificate SHA-256: $FINGERPRINT" - name: Bump version in build.gradle.kts id: version shell: bash env: BUMP_TYPE: ${{ inputs.bump_type }} run: | GRADLE_FILE="CollabTableAndroid/app/build.gradle" CURRENT_CODE=$(grep -oP 'versionCode\s*=\s*\K[0-9]+' "$GRADLE_FILE") CURRENT_NAME=$(grep -oP 'versionName\s*=\s*"\K[^"]+' "$GRADLE_FILE") IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_NAME" case "$BUMP_TYPE" in major) MAJOR=$((MAJOR+1)); MINOR=0; PATCH=0 ;; minor) MINOR=$((MINOR+1)); PATCH=0 ;; patch) PATCH=$((PATCH+1)) ;; esac NEW_CODE=$((CURRENT_CODE+1)) NEW_NAME="${MAJOR}.${MINOR}.${PATCH}" sed -i "s/versionCode = ${CURRENT_CODE}/versionCode = ${NEW_CODE}/" "$GRADLE_FILE" sed -i "s/versionName = \"${CURRENT_NAME}\"/versionName = \"${NEW_NAME}\"/" "$GRADLE_FILE" { echo "new_code=${NEW_CODE}" echo "new_name=${NEW_NAME}" echo "tag=v${NEW_NAME}-debug" } >> "$GITHUB_OUTPUT" - name: Commit version bump shell: bash run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add CollabTableAndroid/app/build.gradle git commit -m "chore(android): bump version to ${{ steps.version.outputs.new_name }} (code ${{ steps.version.outputs.new_code }})" git push - name: Set up Gradle uses: gradle/actions/setup-gradle@v3 - name: Install Android SDK uses: android-actions/setup-android@v4 - name: Accept SDK licenses shell: bash run: yes | sdkmanager --licenses || true # Install the compileSdk platform, build-tools 36.0.0 (used by AGP lint) and 37.0.0 (used by apksigner below). - name: Install Android SDK packages shell: bash run: | sdkmanager "platform-tools" "platforms;android-37.2" "build-tools;36.0.0" "build-tools;37.0.0" - name: Run lint and ktlint working-directory: CollabTableAndroid shell: bash run: | chmod +x gradlew ./gradlew --no-daemon lintDebug ktlintCheck # The release build type picks up the signing config from these variables, so the static key # is used without any change to the Gradle build. - name: Build release APK signed with the static debug key working-directory: CollabTableAndroid shell: bash env: OGS_KEYSTORE_FILE: ${{ github.workspace }}/${{ env.STATIC_KEYSTORE }} OGS_KEYSTORE_PASSWORD: ${{ env.STATIC_STORE_PASSWORD }} OGS_KEY_ALIAS: ${{ env.STATIC_KEY_ALIAS }} OGS_KEY_PASSWORD: ${{ env.STATIC_KEY_PASSWORD }} run: ./gradlew --no-daemon assembleRelease - name: Verify APK is signed with the static debug key shell: bash run: | set -euo pipefail APK="CollabTableAndroid/app/build/outputs/apk/release/app-release.apk" APKSIGNER="$ANDROID_HOME/build-tools/37.0.0/apksigner" CERTS=$("$APKSIGNER" verify --print-certs "$APK") ACTUAL=$(printf '%s\n' "$CERTS" | sed -n 's/^.*certificate SHA-256 digest: //p' | sed -n '1p') EXPECTED=$(keytool -list -v -keystore "$STATIC_KEYSTORE" -storepass:env STATIC_STORE_PASSWORD \ -alias "$STATIC_KEY_ALIAS" | sed -n 's/^[[:space:]]*SHA256: //p' | tr -d ':' | tr 'A-F' 'a-f') if [ "$ACTUAL" != "$EXPECTED" ]; then echo "::error::APK is signed with $ACTUAL, expected the static debug key $EXPECTED." exit 1 fi - name: Rename APK with version shell: bash run: | SRC="CollabTableAndroid/app/build/outputs/apk/release/app-release.apk" cp "$SRC" "CollabTable-${{ steps.version.outputs.tag }}.apk" - name: Generate changelog shell: bash env: CHANGELOG_INPUT: ${{ inputs.changelog }} run: | if [ -n "$CHANGELOG_INPUT" ]; then printf '%s' "$CHANGELOG_INPUT" > release-notes.md else LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") if [ -n "$LAST_TAG" ]; then RANGE="${LAST_TAG}..HEAD" else RANGE="HEAD" fi COMMITS=$(git log "$RANGE" --pretty=format:"%s" | grep -vE "^chore\(android\): (bump version|add static debug signing key)" || true) FEATURES=$(echo "$COMMITS" | grep -E "^feat(\\(.+\\))?:" | sed 's/^feat[^:]*: /- /' || true) FIXES=$(echo "$COMMITS" | grep -E "^fix(\\(.+\\))?:" | sed 's/^fix[^:]*: /- /' || true) OTHERS=$(echo "$COMMITS" | grep -vE "^(feat|fix)(\\(.+\\))?:" | grep -v '^$' | sed 's/^/- /' || true) { if [ -n "$FEATURES" ]; then printf '### Features\n%s\n\n' "$FEATURES"; fi if [ -n "$FIXES" ]; then printf '### Bug Fixes\n%s\n\n' "$FIXES"; fi if [ -n "$OTHERS" ]; then printf '### Other Changes\n%s\n\n' "$OTHERS"; fi } > release-notes.md if [ ! -s release-notes.md ]; then echo 'No changes recorded.' > release-notes.md; fi fi # Marked as a pre-release so it never takes the "Latest" badge from the real release. - name: Create GitHub pre-release uses: softprops/action-gh-release@v2 with: tag_name: ${{ steps.version.outputs.tag }} name: ${{ steps.version.outputs.tag }} (static debug key) body_path: release-notes.md files: CollabTable-${{ steps.version.outputs.tag }}.apk prerelease: true fail_on_unmatched_files: true