diff --git a/.github/workflows/version-management.yml b/.github/workflows/version-management.yml new file mode 100644 index 0000000..396647d --- /dev/null +++ b/.github/workflows/version-management.yml @@ -0,0 +1,126 @@ +name: Version Management + +on: + workflow_dispatch: + inputs: + version_name: + description: 'Version name (semantic version e.g. 1.9.5)' + required: true + type: string + version_code: + description: 'Version code (integer, must increase with each release)' + required: true + type: string + git_tag: + description: 'Git tag for this release (defaults to v + version_name)' + required: false + type: string + release_notes: + description: 'Release notes (comma-separated items)' + required: true + type: string + create_pr: + description: 'Create PR instead of direct commit' + required: false + type: boolean + default: false + branch_name: + description: 'Branch name for PR (only used if create_pr is true)' + required: false + type: string + default: 'version-bump' + +jobs: + update-version: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set git user + run: | + git config user.name "GitHub Actions Bot" + git config user.email "actions@github.com" + + - name: Set git tag if not provided + if: ${{ inputs.git_tag == '' }} + run: echo "GIT_TAG=v${{ inputs.version_name }}" >> $GITHUB_ENV + + - name: Use provided git tag + if: ${{ inputs.git_tag != '' }} + run: echo "GIT_TAG=${{ inputs.git_tag }}" >> $GITHUB_ENV + + - name: Create branch if creating PR + if: ${{ inputs.create_pr == true }} + run: | + BRANCH="${{ inputs.branch_name }}-${{ inputs.version_name }}" + git checkout -b $BRANCH + echo "BRANCH_NAME=$BRANCH" >> $GITHUB_ENV + + - name: Update app/build.gradle.kts + run: | + sed -i "s/versionCode = [0-9]\\+/versionCode = ${{ inputs.version_code }}/g" app/build.gradle.kts + sed -i "s/versionName = \"[^\"]*\"/versionName = \"${{ inputs.version_name }}\"/g" app/build.gradle.kts + echo "✓ Updated app/build.gradle.kts with version ${{ inputs.version_name }} (${{ inputs.version_code }})" + + - name: Update F-Droid metadata file + run: | + if [ -f "metadata/ink.trmnl.android.yml" ]; then + sed -i "s/CurrentVersion: .*/CurrentVersion: ${{ inputs.version_name }}/g" metadata/ink.trmnl.android.yml + sed -i "s/CurrentVersionCode: [0-9]\\+/CurrentVersionCode: ${{ inputs.version_code }}/g" metadata/ink.trmnl.android.yml + sed -i "s/versionName: .*/versionName: ${{ inputs.version_name }}/g" metadata/ink.trmnl.android.yml + sed -i "s/versionCode: [0-9]\\+/versionCode: ${{ inputs.version_code }}/g" metadata/ink.trmnl.android.yml + sed -i "s/commit: .*/commit: ${{ env.GIT_TAG }}/g" metadata/ink.trmnl.android.yml + echo "✓ Updated metadata/ink.trmnl.android.yml with version ${{ inputs.version_name }} (${{ inputs.version_code }})" + else + echo "Warning: metadata/ink.trmnl.android.yml not found" + fi + + - name: Create changelog file + run: | + mkdir -p fastlane/metadata/android/en-US/changelogs + echo "- Updated to the latest version (${{ inputs.version_name }})" > fastlane/metadata/android/en-US/changelogs/${{ inputs.version_code }}.txt + + # Process release notes + IFS=',' read -ra NOTES <<< "${{ inputs.release_notes }}" + for note in "${NOTES[@]}"; do + # Trim whitespace and add bullet point + trimmed_note=$(echo "$note" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + echo "- $trimmed_note" >> fastlane/metadata/android/en-US/changelogs/${{ inputs.version_code }}.txt + done + + echo "✓ Created changelog file at fastlane/metadata/android/en-US/changelogs/${{ inputs.version_code }}.txt" + cat fastlane/metadata/android/en-US/changelogs/${{ inputs.version_code }}.txt + + - name: Commit changes directly + if: ${{ inputs.create_pr == false }} + run: | + git add app/build.gradle.kts metadata/ fastlane/ + git commit -m "chore: prepare release ${{ inputs.version_name }}" + git tag ${{ env.GIT_TAG }} + git push origin HEAD:${{ github.ref_name }} + git push origin ${{ env.GIT_TAG }} + echo "✓ Changes committed and pushed to ${{ github.ref_name }}" + echo "✓ Created and pushed tag ${{ env.GIT_TAG }}" + + - name: Create Pull Request + if: ${{ inputs.create_pr == true }} + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "chore: prepare release ${{ inputs.version_name }}" + title: "Prepare release ${{ inputs.version_name }}" + body: | + This PR updates the version to ${{ inputs.version_name }} (${{ inputs.version_code }}) + + ### Release Notes: + ${{ inputs.release_notes }} + + ### Changes: + - Updated app/build.gradle.kts + - Updated F-Droid metadata + - Created changelog file + + After merging this PR, please create a tag with: `git tag ${{ env.GIT_TAG }} && git push origin ${{ env.GIT_TAG }}` + branch: ${{ env.BRANCH_NAME }} + base: ${{ github.ref_name }} diff --git a/README.md b/README.md index e483e15..f45182a 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,39 @@ To build specific variants: ./gradlew buildAllFlavors ``` +### Version Management + +The project uses GitHub Actions to manage version synchronization across different files: + +- `app/build.gradle.kts`: Contains the app's version code and name +- `metadata/ink.trmnl.android.yml`: Contains F-Droid metadata and versioning +- `fastlane/metadata/android/en-US/changelogs/`: Contains version-specific changelog files + +#### Creating a new release + +1. **Check current version information**: + ```bash + # Show current version information and suggested next version + ./scripts/show_version_info.sh + ``` + +2. **Run the Version Management workflow**: + - Go to GitHub Actions → Version Management workflow + - Click "Run workflow" + - Enter the required information: + - **Version name**: Semantic version (e.g., 1.9.5) + - **Version code**: Integer value, must increase with each release + - **Git tag** (optional): Defaults to v + version name + - **Release notes**: Comma-separated release notes + - **Create PR**: Whether to create a pull request or commit directly + +3. **Wait for workflow completion**: + - The workflow will update all necessary files + - It will create or update the changelog + - It will commit changes and create a git tag + +This automated process ensures consistency across all version-related files without manual edits. + --- ## Related References 📖 diff --git a/scripts/show_version_info.sh b/scripts/show_version_info.sh new file mode 100755 index 0000000..5254af0 --- /dev/null +++ b/scripts/show_version_info.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# Script to display current version information across the project + +set -e + +# Get current directory +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(dirname "$SCRIPT_DIR")" + +echo "🔍 Current TRMNL Android Version Information" +echo "-------------------------------------------" + +# Extract version from app/build.gradle.kts +VERSION_CODE=$(grep -o 'versionCode = [0-9]\+' "$ROOT_DIR/app/build.gradle.kts" | awk '{print $3}') +VERSION_NAME=$(grep -o 'versionName = "[^"]*"' "$ROOT_DIR/app/build.gradle.kts" | sed 's/versionName = "\(.*\)"/\1/') + +echo "📱 From app/build.gradle.kts:" +echo " - Version Code: $VERSION_CODE" +echo " - Version Name: $VERSION_NAME" +echo + +# Extract version from F-Droid metadata +if [ -f "$ROOT_DIR/metadata/ink.trmnl.android.yml" ]; then + echo "🤖 From F-Droid metadata:" + FDROID_VERSION=$(grep -o 'CurrentVersion: .*' "$ROOT_DIR/metadata/ink.trmnl.android.yml" | awk '{print $2}') + FDROID_CODE=$(grep -o 'CurrentVersionCode: [0-9]*' "$ROOT_DIR/metadata/ink.trmnl.android.yml" | awk '{print $2}') + FDROID_TAG=$(grep -o 'commit: .*' "$ROOT_DIR/metadata/ink.trmnl.android.yml" | awk '{print $2}') + echo " - Version Code: $FDROID_CODE" + echo " - Version Name: $FDROID_VERSION" + echo " - Git Tag: $FDROID_TAG" + echo +fi + +# Find and list changelog files +echo "📝 Changelog files:" +if [ -d "$ROOT_DIR/fastlane/metadata/android/en-US/changelogs" ]; then + for file in "$ROOT_DIR/fastlane/metadata/android/en-US/changelogs"/*.txt; do + if [ -f "$file" ]; then + VERSION=$(basename "$file" .txt) + echo " - Version $VERSION:" + sed 's/^/ /' "$file" # Indent the file content + echo + fi + done +else + echo " No changelog files found in fastlane/metadata/android/en-US/changelogs" +fi + +# Suggest next version +NEXT_VERSION_CODE=$((VERSION_CODE + 1)) +# Simple semantic version increment (assumes X.Y.Z format) +IFS='.' read -ra VER_PARTS <<< "$VERSION_NAME" +NEXT_VERSION_NAME="${VER_PARTS[0]}.${VER_PARTS[1]}.$((${VER_PARTS[2]} + 1))" + +echo "🚀 Suggested next version:" +echo " - Version Code: $NEXT_VERSION_CODE" +echo " - Version Name: $NEXT_VERSION_NAME" +echo + +echo "To update version, run the GitHub Actions workflow 'Version Management' with:" +echo " - Version name: $NEXT_VERSION_NAME" +echo " - Version code: $NEXT_VERSION_CODE" +echo " - Git tag: v$NEXT_VERSION_NAME (default)" +echo " - Release notes: your comma-separated release notes"