Auto‑Bump SQLite‑JDBC #317
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto‑Bump SQLite‑JDBC | |
| on: | |
| schedule: | |
| - cron: '0 5 * * *' | |
| workflow_dispatch: | |
| inputs: | |
| should_bump: | |
| description: 'Run Bump Process? (Select "no" to just trigger a build)' | |
| type: boolean | |
| required: true | |
| default: true | |
| version: | |
| description: 'Manual sqlite-jdbc version override (e.g., 3.51.0.0)' | |
| required: false | |
| default: '' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| bump: | |
| runs-on: ubuntu-latest | |
| env: | |
| # --- CONFIGURABLE VIA REPOSITORY VARIABLES --- | |
| GIT_AUTHOR_NAME: "${{ vars.GIT_AUTHOR_NAME || 'Axionize' }}" | |
| GIT_AUTHOR_EMAIL: "${{ vars.GIT_AUTHOR_EMAIL || '154778082+Axionize@users.noreply.github.com' }}" | |
| BOT_NAME: "${{ vars.BOT_NAME || 'Axionize' }}" | |
| BOT_EMAIL: "${{ vars.BOT_EMAIL || 'Axionize+bot@example.com' }}" | |
| steps: | |
| # 1) Setup dynamic author and token based on PAT availability | |
| - name: Setup Context | |
| id: setup_context | |
| run: | | |
| if [[ -n "${{ secrets.AUTOMATION_PAT }}" ]]; then | |
| echo "PAT secret found. Commits will be attributed to '${{ env.GIT_AUTHOR_NAME }}'." | |
| echo "token=${{ secrets.AUTOMATION_PAT }}" >> $GITHUB_OUTPUT | |
| echo "author_string=${{ env.GIT_AUTHOR_NAME }} <${{ env.GIT_AUTHOR_EMAIL }}>" >> $GITHUB_OUTPUT | |
| else | |
| echo "No PAT secret found. Falling back to bot identity '${{ env.BOT_NAME }}'." | |
| echo "token=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_OUTPUT | |
| echo "author_string=${{ env.BOT_NAME }} <${{ env.BOT_EMAIL }}>" >> $GITHUB_OUTPUT | |
| fi | |
| # 2) Checkout repository | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| with: | |
| token: ${{ steps.setup_context.outputs.token }} | |
| # 3) Core Logic: Decide if we should bump, dispatch, or do nothing | |
| - name: Determine Action | |
| id: decision | |
| run: | | |
| SHOULD_BUMP=false | |
| SHOULD_DISPATCH=false | |
| NEW_VER="" | |
| CHANGELOG_MSG="" | |
| if [[ "${{ github.event.inputs.should_bump }}" == "false" ]]; then | |
| # Manual trigger to just re-build, no bump | |
| echo "Manual trigger to re-build. Bumping process will be skipped." | |
| SHOULD_DISPATCH=true | |
| NEW_VER=$(grep '^library_version=' gradle.properties | cut -d'=' -f2) | |
| CHANGELOG_MSG="Manual re-build of version ${NEW_VER}." | |
| else | |
| # Standard bump process (scheduled or manual with bump=true) | |
| echo "Starting standard bump process..." | |
| if [[ -n "${{ github.event.inputs.version }}" ]]; then | |
| echo "Using manually specified version: ${{ github.event.inputs.version }}" | |
| NEW_VER="${{ github.event.inputs.version }}" | |
| else | |
| # --- FIX: Switched to the reliable maven-metadata.xml --- | |
| echo "Fetching latest version from Maven Central's metadata..." | |
| # This URL is the direct source of truth and updates instantly. | |
| METADATA_URL='https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/maven-metadata.xml' | |
| NEW_VER=$(curl -s "$METADATA_URL" | grep '<latest>' | sed -E 's/.*<latest>(.+)<\/latest>.*/\1/') | |
| fi | |
| if [[ -z "$NEW_VER" ]]; then | |
| echo "::error::Could not determine a target version. Aborting." | |
| exit 1 | |
| fi | |
| CURRENT_VER=$(grep '^library_version=' gradle.properties | cut -d'=' -f2 || echo "NOT_FOUND") | |
| echo "Current version: $CURRENT_VER | Target version: $NEW_VER" | |
| if [[ "$NEW_VER" != "$CURRENT_VER" ]]; then | |
| echo "Version differs. Proceeding with bump and dispatch." | |
| SHOULD_BUMP=true | |
| SHOULD_DISPATCH=true | |
| CHANGELOG_MSG="Automated bump to version **${NEW_VER}**." | |
| else | |
| echo "Version is already up-to-date. No action needed." | |
| fi | |
| fi | |
| echo "should_bump=$SHOULD_BUMP" >> "$GITHUB_OUTPUT" | |
| echo "should_dispatch=$SHOULD_DISPATCH" >> "$GITHUB_OUTPUT" | |
| echo "new_version=$NEW_VER" >> "$GITHUB_OUTPUT" | |
| echo "changelog<<EOF" >> "$GITHUB_OUTPUT" | |
| echo "$CHANGELOG_MSG" >> "$GITHUB_OUTPUT" | |
| echo "EOF" >> "$GITHUB_OUTPUT" | |
| echo "NEW_VER=$NEW_VER" >> "$GITHUB_ENV" # For later steps | |
| # 4) Bump version & release_date in gradle.properties | |
| - name: Bump version & release date | |
| if: steps.decision.outputs.should_bump == 'true' | |
| run: | | |
| set -e | |
| TODAY=$(date -u +%F) | |
| echo "Updating gradle.properties to version ${{ env.NEW_VER }} and date $TODAY" | |
| sed -i "s/^library_version=.*/library_version=${{ env.NEW_VER }}/" gradle.properties | |
| if grep -q '^release_date=' gradle.properties; then | |
| sed -i "s/^release_date=.*/release_date=${TODAY}/" gradle.properties | |
| else | |
| echo "release_date=${TODAY}" >> gradle.properties | |
| fi | |
| # 5) Create Pull Request | |
| # Commit the bump straight to main. No PR, no auto-merge, no branches to | |
| # conflict. The push to main triggers the Nightly Release workflow, which | |
| # builds and publishes the new version. (Requires AUTOMATION_PAT so the | |
| # push is allowed to trigger the downstream workflow.) | |
| - name: Commit bump to main | |
| if: steps.decision.outputs.should_bump == 'true' | |
| run: | | |
| set -e | |
| git config user.name "${{ env.GIT_AUTHOR_NAME }}" | |
| git config user.email "${{ env.GIT_AUTHOR_EMAIL }}" | |
| git add gradle.properties | |
| git commit -m "chore: bump sqlite-jdbc to ${{ env.NEW_VER }}" | |
| for i in 1 2 3; do | |
| if git push origin HEAD:main; then | |
| echo "Pushed bump to main." | |
| exit 0 | |
| fi | |
| echo "Push rejected (attempt $i/3), rebasing on latest main and retrying..." | |
| git pull --rebase origin main | |
| done | |
| echo "::error::Failed to push bump to main after 3 attempts." | |
| exit 1 | |
| # Rebuild path only: when re-running without a version change there is no | |
| # push to main, so trigger the Nightly Release workflow explicitly. | |
| - name: Trigger Nightly Release (rebuild only) | |
| if: steps.decision.outputs.should_bump != 'true' && steps.decision.outputs.should_dispatch == 'true' | |
| env: | |
| GH_TOKEN: ${{ steps.setup_context.outputs.token }} | |
| run: | | |
| gh workflow run "Nightly Release" --ref main |