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

177 lines
6.0 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Bump + Release + F-Droid
on:
workflow_dispatch:
push:
tags:
- "v*"
jobs:
release:
runs-on: ubuntu-latest
env:
META_YML: fdroid/metadata/dev.octoshrimpy.quik.yml
GRADLE_FILE: presentation/build.gradle
CHANGELOG: "data/src/main/assets/changelog.json"
steps:
# 1) Checkout full history so tags are available
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: true
# 2) Install fdroidserver & bump metadata.yml
- name: Set up Python & fdroidserver
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Bump F-Droid metadata
run: |
pip3 install fdroidserver
fdroid update --skip-pulls --checkmetadata "$META_YML"
- name: Commit F-Droid metadata.yml
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add "$META_YML"
git diff --quiet --cached || git commit -m "chore: bump F-Droid metadata"
# 3) Set up Java & jq for the rest
- name: Set up Java 17
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: '17'
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
# 4) Bump Android versions & capture NEW_CODE/NEW_NAME
- name: Bump Android version & update build.gradle
id: bump
run: |
set -euo pipefail
# extract current
current_code=$(grep -E '^[[:space:]]*versionCode ' "$GRADLE_FILE" | awk '{print $2}')
current_name=$(grep -E '^[[:space:]]*versionName ' "$GRADLE_FILE" \
| grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
# bump
new_code=$((current_code + 1))
IFS='.' read -r major minor patch <<< "$current_name"
new_name="${major}.$((minor + 1)).0"
# apply
sed -i \
-e "s|^[[:space:]]*versionCode[[:space:]]\+$current_code|versionCode $new_code|" \
-e "s|^[[:space:]]*versionName[[:space:]]\+'$current_name'|versionName '$new_name'|" \
"$GRADLE_FILE"
echo "NEW_CODE=$new_code" >> $GITHUB_ENV
echo "NEW_NAME=$new_name" >> $GITHUB_ENV
echo "Bumped to $new_name ($new_code)"
# 5) Gather commits & prepend to changelog.json
- name: Update changelog.json & write F-Droid txt
run: |
set -euo pipefail
# determine previous tag or fallback
# try the exact tag for LAST release, based on NEW_NAME
prev_tag="v${NEW_NAME}"
if git rev-parse --verify --quiet "$prev_tag" >/dev/null; then
base="$prev_tag"
echo "ℹ️ Found previous tag $prev_tag"
else
# fallback: latest numeric tag
base=$(git describe --tags --match "v[0-9]*" --abbrev=0 2>/dev/null || echo "")
if [[ -n "$base" ]]; then
echo "ℹ️ Previous tag $prev_tag not found; using latest tag $base"
else
echo "⚠️ No tags found; including entire history"
fi
fi
[[ -n "$base" ]] && range="$base..HEAD" || range="HEAD"
# gather, clean, dedupe, oldest→newest
mapfile -t commits < <(
git log --no-merges --reverse --pretty=format:"%s by %an" $range \
| sed -E 's/[[:space:]]*\.*[[:space:]]+by/ by/' \
| sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//' \
| awk '!seen[$0]++'
)
# build JSON array
if (( ${#commits[@]} )); then
changes_json=$(printf '%s\n' "${commits[@]}" | jq -R . | jq -s .)
else
changes_json="[]"
fi
# prepend new entry
jq --argjson changes "$changes_json" \
--arg vc "$new_code" \
--arg vn "$new_name" \
'
# 1) helper to capitalize first character
def capfirst:
sub("^(.)"; "\(ascii_upcase(.1))");
# 2) apply capitalization to all changes
$all := ($changes | map(capfirst));
# 3) split into fixes vs other changes
$fixes := $all | map(select(test("^(Fix|fix)")));
$others := $all | map(select(test("^(Fix|fix)") | not));
# 4) build the new entry object with both fields
. = [{
versionCode: ($vc | tonumber),
versionName: $vn,
fixes: $fixes,
changes: $others
}] + .
' \
"$CHANGELOG" > "${CHANGELOG}.tmp" \
&& mv "${CHANGELOG}.tmp" "$CHANGELOG"
# write fdroid/metadata/<new_code>.txt
mkdir -p fdroid/metadata
out="fdroid/metadata/${{ env.NEW_CODE }}.txt"
{
echo "Changes in ${{ env.NEW_NAME }} (${{ env.NEW_CODE }}):"
echo
for c in "${commits[@]}"; do echo "- $c"; done
} > "$out"
# 6) Commit all metadata, changelog & build.gradle
- name: Commit version & changelog
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add "$GRADLE_FILE" "$CHANGELOG" fdroid/metadata/"${{ env.NEW_CODE }}".txt
git diff --quiet --cached || git commit -m "chore: bump to ${{ env.NEW_NAME }} (${{ env.NEW_CODE }})"
git push
# 7) Build the APK
- name: Build release APK
run: ./gradlew clean :presentation:assembleRelease
# 8) Tag & push
- name: Tag new release
run: |
git tag "v${{ env.NEW_NAME }}"
git push origin "v${{ env.NEW_NAME }}"
# 9) Create GitHub Release & upload APK
- name: Publish GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: "v${{ env.NEW_NAME }}"
files: presentation/build/outputs/apk/release/*-release.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}