-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (72 loc) · 2.62 KB
/
update.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Update package
on:
schedule:
- cron: "15 7 * * *"
workflow_dispatch:
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.version.outputs.VERSION }}
UPDATED: ${{ steps.updated.outputs.UPDATED }}
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- name: Get current version
id: version
run: |
version=$(npm view @ast-grep/cli version)
version_check='^[0-9]+\.[0-9]+\.[0-9]+$'
if [[ "${version}" =~ $version_check ]]; then
echo "Found version '$version'"
echo "VERSION=${version}" >> $GITHUB_OUTPUT
else
echo "::error::Invalid package version: '$version'"
exit 1
fi
- name: Check against local version
id: updated
shell: python
env:
VERSION: "${{ steps.version.outputs.VERSION }}"
run: |
import pathlib, re, os
npm_version = os.environ["VERSION"]
config = pathlib.Path(".pre-commit-hooks.yaml").read_text()
match = re.search(r'"@ast-grep/cli@([^\"]+)"', config)
config_version = match.group(1) if match else npm_version
updated = str(npm_version != config_version).lower()
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
print(f"UPDATED={updated}", file=fh)
update-update:
runs-on: ubuntu-latest
needs: ["check-version"]
if: ${{ needs.check-version.outputs.UPDATED == 'true' }}
permissions:
contents: write
env:
VERSION: "${{ needs.check-version.outputs.VERSION }}"
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- name: Update version
shell: python
run: |
import pathlib, re, os
from functools import partial
version = os.environ["VERSION"]
replacements = {
".pre-commit-hooks.yaml": partial(re.sub, r'"@ast-grep/cli@[^\"]+"', f'"@ast-grep/cli@{version}"'),
"README.md": partial(re.sub, r'rev: \d+\.\d+\.\d+', f'rev: {version}'),
}
for name, replacer in replacements.items():
path = pathlib.Path(name)
content = path.read_text()
path.write_text(replacer(content))
- name: Push update
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
git commit -am "chore: update version ${VERSION}"
git tag "${VERSION}"
git push --tags origin main