Skip to content

Update package

Update package #265

Workflow file for this run

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@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # 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@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # 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