Skip to content

Commit

Permalink
fix: version update string included "
Browse files Browse the repository at this point in the history
  • Loading branch information
boidolr committed Feb 15, 2024
1 parent 5276288 commit a9ab126
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
70 changes: 38 additions & 32 deletions .github/workflows/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
workflow_dispatch:

jobs:
update-version:
check-version:
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.version.outputs.VERSION }}
Expand All @@ -18,43 +18,36 @@ jobs:
- name: Get current version
id: version
run: |
version=$(npm view @ast-grep/cli version)
echo "VERSION=${version}" >> $GITHUB_OUTPUT
version=$(npm view @ast-grep/cli version)
version_check='^[0-9]+\.[0-9]+\.[0-9]+$'
if [[ $version =~ $version_check ]]; then
echo "VERSION=${version}" >> $GITHUB_OUTPUT
else
echo "::error::Invalid package version: '$version'"
exit 1
fi
- name: Update version
id: python
shell: python
run: |
import pathlib, re, os
version = "${{ steps.version.outputs.VERSION }}"
config = pathlib.Path(".pre-commit-hooks.yaml")
readme = pathlib.Path("README.md")
original_config = config.read_text()
original_readme = readme.read_text()
updated_config = re.sub(r'"@ast-grep/cli@[^\"]+"', f'"@ast-grep/cli@{version}"', original_config)
updated_readme = re.sub(r'rev: v\d+\.\d+\.\d+', f'rev: {version}"', original_readme)
if updated_config != original_config:
config.write_text(updated_config)
readme.write_text(updated_readme)
npm_version = "${{ steps.version.outputs.VERSION }}"
config = pathlib.Path(".pre-commit-hooks.yaml").read_text()
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
print("UPDATED=true", file=fh)
match = re.search(r'"@ast-grep/cli@([^\"]+)"', config)
config_version = match.group(1) if match else npm_version
- name: Stash changes
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4
with:
name: config
path: |
.pre-commit-hooks.yaml
README.md
updated = str(npm_version != config_version).lower()
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
print(f"UPDATED={updated}", file=fh)
commit-update:
update-update:
runs-on: ubuntu-latest
needs: ["update-version"]
if: ${{ needs.update-version.outputs.UPDATED == 'true' }}
needs: ["check-version"]
if: ${{ needs.check-version.outputs.UPDATED == 'true' }}

permissions:
contents: write
Expand All @@ -63,15 +56,28 @@ jobs:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4
with:
name: config
- name: Update version
shell: python
run: |
import pathlib, re, os
version = "${{ needs.check-version.outputs.VERSION }}"
config = pathlib.Path(".pre-commit-hooks.yaml")
readme = pathlib.Path("README.md")
original_config = config.read_text()
original_readme = readme.read_text()
updated_config = re.sub(r'"@ast-grep/cli@[^\"]+"', f'"@ast-grep/cli@{version}"', original_config)
updated_readme = re.sub(r'rev: v\d+\.\d+\.\d+', f'rev: {version}', original_readme)
config.write_text(updated_config)
readme.write_text(updated_readme)
- name: Push update
run: |
git config user.name github-actions
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git commit -am "chore: update version "
git tag "${{ needs.update-version.outputs.VERSION }}"
git commit -am "chore: update version ${{ needs.check-version.outputs.VERSION }}"
git tag "${{ needs.check-version.outputs.VERSION }}"
git push --tags origin main
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Minimal git hook to run [ast-grep](https://github.com/ast-grep/ast-grep) based o
Add this to your `.pre-commit-config.yaml`:
```
- repo: https://github.com/boidolr/pre-commit-ast-grep
rev: 0.19.0" # Use the ref you want to point at
rev: 0.19.0 # Use the ref you want to point at
hooks:
- id: ast-grep
```
Expand All @@ -24,7 +24,7 @@ Note that only rules with a severity of "error" will lead to the commit hook fai

```
- repo: https://github.com/boidolr/pre-commit-ast-grep
rev: 0.19.0" # Use the ref you want to point at
rev: 0.19.0
hooks:
- id: ast-grep
args: ["--update-all"]
Expand All @@ -39,7 +39,7 @@ Mixing rules with fixes and without fixes with the "--update-all" option is curr

```
- repo: https://github.com/boidolr/pre-commit-ast-grep
rev: 0.19.0" # Use the ref you want to point at
rev: 0.19.0
hooks:
- id: ast-grep
args: ["--config", "/some/path/sgconfig.yaml"]
Expand Down

0 comments on commit a9ab126

Please sign in to comment.