Skip to content

Commit ab2cf15

Browse files
committed
add workflow to publish to npm
1 parent f82bdb9 commit ab2cf15

File tree

4 files changed

+129
-1
lines changed

4 files changed

+129
-1
lines changed

.github/workflows/npm-publish.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-node@v4
13+
with:
14+
node-version: '18.x'
15+
registry-url: 'https://registry.npmjs.org'
16+
17+
- name: Install pnpm
18+
uses: pnpm/action-setup@v2
19+
with:
20+
version: 8
21+
run_install: false
22+
23+
- name: Get pnpm store directory
24+
shell: bash
25+
run: |
26+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
27+
28+
- uses: actions/cache@v3
29+
name: Setup pnpm cache
30+
with:
31+
path: ${{ env.STORE_PATH }}
32+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
33+
restore-keys: |
34+
${{ runner.os }}-pnpm-store-
35+
36+
- name: Install dependencies
37+
run: pnpm install
38+
39+
- name: Lint
40+
run: pnpm run lint
41+
42+
- name: Build
43+
run: pnpm run build
44+
45+
- name: Test
46+
run: pnpm test -- --watchAll=false
47+
48+
- name: E2E Tests
49+
run: pnpm run e2e-test
50+
51+
- name: Publish to npm
52+
run: pnpm publish --no-git-checks
53+
env:
54+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [18.x, 20.x]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
23+
- name: Install pnpm
24+
uses: pnpm/action-setup@v2
25+
with:
26+
version: 8
27+
run_install: false
28+
29+
- name: Get pnpm store directory
30+
shell: bash
31+
run: |
32+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
33+
34+
- uses: actions/cache@v3
35+
name: Setup pnpm cache
36+
with:
37+
path: ${{ env.STORE_PATH }}
38+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
39+
restore-keys: |
40+
${{ runner.os }}-pnpm-store-
41+
42+
- name: Install dependencies
43+
run: pnpm install
44+
45+
- name: Lint
46+
run: pnpm run lint
47+
48+
- name: Build
49+
run: pnpm run build
50+
51+
- name: Run tests
52+
run: pnpm test -- --watchAll=false
53+
54+
- name: Run E2E tests
55+
run: pnpm run e2e-test

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
node_modules
2-
dist
2+
dist
3+
*.tgz
4+
.npmrc
5+
.npm
6+
npm-debug.log*

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ Note that this will not work from a Mac OS host per [this Docker issue](https://
133133

134134
You can enable debugging on either the server or the client by setting the environmental variable `GIT_CREDENTIAL_FORWARDER_DEBUG` to `true`.
135135

136+
## Development
137+
138+
### Publishing to npm
139+
140+
This project uses GitHub Actions to automatically publish to npm when a new release is created. To set this up:
141+
142+
1. Generate an npm token with publish permissions
143+
2. Add the token as a GitHub repository secret named `NPM_TOKEN`
144+
3. Update the version in package.json
145+
4. Commit the changes and push to GitHub
146+
5. Create a new tag for the release: `git tag v1.x.x && git push --tags`
147+
6. Create a new release on GitHub using the tag to trigger the publishing workflow
148+
149+
The GitHub Actions workflow will use pnpm to build, test, and publish the package to the npm registry.
150+
136151
## Security
137152

138153
Nothing is perfectly secure, but I have tried to think through the security implications of running a helper like this. Here are some thoughts and I would definitely welcome any others in the issues or discussions sections:

0 commit comments

Comments
 (0)