Skip to content

Commit d95b593

Browse files
committed
ci: add sync-plugin-version workflow (auto-bump plugin.json on tag)
1 parent 927ae9c commit d95b593

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Sync plugin.json version
2+
on:
3+
push:
4+
tags: ['v*']
5+
permissions:
6+
contents: write
7+
pull-requests: write
8+
jobs:
9+
sync:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
ref: main
15+
fetch-depth: 0
16+
token: ${{ secrets.GITHUB_TOKEN }}
17+
- name: Compute target version from tag
18+
id: ver
19+
run: |
20+
TAG="${GITHUB_REF_NAME}"
21+
VERSION="${TAG#v}"
22+
echo "version=$VERSION" >> $GITHUB_OUTPUT
23+
echo "tag=$TAG" >> $GITHUB_OUTPUT
24+
- name: Update plugin.json
25+
run: |
26+
if [ ! -f plugin.json ]; then echo "no plugin.json; skipping"; exit 0; fi
27+
CURRENT=$(python3 -c "import json; print(json.load(open('plugin.json')).get('version',''))")
28+
TARGET="${{ steps.ver.outputs.version }}"
29+
if [ "$CURRENT" = "$TARGET" ]; then
30+
echo "plugin.json already at $TARGET; no action"
31+
exit 0
32+
fi
33+
python3 -c "
34+
import json
35+
p = json.load(open('plugin.json'))
36+
p['version'] = '$TARGET'
37+
json.dump(p, open('plugin.json', 'w'), indent=2)
38+
open('plugin.json', 'a').write('\n')
39+
"
40+
- name: Open sync PR if plugin.json changed
41+
run: |
42+
if git diff --quiet plugin.json; then
43+
echo "no changes"
44+
exit 0
45+
fi
46+
BRANCH="chore/sync-plugin-version-${{ steps.ver.outputs.tag }}"
47+
git config user.email "github-actions[bot]@users.noreply.github.com"
48+
git config user.name "github-actions[bot]"
49+
git checkout -b "$BRANCH"
50+
git add plugin.json
51+
git commit -m "chore: sync plugin.json version to ${{ steps.ver.outputs.tag }}"
52+
git push origin "$BRANCH"
53+
gh pr create \
54+
--base main \
55+
--head "$BRANCH" \
56+
--title "chore: sync plugin.json version to ${{ steps.ver.outputs.tag }}" \
57+
--body "Triggered by release ${{ steps.ver.outputs.tag }}. Auto-sync to prevent drift. Closes workflow-registry#37."
58+
env:
59+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)