Skip to content

Commit 7191ff0

Browse files
committed
feat: support npm publish
1 parent 66b12ff commit 7191ff0

3 files changed

Lines changed: 111 additions & 3 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: 'NPM Publish'
2+
description: 'Publish package to npm registry.'
3+
4+
inputs:
5+
node-version:
6+
description: 'Node.js version to use.'
7+
required: false
8+
default: '20'
9+
package-dir:
10+
description: 'Directory containing package.json.'
11+
required: false
12+
default: '.'
13+
deploy-command:
14+
description: 'Publish command to execute.'
15+
required: false
16+
default: 'npm run deploy'
17+
access-token:
18+
description: 'NPM auth token.'
19+
required: true
20+
21+
runs:
22+
using: 'composite'
23+
steps:
24+
- name: 📦 Install Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: ${{ inputs.node-version }}
28+
registry-url: 'https://registry.npmjs.org'
29+
30+
- name: 🔍 Verify NPM Package File
31+
shell: bash
32+
working-directory: ${{ inputs.package-dir }}
33+
run: |
34+
if [ ! -f 'package.json' ]; then
35+
echo '❌ package.json Not Found'
36+
exit 1
37+
fi
38+
39+
- name: 📦 Install Dependencies
40+
shell: bash
41+
working-directory: ${{ inputs.package-dir }}
42+
run: npm ci
43+
44+
- name: 🚀 Deploy npm Package
45+
shell: bash
46+
working-directory: ${{ inputs.package-dir }}
47+
env:
48+
NODE_AUTH_TOKEN: ${{ inputs.access-token }}
49+
run: ${{ inputs.deploy-command }}

.github/workflows/reusable-publish-release.yml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,27 @@ name: Publish Release
22

33
on:
44
workflow_call:
5+
inputs:
6+
npm-node-version:
7+
description: 'Node.js version for npm publish.'
8+
required: false
9+
type: string
10+
default: '20'
11+
npm-package-dir:
12+
description: 'Directory containing package.json for npm publish.'
13+
required: false
14+
type: string
15+
default: '.'
16+
npm-deploy-command:
17+
description: 'Command used to publish npm package.'
18+
required: false
19+
type: string
20+
default: 'npm run deploy'
521
secrets:
622
ACCESS_TOKEN:
723
required: true
24+
NPM_TOKEN:
25+
required: false
826

927
jobs:
1028
publish-release:
@@ -15,7 +33,7 @@ jobs:
1533
- name: 👣 Track Workflow Run
1634
continue-on-error: true
1735
run: |
18-
curl -s "https://abacus.jasoncameron.dev/hit/leoweyr/github-release-workflow-usage" > /dev/null
36+
curl -s "https://abacus.jasoncameron.dev/hit/leoweyr/github-release-workflow-usage" > /dev/null
1937
2038
- name: 📂 Checkout Code
2139
uses: actions/checkout@v4
@@ -44,3 +62,31 @@ jobs:
4462
--title "${{ env.VERSION_TITLE }}" \
4563
--notes-file release_body.md \
4664
--verify-tag
65+
66+
- name: 🔍 Verify NPM Token
67+
id: verify_npm_token
68+
run: |
69+
if [ -z "${{ secrets.NPM_TOKEN }}" ]; then
70+
echo '👻 NPM_TOKEN is not configured.'
71+
echo 'enabled=false\n' >> "$GITHUB_OUTPUT"
72+
exit 0
73+
fi
74+
75+
echo 'enabled=true\n' >> "$GITHUB_OUTPUT"
76+
77+
- name: 🔄 Sync NPM Publish Action
78+
if: steps.verify_npm_token.outputs.enabled == 'true'
79+
uses: actions/checkout@v4
80+
with:
81+
repository: 'leoweyr/github-release-workflow'
82+
path: .release-workflow
83+
sparse-checkout: .github/actions/npm-publish
84+
85+
- name: 🚀 Deploy NPM Package
86+
if: steps.verify_npm_token.outputs.enabled == 'true'
87+
uses: ./.release-workflow/.github/actions/npm-publish
88+
with:
89+
node-version: ${{ inputs.npm-node-version }}
90+
package-dir: ${{ inputs.npm-package-dir }}
91+
deploy-command: ${{ inputs.npm-deploy-command }}
92+
access-token: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![github-release-workflow](https://socialify.git.ci/leoweyr/github-release-workflow/image?description=1&font=KoHo&forks=1&issues=1&logo=https%3A%2F%2Fraw.githubusercontent.com%2Fleoweyr%2Fgithub-release-workflow%2Frefs%2Fheads%2Fdevelop%2Fassets%2Ficon.svg&name=1&owner=1&pattern=Formal+Invitation&pulls=1&stargazers=1&theme=Light)
1+
![github-release-workflow](https://socialify.git.ci/leoweyr/github-release-workflow/image?description=1&font=KoHo&logo=https%3A%2F%2Fraw.githubusercontent.com%2Fleoweyr%2Fgithub-release-workflow%2Frefs%2Fheads%2Fdevelop%2Fassets%2Ficon.svg&name=1&owner=1&pattern=Formal+Invitation&theme=Light)
22

33
![Usage](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fabacus.jasoncameron.dev%2Fget%2Fleoweyr%2Fgithub-release-workflow-usage&query=%24.value&label=Usage&color=blue&suffix=%20times)
44
![Used by Stats](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/leoweyr/0575adecfc13c95f281dfccfe5b76063/raw/github-release-workflow-used-by-stats.json)
@@ -38,4 +38,17 @@ This workflow streamlines your release process into a few simple steps:
3838
4. **Review and Merge**: Review the Pull Request created by the bot.
3939
* **Do not modify the Pull Request title or body**, as they are used for the release metadata.
4040
* Merge the Pull Request.
41-
* The workflow will automatically create a GitHub Release for you.
41+
* The workflow will automatically create coordinated releases across GitHub and supported package registries.
42+
43+
## 📦 Optional Publishing
44+
45+
> [!NOTE]
46+
>
47+
> If the required secret for the release target are not configured, publishing will not start.
48+
49+
Configure target publishing in your user-side entry workflow (`.github/workflows/publish-release.yml`):
50+
51+
| Release Target | Required Secret | User-Side Inputs (`with`) |
52+
|----------------|-----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
53+
| GitHub Release | `ACCESS_TOKEN` (Mapped from `secrets.GITHUB_TOKEN`) | None |
54+
| NPM | `NPM_TOKEN` | `npm-node-version` (Default `20`)<br/>`npm-package-dir` (Default `.`)<br/>`npm-deploy-command` (Default `npm run deploy`) |

0 commit comments

Comments
 (0)