ci: add workflow_dispatch trigger to publish workflow #4
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: CI + Auto Tag | |
| on: | |
| push: | |
| branches: [main] | |
| jobs: | |
| ci-and-tag: | |
| name: Test & Tag | |
| runs-on: ubuntu-latest | |
| if: "!contains(github.event.head_commit.message, '[skip ci]')" | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Test | |
| run: npm test | |
| - name: Bump patch version and tag | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| CURRENT=$(node -p "require('./package.json').version") | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT" | |
| NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))" | |
| node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
| pkg.version = '$NEW_VERSION'; | |
| fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | |
| " | |
| git add package.json | |
| git commit -m "chore: bump version to $NEW_VERSION [skip ci]" | |
| git tag "v$NEW_VERSION" | |
| git push origin main | |
| git push origin "v$NEW_VERSION" |