66 workflow_dispatch : # manual “Run workflow” button
77
88permissions :
9- contents : write # push commits, create releases
9+ contents : write # push commits, create releases, trigger dispatch
1010 pull-requests : write # open / merge PRs
1111
1212jobs :
@@ -15,110 +15,130 @@ jobs:
1515
1616 env :
1717 BOT_NAME : " Axionize"
18- BOT_EMAIL : " Axionize+bot@example.com"
18+ BOT_EMAIL : " Axionize+bot@example.com" # Use the actual committer email
1919
2020 steps :
21- # ─────────────────────────────────────────────────────────
2221 # 1) Checkout
23- # ─────────────────────────────────────────────────────────
2422 - uses : actions/checkout@v3
2523 with :
2624 token : ${{ secrets.GITHUB_TOKEN }} # writeable token
2725
28- # ─────────────────────────────────────────────────────────
2926 # 2) Latest version on Maven Central
30- # ─────────────────────────────────────────────────────────
3127 - name : Fetch newest sqlite‑jdbc
3228 id : maven
3329 run : |
34- latest=$(curl -s \
35- 'https://search.maven.org/solrsearch/select?q=g:%22org.xerial%22+AND+a:%22sqlite-jdbc%22&rows=1&wt=json' \
36- | jq -r '.response.docs[0].latestVersion')
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')
3731 echo "latest=$latest"
3832 echo "latest=$latest" >> "$GITHUB_OUTPUT"
3933
4034 # 2½) Make the version available as an env var
4135 - name : Export NEW_VER
4236 run : echo "NEW_VER=${{ steps.maven.outputs.latest }}" >> $GITHUB_ENV
4337
44- # ─────────────────────────────────────────────────────────
4538 # 3) Current version in gradle.properties
46- # ─────────────────────────────────────────────────────────
4739 - name : Read current version
4840 id : current
4941 run : |
50- current=$(grep '^library_version=' gradle.properties | cut -d'=' -f2)
42+ current=$(grep '^library_version=' gradle.properties | cut -d'=' -f2 || echo "NOT_FOUND") # Handle missing file/key gracefully
5143 echo "current=$current"
5244 echo "current=$current" >> "$GITHUB_OUTPUT"
5345
54- # 3½) Export NEW_VER (already in your file)
55- - name : Export NEW_VER
56- run : echo "NEW_VER=${{ steps.maven.outputs.latest }}" >> $GITHUB_ENV
46+ # 4) Exit early if nothing to update (or error reading current)
47+ - name : Check versions and decide action
48+ id : decision
49+ 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"
59+ 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
63+ fi
5764
58- # ─────────────────────────────────────────────────────────
59- # 4) Exit early if nothing to update
60- # ─────────────────────────────────────────────────────────
61- - name : Skip if up‑to‑date
62- if : ${{ steps.maven.outputs.latest == steps.current.outputs.current }}
63- run : echo "Nothing to bump — already on ${{ steps.current.outputs.current }}."
64-
65- # 5) Bump version & release_date ── we already compute TODAY here
66- - name : Bump version & release date
67- id : bump
68- if : ${{ steps.maven.outputs.latest != steps.current.outputs.current }}
65+ # 5) Bump version & release_date
66+ - name : Bump version & release date in gradle.properties
67+ if : steps.decision.outputs.should_bump == 'true'
6968 run : |
7069 set -e
71- TODAY=$(date -u +%F) # 2024-06-08
72- echo "TODAY=$TODAY" >> $GITHUB_ENV # ← make it available later
73-
74- sed -i "s/^library_version=.*/library_version=${{ steps.maven.outputs.latest }}/" gradle.properties
70+ echo "Updating gradle.properties to version ${{ env.NEW_VER }} and date ${{ env.TODAY }}"
71+ sed -i "s/^library_version=.*/library_version=${{ env.NEW_VER }}/" gradle.properties
7572 if grep -q '^release_date=' gradle.properties; then
76- sed -i "s/^release_date=.*/release_date=${TODAY}/" gradle.properties
73+ sed -i "s/^release_date=.*/release_date=${{ env. TODAY } }/" gradle.properties
7774 else
78- echo "release_date=${TODAY}" >> gradle.properties
75+ echo "release_date=${{ env. TODAY } }" >> gradle.properties
7976 fi
77+ echo "gradle.properties updated."
78+
79+ # --- CHOOSE ONE OF THE FOLLOWING OPTIONS (A or B) ---
8080
81- # ---------------------------------------------------------------------
82- # 5) OPTION A → Commit directly to main (UNCOMMENT to use)
83- # ---------------------------------------------------------------------
84- # - name: Bump + push to main # ← uncomment block to enable option A
85- # if: ${{ steps.maven.outputs.latest != steps.current.outputs.current }}
86- # env:
87- # LATEST: ${{ steps.maven.outputs.latest }}
81+ # OPTION A: Commit directly to main
82+ # - name: Commit and Push Bump Directly to main
83+ # if: steps.decision.outputs.should_bump == 'true'
8884 # run: |
8985 # set -e
90- # sed -i "s/^library_version=.*/library_version=${LATEST}/" gradle.properties
91- # git config user.name "Axionize"
92- # git config user.email "154778082+Axionize@users.noreply.github.com"
86+ # git config user.name "${{ env.BOT_NAME }}"
87+ # git config user.email "${{ env.BOT_EMAIL }}"
9388 # git add gradle.properties
94- # git commit -m "chore: bump sqlite-jdbc to ${LATEST}"
89+ # git commit -m "chore: bump sqlite-jdbc to ${{ env.NEW_VER }} (released ${{ env.TODAY }})"
90+ # echo "Pushing changes to main..."
9591 # git push origin HEAD:main
92+ # echo "Changes pushed."
9693
97- # ---------------------------------------------------------------------
98- # 5/6) OPTION B → PR + auto‑merge (DEFAULT below)
99- # ---------------------------------------------------------------------
100- # 6) Create or update the PR
94+ # OPTION B: Create PR and Enable Auto-Merge (DEFAULT in your original)
10195 - name : Create PR
10296 id : create-pr
103- if : ${{ steps.maven .outputs.latest != steps.current.outputs.current }}
97+ if : steps.decision .outputs.should_bump == 'true'
10498 uses : peter-evans/create-pull-request@v5
10599 with :
100+ # Use the specific BOT_EMAIL for author/committer
101+ author : " ${{ env.BOT_NAME }} <${{ env.BOT_EMAIL }}>"
102+ committer : " ${{ env.BOT_NAME }} <${{ env.BOT_EMAIL }}>"
106103 token : ${{ secrets.GITHUB_TOKEN }}
107- branch : bump-sqlite-${{ steps.maven.outputs.latest }}
104+ branch : bump-sqlite-${{ env.NEW_VER }}
108105 add-paths : gradle.properties
109- commit-message : " chore: bump sqlite-jdbc to ${{ steps.maven.outputs.latest }} (released ${{ env.TODAY }})"
110- title : " chore: bump sqlite-jdbc to ${{ steps.maven.outputs.latest }}"
106+ commit-message : " chore: bump sqlite-jdbc to ${{ env.NEW_VER }} (released ${{ env.TODAY }})"
107+ title : " chore: bump sqlite-jdbc to ${{ env.NEW_VER }}"
111108 body : |
112- Automated bump
113- • **library_version** → `${{ steps.maven.outputs.latest }}`
109+ Automated bump
110+ • **library_version** → `${{ env.NEW_VER }}`
114111 • **release_date** → `${{ env.TODAY }}`
115112 delete-branch : true
116- author : " ${{ env.BOT_NAME }} <${{ env.BOT_EMAIL }}>"
117- committer : " ${{ env.BOT_NAME }} <${{ env.BOT_EMAIL }}>"
118113
119- # 7) Enable auto‑merge
120114 - name : Enable PR auto‑merge
121- if : ${{ steps.create-pr.outputs.pull-request-number }}
122- run : gh pr merge --squash --auto "${{ steps.create-pr.outputs.pull-request-number }}"
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
117+ if : steps.create-pr.outputs.pull-request-number
123118 env :
124- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
119+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
120+ run : |
121+ echo "Enabling auto-merge for PR #${{ steps.create-pr.outputs.pull-request-number }}"
122+ 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.
125+
126+ # --- END OF OPTIONS ---
127+
128+ # 6) ***NEW STEP***: Send repository_dispatch IF a bump occurred
129+ - 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'
132+ 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 }}
136+ run : |
137+ echo "Bump occurred. Sending repository_dispatch event: sqlite_jdbc_bumped"
138+ gh api \
139+ --method POST \
140+ -H "Accept: application/vnd.github.v3+json" \
141+ /repos/${{ github.repository }}/dispatches \
142+ -f event_type='sqlite_jdbc_bumped' \
143+ -f client_payload='{"version": "${{ env.NEW_VER_PAYLOAD }}", "reason": "Auto-bump completed"}'
144+ echo "Dispatch event sent."
0 commit comments