Files
quik/.github/workflows/bump-and-build.yml
T
2025-06-28 08:11:28 -04:00

141 lines
5.0 KiB
YAML

on:
workflow_dispatch:
push:
tags:
- "v*"
env:
APK_PATH: presentation/build/outputs/apk/release/QUIK-release.apk
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
version_name: ${{ steps.bump.outputs.version_name }}
version_code: ${{ steps.bump.outputs.version_code }}
release_notes: ${{ steps.notes.outputs.notes }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch full history for git log & tags
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Bump version in Gradle
id: bump
working-directory: presentation
run: |
LINE=$(grep "versionName" build.gradle)
VER=$(echo "$LINE" | sed -E "s/.*versionName ['\"]([0-9]+\.[0-9]+\.[0-9]+)['\"].*/\1/")
CODE=$(grep "versionCode" build.gradle | awk '{print $2}')
IFS='.' read MAJ MIN PAT <<<"$VER"
MIN=$((MIN + 1)); PAT=0
NEW_VER="$MAJ.$MIN.$PAT"
NEW_CODE=$((CODE + 1))
sed -i "s/versionName.*/versionName '$NEW_VER'/" build.gradle
sed -i "s/versionCode.*/versionCode $NEW_CODE/" build.gradle
echo "version_name=$NEW_VER" >> $GITHUB_OUTPUT
echo "version_code=$NEW_CODE" >> $GITHUB_OUTPUT
- name: Generate release notes from commits
id: notes
run: |
git fetch --tags
# find the previous tag, or root commit if none
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || git rev-list --max-parents=0 HEAD)
NOTES=$(git log "$LAST_TAG"..HEAD --pretty=format:"* %s")
echo "::set-output name=notes::$NOTES"
- name: Update changelog.json
run: |
VN=${{ steps.bump.outputs.version_name }}
VC=${{ steps.bump.outputs.version_code }}
NOTES="${{ steps.notes.outputs.notes }}"
# build JSON array of bullet lines
NOTES_JSON=$(printf '%s\n' "$NOTES" | jq -R . | jq -s .)
jq \
--arg versionName "$VN" \
--argjson versionCode "$VC" \
--argjson notes "$NOTES_JSON" \
'. += [{versionName: $versionName, versionCode: $versionCode, notes: $notes}]' \
data/src/main/assets/changelog.json > changelog.tmp.json
mv changelog.tmp.json data/src/main/assets/changelog.json
- name: Commit & push bump + changelog
run: |
BRANCH="bump/${{ steps.bump.outputs.version_name }}-${{ github.run_id }}"
git checkout -b "$BRANCH"
git add presentation/build.gradle data/src/main/assets/changelog.json
git commit -m "chore: bump to ${{ steps.bump.outputs.version_name }} & update changelog [skip ci]" || exit 0
git push --set-upstream origin "$BRANCH"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: bump/${{ steps.bump.outputs.version_name }}-${{ github.run_id }}
base: master
title: "chore: bump to ${{ steps.bump.outputs.version_name }}"
body: |
## Release ${{ steps.bump.outputs.version_name }}
${{ steps.notes.outputs.notes }}
build:
needs: prepare
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Decode Keystore
run: echo "${{ secrets.KEYSTORE_FILE }}" | base64 -d > my-release-key.keystore
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build Release APK
run: |
./gradlew presentation:assembleRelease \
-Pandroid.injected.signing.store.file=$PWD/my-release-key.keystore \
-Pandroid.injected.signing.store.password=${{ secrets.KEYSTORE_PASSWORD }} \
-Pandroid.injected.signing.key.alias=${{ secrets.KEY_ALIAS }} \
-Pandroid.injected.signing.key.password=${{ secrets.KEY_PASSWORD }}
- name: Rename APK
run: mv presentation/build/outputs/apk/release/QUIK-*-release.apk $APK_PATH
- name: Upload APK artifact
uses: actions/upload-artifact@v4
with:
name: QUIK-release.apk
path: $APK_PATH
release:
if: github.event_name == 'push'
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate release notes from commits
id: notes
run: |
git fetch --tags
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || git rev-list --max-parents=0 HEAD)
NOTES=$(git log "$LAST_TAG"..HEAD --pretty=format:"* %s")
echo "::set-output name=notes::$NOTES"
- name: Create GitHub Release
uses: actions/create-release@v1
with:
tag_name: ${{ github.ref_name }}
body: ${{ steps.notes.outputs.notes }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}