Skip to content

Commit d2e6810

Browse files
committed
feat(gha): publish dev package to GitHub Packages
Introduces a GitHub Actions workflow which publishes a developer package whenever commits are pushed to the `main` branch. The `publish-dev-package` workflow starts when commits are pushed to the `main` branch and calls the `publish-package` workflow that does the job to publish a developer package. A developer package has the version number followed by a dash (`-`) plus the short commit hash of the commit used to build the package.
1 parent 89f7386 commit d2e6810

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "Publish a developer package to GitHub npm registry"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
packages: write
11+
12+
jobs:
13+
publish-dev:
14+
uses: ./.github/workflows/publish-package.yml
15+
16+
with:
17+
npm-registry-url: "https://npm.pkg.github.com/"
18+
19+
secrets:
20+
npm-token: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: "Publish a package to a specified npm registry"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
npm-registry-url:
7+
description: "URL of the npm registry to publish to; e.g., https://npm.pkg.github.com for GitHub Packages"
8+
type: string
9+
required: true
10+
11+
secrets:
12+
npm-token:
13+
description: "Token that is allowed to publish to the npm registry; e.g., secrets.GITHUB_TOKEN for GitHub Packages"
14+
required: true
15+
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
env:
21+
node-version: 22
22+
23+
jobs:
24+
build-and-publish:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
31+
- name: Get short commit hash
32+
id: commit-hash
33+
run: echo "short-commit-hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
34+
35+
# appends the short commit hash to the version number
36+
# 1. reads the package.json file
37+
# 2. replaces the version and saves it in the package.json
38+
- name: Read package information
39+
id: package-info
40+
# uses the exact commit to prevent harmful updates
41+
uses: jaywcjlove/github-action-package@f6a7afaf74f96a166243f05560d5af4bd4eaa570
42+
with:
43+
path: package.json
44+
- name: Append short commit hash to the version
45+
# uses the exact commit to prevent harmful updates
46+
uses: jaywcjlove/github-action-package@f6a7afaf74f96a166243f05560d5af4bd4eaa570
47+
with:
48+
path: package.json
49+
version: ${{ steps.package-info.outputs.version }}-${{ steps.commit-hash.outputs.short-commit-hash }}
50+
51+
- name: Install pnpm
52+
uses: pnpm/action-setup@v4
53+
# the version is specified in package.json
54+
55+
- name: Setup Node.js ${{ env.node-version }}
56+
uses: actions/setup-node@v4
57+
with:
58+
node-version: ${{ env.node-version }}
59+
cache: pnpm
60+
registry-url: ${{ inputs.npm-registry-url }}
61+
scope: '@codemonger-io'
62+
63+
- name: Install dependencies
64+
run: pnpm install
65+
66+
# the build script is executed by the prepare script
67+
- name: Build and publish
68+
env:
69+
NODE_AUTH_TOKEN: ${{ secrets.npm-token }}
70+
run: pnpm publish --no-git-checks

0 commit comments

Comments
 (0)