Sync dclint version from npm #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync dclint version from npm | |
| on: | |
| push: | |
| branches: [main] | |
| schedule: | |
| - cron: '0 6 * * 1' | |
| workflow_dispatch: | |
| jobs: | |
| update: | |
| name: Update dclint version | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Get latest dclint version from npm | |
| id: get_version | |
| run: | | |
| VERSION=$(npm show dclint version) | |
| echo "Latest version is $VERSION" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Extract current version from hooks | |
| id: get_current | |
| run: | | |
| CURRENT=$(grep -o 'dclint@[0-9]\+\.[0-9]\+\.[0-9]\+' .pre-commit-hooks.yaml | head -1 | cut -d@ -f2) | |
| echo "Current version is $CURRENT" | |
| echo "current=$CURRENT" >> $GITHUB_OUTPUT | |
| - name: Compare versions | |
| id: compare | |
| run: | | |
| if [ "${{ steps.get_version.outputs.version }}" != "${{ steps.get_current.outputs.current }}" ]; then | |
| echo "Version changed" | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No change" | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Replace version in .pre-commit-hooks.yaml and README.md | |
| if: steps.compare.outputs.changed == 'true' | |
| run: | | |
| NEW_VERSION=${{ steps.get_version.outputs.version }} | |
| # Update npm version: [email protected] | |
| sed -i "s/dclint@[0-9]\+\.[0-9]\+\.[0-9]\+/dclint@${NEW_VERSION}/g" .pre-commit-hooks.yaml | |
| # Update docker version: dclint:X.Y.Z | |
| sed -i "s/zavoloklom\/dclint:[0-9]\+\.[0-9]\+\.[0-9]\+/zavoloklom\/dclint:${NEW_VERSION}/g" .pre-commit-hooks.yaml | |
| # Update README.md | |
| sed -i "s/rev: v[0-9]\+\.[0-9]\+\.[0-9]\+/rev: v${NEW_VERSION}/g" README.md | |
| - name: Commit and tag new version | |
| if: steps.compare.outputs.changed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add .pre-commit-hooks.yaml README.md | |
| git commit -m "chore: update DCLint to v${{ steps.get_version.outputs.version }}" | |
| git tag -a v${{ steps.get_version.outputs.version }} -m "Update DCLint to v${{ steps.get_version.outputs.version }}" | |
| git push origin main --follow-tags |