Skip to content

chore(bump): from v0.0.5 to v0.1.0 #87

chore(bump): from v0.0.5 to v0.1.0

chore(bump): from v0.0.5 to v0.1.0 #87

name: Publish package to registries
# Publishes the newest version of the package to both NPM and GitHub packages.
# If the workflow is triggered because of a tag push it will push that tag,
# but if the trigger is a regular commit push, then it will push an unstable
# tag.
on:
push:
tags: [v*.*.*]
branches: [main, master, release, development]
paths:
- .github/workflows/many--publish-npm-package.yaml
- test/**
- lib/**
- src/**
- browser/**
- '*package*'
- '*tsconfig*'
- '*vitest*'
- '*eslint*'
- '*prettier*'
jobs:
build:
name: Build new package version
runs-on: ubuntu-latest
outputs:
is_release: ${{ steps.version.outputs.is_release }}
is_prerelease: ${{ steps.version.outputs.is_prerelease }}
npm_tag: ${{ steps.version.outputs.npm_tag }}
package_version: ${{ steps.package.outputs.version }}
package_name: ${{ steps.package.outputs.name }}
artifact_name: ${{ steps.artifact-name.outputs.name }}
steps:
- name: Checkout repository
uses: actions/[email protected]
- name: Set up Node.js
uses: actions/[email protected]
with:
node-version: 24
cache-dependency-path: package-lock.json
cache: 'npm'
- name: Read `package.json` file and output contents
id: package
run: |
version=$(node --print "require('./package.json').version")
echo "version=$version" >> $GITHUB_OUTPUT
echo "PACKAGE_VERSION=$version" >> $GITHUB_ENV
name=$(node --print "require('./package.json').name")
echo "name=$name" >> $GITHUB_OUTPUT
echo "PACKAGE_NAME=$name" >> $GITHUB_ENV
- name: Determine version and tag
id: version
run: |
if [[ "${GITHUB_REF}" == refs/tags/v*.*.*-* ]]; then
# prerelease for example: v1.2.3-alpha
echo "npm_tag=${GITHUB_REF##*-}" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
echo "is_prerelease=true" >> $GITHUB_OUTPUT
elif [[ "${GITHUB_REF}" == refs/tags/v*.*.* ]]; then
# release for example: v1.2.3
echo "npm_tag=latest" >> $GITHUB_OUTPUT
echo "is_release=true" >> $GITHUB_OUTPUT
echo "is_prerelease=false" >> $GITHUB_OUTPUT
else
# regular commit
echo "npm_tag=unstable" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Verify tag matches package.json
if: steps.version.outputs.is_release == 'true'
run: |
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
echo -n "Error: package.json version ($PACKAGE_VERSION)"
echo " does not match tag ($TAG_VERSION)"
exit 1
fi
- name: Install all dependencies
run: npm ci
- name: Build the project
run: npm run build
- name: Ensure we are not pushing a broken version
run: npm run test
- name: Turn links into permalinks on the README
run: |
file="README.md"
domain="github.com"
repo="${{ github.repository }}"
commit="${{ github.sha }}"
link="https://$domain/$repo/blob/$commit"
sed --in-place "s#\(\[.*\]\)(\./\([^)]*\))#\1($link/\2)#g" "$file"
sed --in-place "s#\(src\|srcset\)=\"\./#\1=\"$link/#g" "$file"
- name: Remove sections from readme.
run: |
sed --in-place '/<badges-container/,/<\/badges-container>/d' README.md
sed --in-place '/<toc-section/,/<\/toc-section>/d' README.md
sed --in-place '/<contributing-section/,/<\/contributing-section>/d' README.md
- name: Remove test files from final package
run: rm dist/vitest.* --recursive dist/test --force
- name: artifact name
id: artifact-name
run: echo "name=${{ github.sha }}-${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
- name: Upload build artifact
uses: actions/[email protected]
with:
name: ${{ steps.artifact-name.outputs.name }}
if-no-files-found: 'error'
retention-days: 1
include-hidden-files: true
path: |
dist
package.json
package-lock.json
README.md
LICENSE
publish:
name: Publish to ${{ matrix.registry_name }}
runs-on: ubuntu-latest
environment: ${{ matrix.environment }}
needs: build
strategy:
matrix:
include:
- registry_name: NPM
registry_url: https://registry.npmjs.org
environment: ${{ github.ref_type == 'tag' && 'production' || 'staging' }}-npm
- registry_name: GitHub
registry_url: https://npm.pkg.github.com
environment: ${{ github.ref_type == 'tag' && 'production' || 'staging' }}-github-npm
fail-fast: true
permissions:
id-token: write
contents: read
packages: write
env:
PACKAGE_NAME: ${{ needs.build.outputs.package_name }}
PACKAGE_VERSION: ${{ needs.build.outputs.package_version }}
steps:
- name: Set up Node.js
uses: actions/[email protected]
with:
node-version: 24
registry-url: ${{ matrix.registry_url }}
- name: Download build artifact
uses: actions/[email protected]
with: { name: "${{ needs.build.outputs.artifact_name }}" }
- name: Configure npm auth
if: ${{ matrix.registry_name == 'GitHub' }}
env: { NODE_AUTH_TOKEN: "${{ secrets.GITHUB_TOKEN }}" }
run: |
echo "//npm.pkg.github.com/:_authToken=$NODE_AUTH_TOKEN" > ~/.npmrc
echo "NODE_AUTH_TOKEN=$NODE_AUTH_TOKEN" >> "$GITHUB_ENV"
- name: Publish package
run: |
if [ "${{ needs.build.outputs.is_release }}" = "true" ]; then
npm publish --registry ${{ matrix.registry_url }} --tag ${{ needs.build.outputs.npm_tag }}
elif [ "${{ needs.build.outputs.is_prerelease }}" = "true" ]; then
npm version prerelease --preid "${{ needs.build.outputs.npm_tag }}" --no-git-tag-version
npm publish --registry ${{ matrix.registry_url }} --tag ${{ needs.build.outputs.npm_tag }}
else
SHORT_SHA=${GITHUB_SHA:0:7}
npm version prerelease --preid "${{ needs.build.outputs.npm_tag }}-$SHORT_SHA" --no-git-tag-version
npm publish --registry ${{ matrix.registry_url }} --tag ${{ needs.build.outputs.npm_tag }}
fi