Publish to npm registry (patch) #12
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: 'pkgs: Publish to npm registry' | |
run-name: 'Publish to npm registry (${{ inputs.version }})' | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Semantic Version' | |
required: true | |
default: 'minor' | |
type: choice | |
options: | |
- patch | |
- minor | |
- major | |
- prerelease | |
jobs: | |
publish: | |
name: 'Publish to npm registry' | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
steps: | |
- name: '🛒 Checkout Code' | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GH_BOT_TOKEN }} | |
- name: "𝌤 Enable Corepack" | |
run: corepack enable | |
- name: '🟢 Setup Node.js' | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
registry-url: 'https://npm.pkg.github.com' | |
token: ${{ secrets.GH_BOT_TOKEN }} | |
scope: '@joggrdocs' | |
cache: 'yarn' | |
- name: '📦 Install packages' | |
run: yarn install | |
- name: '🔼 Increment Version' | |
# We have to run with npm because yarn's update is based on "stableVersion" which is not what we want | |
run: yarn workspaces foreach --all exec npm version --no-git-tag-version --no-workspaces-update ${{ 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: '🏗️ Build' | |
run: yarn turbo run build --filter="./packages/*" | |
- 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 workspaces foreach -A --include "packages/*" npm publish --tolerate-republish --access public | |
- 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 ./packages/*/package.json ./package.json | |
git commit -m "[🤖 npm-publish]: ${{ steps.version.outputs.result }} (${{ inputs.version }}) [skip-ci]" | |
git push origin HEAD --force | |
- name: '📝 Publish Release Notes' | |
uses: release-drafter/release-drafter@v6 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
version: v${{ steps.version.outputs.result }} | |
publish: true |