Release #6
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: Release | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js 24.x | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24.x | |
| registry-url: "https://registry.npmjs.org" | |
| cache: "npm" | |
| - name: Use npm 11+ | |
| run: npm install -g npm@^11.10.0 | |
| - name: Print Node and npm versions | |
| run: | | |
| node -v | |
| npm -v | |
| - name: Read version from package.json | |
| id: package_meta | |
| run: | | |
| PACKAGE_VERSION="$(node -p "require('./package.json').version")" | |
| echo "version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "tag=v$PACKAGE_VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run tests | |
| run: npm test | |
| - name: Ensure npm version is not already published | |
| run: | | |
| PKG_NAME="$(node -p "require('./package.json').name")" | |
| VERSION="${{ steps.package_meta.outputs.version }}" | |
| if npm view "${PKG_NAME}@${VERSION}" version >/dev/null 2>&1; then | |
| echo "${PKG_NAME}@${VERSION} is already published on npm." | |
| exit 1 | |
| fi | |
| - name: Create GitHub release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| TAG="${{ steps.package_meta.outputs.tag }}" | |
| NOTES="$(gh api "repos/${GITHUB_REPOSITORY}/releases/generate-notes" -f tag_name="$TAG" -f target_commitish="$GITHUB_SHA" --jq .body)" | |
| gh release create "$TAG" --title "$TAG" --notes "$NOTES" --target "$GITHUB_SHA" | |
| - name: Publish package to npm | |
| run: npm publish --access public |