pkg: Publish to npm #25
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' | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Semantic Version' | |
required: true | |
type: choice | |
options: | |
- patch | |
- minor | |
- major | |
- calculate | |
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: 'πΌ Increment Version' | |
if: ${{ inputs.version != 'calculate' }} | |
run: yarn version ${{ inputs.version }} | |
- name: '#οΈβ£ Get Version' | |
uses: actions/github-script@v7 | |
if: ${{ inputs.version != 'calculate' }} | |
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' | |
if: ${{ inputs.version != 'calculate' }} | |
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 | |
if: ${{ inputs.version != 'calculate' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
version: v${{ steps.version.outputs.result }} | |
publish: true | |
- name: 'π Generate Release Notes (calculated)' | |
uses: toolmantim/release-drafter@v6 | |
if: ${{ inputs.version == 'calculate' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
publish: true | |
- name: 'ποΈ Build' | |
run: yarn build | |
- 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 |