Merge remote-tracking branch 'origin/main' #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: npm release | |
| on: | |
| push: | |
| branches: [main] | |
| release: | |
| types: [published] | |
| workflow_dispatch: {} | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Use Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| registry-url: https://registry.npmjs.org | |
| - name: Read package metadata | |
| id: pkg | |
| run: | | |
| NAME=$(node -p "require('./package.json').name") | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "name=$NAME" >> "$GITHUB_OUTPUT" | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Ensure unique version | |
| id: version | |
| env: | |
| PKG_NAME: ${{ steps.pkg.outputs.name }} | |
| PKG_VERSION: ${{ steps.pkg.outputs.version }} | |
| run: | | |
| if npm view "$PKG_NAME@$PKG_VERSION" version >/dev/null 2>&1; then | |
| npm version patch --no-git-tag-version | |
| NEW_VERSION=$(node -p "require('./package.json').version") | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "Bumped to $NEW_VERSION for publish" | |
| else | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| echo "version=$PKG_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "Publishing $PKG_VERSION" | |
| fi | |
| - name: Install | |
| run: npm ci | |
| - name: Build | |
| run: npm run build | |
| - name: Publish | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: npm publish --access public | |
| - name: Commit version bump | |
| if: steps.version.outputs.changed == 'true' | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add package.json package-lock.json | |
| git commit -m "chore: bump version to v${VERSION}" | |
| git push origin HEAD:main |