Skip to content

Commit fb2215e

Browse files
committed
feat(gha): publish developer package
Introduces a GitHub Actions workflow `publish-dev-package` which publishes a developer package to the GitHub npm registry when commits are pushed to the `main` branch. A developer package bears the target release version but followed by the short commit hash of the commit used to build the package. The actual steps are described in `publish-package.yml`. `publish-dev-package` can also be triggered by the `issue/2-publish-dev-package` branch for experiments. The trigger has to be removed after finishing the experiments.
1 parent 6ad6faf commit fb2215e

File tree

2 files changed

+93
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)