Skip to content

2.0.0

2.0.0 #19

name: Autopublish to npm on release creation
on:
release:
types: [published]
permissions:
contents: write
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.release.target_commitish }}
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: 'https://registry.npmjs.org'
- run: npm install -g npm@latest
- run: npm ci
- run: git config --global user.name "GitHub CD bot"
- run: git config --global user.email "github-cd-bot@example.com"
- run: git add . && git diff --staged --quiet || git commit -m "Update dependencies"
- run: git status
- run: npm version ${{ github.event.release.tag_name }} --no-git-tag-version
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Bump version to ${{ github.event.release.tag_name }}"
file_pattern: "package.json package-lock.json"
- name: Determine npm tag
id: npm_tag
run: |
TAG="${{ github.event.release.tag_name }}"
if echo "$TAG" | grep -qE "alpha|-alpha|\.a\."; then
echo "tag=alpha" >> $GITHUB_OUTPUT
elif echo "$TAG" | grep -qE "beta|-beta|\.b\."; then
echo "tag=beta" >> $GITHUB_OUTPUT
elif echo "$TAG" | grep -qE "rc|-rc|\.rc\."; then
echo "tag=rc" >> $GITHUB_OUTPUT
elif [ "${{ github.event.release.prerelease }}" = "true" ]; then
echo "tag=beta" >> $GITHUB_OUTPUT
else
echo "tag=latest" >> $GITHUB_OUTPUT
fi
- name: Publish to npm
run: npm publish --provenance --tag ${{ steps.npm_tag.outputs.tag }}
show-npm-log:
runs-on: ubuntu-latest
needs: publish
if: failure()
steps:
- run: echo "NPM Logs Directory:"
- run: ls -l /home/runner/.npm/_logs/
- run: echo "Displaying the most recent log:"
- run: cat /home/runner/.npm/_logs/*.log