Create bump-and-build.yml

This commit is contained in:
octoshrimpy
2025-06-28 07:00:04 -04:00
committed by GitHub
parent 6fe2aea703
commit e6e97dc285
+96
View File
@@ -0,0 +1,96 @@
name: Bump Feature Version and Build Release
on:
workflow_dispatch:
jobs:
bump-feature-version-and-build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Git user
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Ensure gradlew is executable (for fresh clones)
- name: Ensure gradlew is executable
run: chmod +x ./presentation/gradlew
- name: Bump MINOR version in build.gradle (features update)
working-directory: presentation
run: |
# Extract current versionName and versionCode
VERSION_LINE=$(grep "versionName" build.gradle)
VERSION_NAME=$(echo "$VERSION_LINE" | sed -n "s/.*versionName[ ]*['\"]\([^'\"]*\)['\"].*/\1/p")
VERSION_CODE=$(grep "versionCode" build.gradle | awk '{print $2}')
# Error handling for version parsing
if [[ ! "$VERSION_NAME" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: versionName is not in MAJOR.MINOR.PATCH format: $VERSION_NAME"
exit 1
fi
if ! [[ "$VERSION_CODE" =~ ^[0-9]+$ ]]; then
echo "Error: versionCode is not an integer: $VERSION_CODE"
exit 1
fi
# Split versionName into major, minor, patch
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION_NAME"
# Bump minor version, reset patch to 0
MINOR=$((MINOR + 1))
PATCH=0
NEW_VERSION_NAME="$MAJOR.$MINOR.$PATCH"
NEW_VERSION_CODE=$((VERSION_CODE + 1))
# Update build.gradle in-place
sed -i "s/versionName.*/versionName '$NEW_VERSION_NAME'/" build.gradle
sed -i "s/versionCode.*/versionCode $NEW_VERSION_CODE/" build.gradle
echo "Bumped version to $NEW_VERSION_NAME ($NEW_VERSION_CODE)"
- name: Commit version bump
working-directory: presentation
run: |
git add build.gradle
git commit -m "chore: bump feature version [skip ci]" || echo "No changes to commit"
git push
- name: Build Release
working-directory: presentation
run: ./gradlew assembleRelease
# Find and upload APK artifacts for easy download
- name: Upload APK as artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: release-apk
path: |
presentation/build/outputs/apk/release/*.apk
presentation/app/build/outputs/apk/release/*.apk
# Adjust/add paths if your APKs are elsewhere
# Optional: Show APK files found (for debugging)
- name: List built APKs
working-directory: presentation
run: |
echo "APK files in build/outputs/apk/release:"
ls -lh build/outputs/apk/release || echo "No APKs found"
echo "APK files in app/build/outputs/apk/release:"
ls -lh app/build/outputs/apk/release || echo "No APKs found"
# Documentation for maintainers
- name: Workflow summary
run: |
echo "This workflow:"
echo "- Bumps the MINOR version and resets PATCH in presentation/build.gradle"
echo "- Commits and pushes the version update"
echo "- Builds the release APK"
echo "- Uploads the APK as a downloadable artifact"