11name : Auto‑Bump SQLite‑JDBC
22
33on :
4- schedule : # every day at 05:00 UTC
4+ schedule :
55 - cron : ' 0 5 * * *'
6- workflow_dispatch : # manual “Run workflow” button
6+ workflow_dispatch :
7+ inputs :
8+ should_bump :
9+ description : ' Run Bump Process? (Select "no" to just trigger a build)'
10+ type : boolean
11+ required : true
12+ default : true
13+ version :
14+ description : ' Manual sqlite-jdbc version override (e.g., 3.51.0.0)'
15+ required : false
16+ default : ' '
717
818permissions :
9- contents : write # push commits, create releases, trigger dispatch
10- pull-requests : write # open / merge PRs
19+ contents : write
20+ pull-requests : write
1121
1222jobs :
1323 bump :
1424 runs-on : ubuntu-latest
1525
1626 env :
17- BOT_NAME : " Axionize"
18- BOT_EMAIL :
" [email protected] " # Use the actual committer email 27+ # --- CONFIGURABLE VIA REPOSITORY VARIABLES ---
28+ GIT_AUTHOR_NAME : " ${{ vars.GIT_AUTHOR_NAME || 'Axionize' }}"
29+ GIT_AUTHOR_EMAIL :
" ${{ vars.GIT_AUTHOR_EMAIL || '[email protected] ' }}" 30+ BOT_NAME : " ${{ vars.BOT_NAME || 'Axionize' }}"
31+ BOT_EMAIL :
" ${{ vars.BOT_EMAIL || '[email protected] ' }}" 1932
2033 steps :
21- # 1) Checkout
22- - uses : actions/checkout@v3
23- with :
24- token : ${{ secrets.GITHUB_TOKEN }} # writeable token
25-
26- # 2) Latest version on Maven Central
27- - name : Fetch newest sqlite‑jdbc
28- id : maven
34+ # 1) Setup dynamic author and token based on PAT availability
35+ - name : Setup Context
36+ id : setup_context
2937 run : |
30- latest=$(curl -s 'https://search.maven.org/solrsearch/select?q=g:%22org.xerial%22+AND+a:%22sqlite-jdbc%22&rows=1&wt=json' | jq -r '.response.docs[0].latestVersion')
31- echo "latest=$latest"
32- echo "latest=$latest" >> "$GITHUB_OUTPUT"
33-
34- # 2½) Make the version available as an env var
35- - name : Export NEW_VER
36- run : echo "NEW_VER=${{ steps.maven.outputs.latest }}" >> $GITHUB_ENV
38+ if [[ -n "${{ secrets.AUTOMATION_PAT }}" ]]; then
39+ echo "PAT secret found. Commits will be attributed to '${{ env.GIT_AUTHOR_NAME }}'."
40+ echo "token=${{ secrets.AUTOMATION_PAT }}" >> $GITHUB_OUTPUT
41+ echo "author_string=${{ env.GIT_AUTHOR_NAME }} <${{ env.GIT_AUTHOR_EMAIL }}>" >> $GITHUB_OUTPUT
42+ else
43+ echo "No PAT secret found. Falling back to bot identity '${{ env.BOT_NAME }}'."
44+ echo "token=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_OUTPUT
45+ echo "author_string=${{ env.BOT_NAME }} <${{ env.BOT_EMAIL }}>" >> $GITHUB_OUTPUT
46+ fi
3747
38- # 3) Current version in gradle.properties
39- - name : Read current version
40- id : current
41- run : |
42- current=$(grep '^library_version=' gradle.properties | cut -d'=' -f2 || echo "NOT_FOUND") # Handle missing file/key gracefully
43- echo "current=$current"
44- echo "current=$current" >> "$GITHUB_OUTPUT"
48+ # 2) Checkout repository
49+ - name : Checkout repository
50+ uses : actions/checkout@v3
51+ with :
52+ token : ${{ steps.setup_context.outputs.token }}
4553
46- # 4) Exit early if nothing to update ( or error reading current)
47- - name : Check versions and decide action
54+ # 3) Core Logic: Decide if we should bump, dispatch, or do nothing
55+ - name : Determine Action
4856 id : decision
4957 run : |
50- if [[ "${{ steps.maven.outputs.latest }}" == "${{ steps.current.outputs.current }}" ]]; then
51- echo "Version is up-to-date (${{ steps.current.outputs.current }}). No action needed."
52- echo "should_bump=false" >> "$GITHUB_OUTPUT"
53- elif [[ "${{ steps.current.outputs.current }}" == "NOT_FOUND" ]]; then
54- echo "Could not read current version from gradle.properties. Skipping bump."
55- echo "should_bump=false" >> "$GITHUB_OUTPUT"
56- elif [[ -z "${{ steps.maven.outputs.latest }}" ]]; then
57- echo "Could not fetch latest version from Maven. Skipping bump."
58- echo "should_bump=false" >> "$GITHUB_OUTPUT"
58+ SHOULD_BUMP=false
59+ SHOULD_DISPATCH=false
60+ NEW_VER=""
61+ CHANGELOG_MSG=""
62+
63+ if [[ "${{ github.event.inputs.should_bump }}" == "false" ]]; then
64+ # Manual trigger to just re-build, no bump
65+ echo "Manual trigger to re-build. Bumping process will be skipped."
66+ SHOULD_DISPATCH=true
67+ NEW_VER=$(grep '^library_version=' gradle.properties | cut -d'=' -f2)
68+ CHANGELOG_MSG="Manual re-build of version ${NEW_VER}."
5969 else
60- echo "Current version (${{ steps.current.outputs.current }}) differs from latest (${{ steps.maven.outputs.latest }}). Proceeding with bump."
61- echo "should_bump=true" >> "$GITHUB_OUTPUT"
62- echo "TODAY=$(date -u +%F)" >> $GITHUB_ENV # Set TODAY env var only if bumping
70+ # Standard bump process (scheduled or manual with bump=true)
71+ echo "Starting standard bump process..."
72+ if [[ -n "${{ github.event.inputs.version }}" ]]; then
73+ echo "Using manually specified version: ${{ github.event.inputs.version }}"
74+ NEW_VER="${{ github.event.inputs.version }}"
75+ else
76+ # --- FIX: Switched to the reliable maven-metadata.xml ---
77+ echo "Fetching latest version from Maven Central's metadata..."
78+ # This URL is the direct source of truth and updates instantly.
79+ METADATA_URL='https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/maven-metadata.xml'
80+ NEW_VER=$(curl -s "$METADATA_URL" | grep '<latest>' | sed -E 's/.*<latest>(.+)<\/latest>.*/\1/')
81+ fi
82+
83+ if [[ -z "$NEW_VER" ]]; then
84+ echo "::error::Could not determine a target version. Aborting."
85+ exit 1
86+ fi
87+
88+ CURRENT_VER=$(grep '^library_version=' gradle.properties | cut -d'=' -f2 || echo "NOT_FOUND")
89+ echo "Current version: $CURRENT_VER | Target version: $NEW_VER"
90+
91+ if [[ "$NEW_VER" != "$CURRENT_VER" ]]; then
92+ echo "Version differs. Proceeding with bump and dispatch."
93+ SHOULD_BUMP=true
94+ SHOULD_DISPATCH=true
95+ CHANGELOG_MSG="Automated bump to version **${NEW_VER}**."
96+ else
97+ echo "Version is already up-to-date. No action needed."
98+ fi
6399 fi
64100
65- # 5) Bump version & release_date
66- - name : Bump version & release date in gradle.properties
101+ echo "should_bump=$SHOULD_BUMP" >> "$GITHUB_OUTPUT"
102+ echo "should_dispatch=$SHOULD_DISPATCH" >> "$GITHUB_OUTPUT"
103+ echo "new_version=$NEW_VER" >> "$GITHUB_OUTPUT"
104+ echo "changelog<<EOF" >> "$GITHUB_OUTPUT"
105+ echo "$CHANGELOG_MSG" >> "$GITHUB_OUTPUT"
106+ echo "EOF" >> "$GITHUB_OUTPUT"
107+ echo "NEW_VER=$NEW_VER" >> "$GITHUB_ENV" # For later steps
108+
109+ # 4) Bump version & release_date in gradle.properties
110+ - name : Bump version & release date
67111 if : steps.decision.outputs.should_bump == 'true'
68112 run : |
69113 set -e
70- echo "Updating gradle.properties to version ${{ env.NEW_VER }} and date ${{ env.TODAY }}"
114+ TODAY=$(date -u +%F)
115+ echo "Updating gradle.properties to version ${{ env.NEW_VER }} and date $TODAY"
71116 sed -i "s/^library_version=.*/library_version=${{ env.NEW_VER }}/" gradle.properties
72117 if grep -q '^release_date=' gradle.properties; then
73- sed -i "s/^release_date=.*/release_date=${{ env. TODAY } }/" gradle.properties
118+ sed -i "s/^release_date=.*/release_date=${TODAY}/" gradle.properties
74119 else
75- echo "release_date=${{ env. TODAY } }" >> gradle.properties
120+ echo "release_date=${TODAY}" >> gradle.properties
76121 fi
77- echo "gradle.properties updated."
78-
79- # --- CHOOSE ONE OF THE FOLLOWING OPTIONS (A or B) ---
80-
81- # OPTION A: Commit directly to main
82- # - name: Commit and Push Bump Directly to main
83- # if: steps.decision.outputs.should_bump == 'true'
84- # run: |
85- # set -e
86- # git config user.name "${{ env.BOT_NAME }}"
87- # git config user.email "${{ env.BOT_EMAIL }}"
88- # git add gradle.properties
89- # git commit -m "chore: bump sqlite-jdbc to ${{ env.NEW_VER }} (released ${{ env.TODAY }})"
90- # echo "Pushing changes to main..."
91- # git push origin HEAD:main
92- # echo "Changes pushed."
93-
94- # OPTION B: Create PR and Enable Auto-Merge (DEFAULT in your original)
95- - name : Create PR
122+
123+ # 5) Create Pull Request
124+ - name : Create Pull Request
96125 id : create-pr
97126 if : steps.decision.outputs.should_bump == 'true'
98127 uses : peter-evans/create-pull-request@v5
99128 with :
100- # Use the specific BOT_EMAIL for author/committer
101- author : " ${{ env.BOT_NAME }} <${{ env.BOT_EMAIL }}> "
129+ token : ${{ steps.setup_context.outputs.token }}
130+ author : ${{ steps.setup_context.outputs.author_string }}
102131 committer : " ${{ env.BOT_NAME }} <${{ env.BOT_EMAIL }}>"
103- token : ${{ secrets.GITHUB_TOKEN }}
104- branch : bump-sqlite-${{ env.NEW_VER }}
132+ branch : " bump/sqlite-${{ env.NEW_VER }}"
105133 add-paths : gradle.properties
106- commit-message : " chore: bump sqlite-jdbc to ${{ env.NEW_VER }} (released ${{ env.TODAY }})"
107- title : " chore: bump sqlite-jdbc to ${{ env.NEW_VER }}"
108- body : |
109- Automated bump
110- • **library_version** → `${{ env.NEW_VER }}`
111- • **release_date** → `${{ env.TODAY }}`
134+ commit-message : " chore: bump sqlite-jdbc to ${{ env.NEW_VER }}"
135+ title : " chore: bump sqlite-jdbc to ${{ env.NEW_VER }}"
136+ body : ${{ steps.decision.outputs.changelog }}
112137 delete-branch : true
113138
114- - name : Enable PR auto‑merge
115- id : merge-pr # Give it an ID for potential future checks
116- # Run only if the PR was actually created in the previous step
139+ # 6) Enable PR Auto-Merge
140+ - name : Enable PR auto-merge
117141 if : steps.create-pr.outputs.pull-request-number
118142 env :
119- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
143+ GH_TOKEN : ${{ steps.setup_context.outputs.token }}
120144 run : |
121- echo "Enabling auto-merge for PR #${{ steps.create-pr.outputs.pull-request-number }}"
122145 gh pr merge --squash --auto "${{ steps.create-pr.outputs.pull-request-number }}"
123- echo "Auto-merge enabled."
124- # Note: Merging happens asynchronously after checks pass.
125146
126- # --- END OF OPTIONS ---
127-
128- # 6) ***NEW STEP***: Send repository_dispatch IF a bump occurred
147+ # 7) Trigger Release Workflow
129148 - name : Trigger Nightly Release via Dispatch
130- # Condition: EITHER direct push was attempted OR a PR was created
131- if : steps.decision.outputs.should_bump == 'true'
149+ if : steps.decision.outputs.should_dispatch == 'true'
132150 env :
133- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
134- # Pass the new version info if needed by the triggered workflow
135- NEW_VER_PAYLOAD : ${{ env.NEW_VER }}
151+ GH_TOKEN : ${{ steps.setup_context.outputs.token }}
136152 run : |
137- set -e # Exit on error
138- echo "Bump occurred. Sending repository_dispatch event: sqlite_jdbc_bumped"
139-
140- # Construct the full JSON payload using a heredoc
141- JSON_PAYLOAD=$(cat <<EOF
142- {
143- "event_type": "sqlite_jdbc_bumped",
144- "client_payload": {
145- "version": "${NEW_VER_PAYLOAD}",
146- "reason": "Auto-bump completed"
147- }
148- }
149- EOF
150- )
151-
152- # Pipe the JSON payload into gh api using --input -
153+ set -e
154+ JSON_PAYLOAD=$(jq -n \
155+ --arg ver "${{ steps.decision.outputs.new_version }}" \
156+ --arg changelog "${{ steps.decision.outputs.changelog }}" \
157+ '{event_type: "sqlite_jdbc_bumped", client_payload: {version: $ver, changelog: $changelog}}')
158+
159+ echo "Sending dispatch with payload: $JSON_PAYLOAD"
153160 echo "$JSON_PAYLOAD" | gh api \
154161 --method POST \
155162 -H "Accept: application/vnd.github.v3+json" \
156163 /repos/${{ github.repository }}/dispatches \
157164 --input -
158-
159- echo "Dispatch event sent."
165+ echo "Dispatch event sent."
0 commit comments