Publish to npm Registry (minor) #5
This file contains 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: 'pkg: Publish to npm' | |
run-name: 'Publish to npm Registry (${{ inputs.version }})' | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Semantic Version' | |
required: true | |
type: choice | |
options: | |
- patch | |
- minor | |
- major | |
jobs: | |
publish: | |
name: Publish to npm | |
runs-on: ubuntu-latest | |
steps: | |
- name: 'π Checkout Code' | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GH_BOT_TOKEN }} | |
- name: 'π’ Use Node.js' | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
registry-url: 'https://registry.npmjs.org' | |
cache: 'yarn' | |
- name: 'π¦ Install packages' | |
run: yarn install | |
- name: 'ποΈ Build' | |
run: yarn build | |
- name: 'πΌ Increment Version' | |
run: yarn version ${{ inputs.version }} | |
- name: '#οΈβ£ Get Version' | |
uses: actions/github-script@v7 | |
id: version | |
with: | |
result-encoding: string | |
retries: 3 | |
script: | | |
const fs = require('fs'); | |
const pj = JSON.parse(fs.readFileSync('${{ github.workspace }}/package.json')); | |
return pj.version; | |
- name: 'πΎ Commit Incremented Version' | |
run: | | |
git config --local user.email "${{ secrets.GH_BOT_EMAIL }}" | |
git config --local user.name "${{ secrets.GH_BOT_NAME }}" | |
git add package.json | |
git commit -am "[π€ release]: ${{ steps.version.outputs.result }} (${{ inputs.version }})" | |
git push origin HEAD --force | |
- name: 'π Generate Release Notes (user-input)' | |
uses: toolmantim/release-drafter@v6 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
version: v${{ steps.version.outputs.result }} | |
publish: true | |
- name: Setup .yarnrc.yml | |
run: | | |
yarn config set npmScopes.joggr.npmRegistryServer "https://registry.npmjs.org" | |
yarn config set npmScopes.joggr.npmAlwaysAuth true | |
yarn config set npmScopes.joggr.npmAuthToken $NPM_AUTH_TOKEN | |
env: | |
NPM_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH }} | |
- name: 'π’ Publish' | |
run: yarn npm publish --access public |