Skip to content

Commit 6507c7b

Browse files
workflow to release package in npm and github
1 parent 4ad790e commit 6507c7b

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

.github/workflows/publish.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Publish Package
2+
on:
3+
release:
4+
types: [published]
5+
6+
jobs:
7+
prepare:
8+
permissions:
9+
contents: write
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
token: ${{ secrets.GITHUB_TOKEN }}
15+
ref: ${{ github.event.repository.default_branch }}
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: 24
20+
registry-url: https://registry.npmjs.org
21+
- name: Install dependencies
22+
run: npm ci
23+
- name: Build
24+
run: npm run build
25+
- name: Run tests
26+
run: npm test
27+
- name: Update package.json with release tag
28+
run: |
29+
TAG="${{ github.event.release.tag_name }}"
30+
echo "Updating package.json version to $TAG"
31+
npm version "$TAG" --no-git-tag-version
32+
- name: Commit and push version update
33+
run: |
34+
TAG="${{ github.event.release.tag_name }}"
35+
git config user.name "github-actions"
36+
git config user.email "github-actions@github.com"
37+
git add package.json package-lock.json
38+
git commit -m "Update package.json to version $TAG"
39+
git push origin ${{ github.event.repository.default_branch }}
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
43+
publish-npm:
44+
needs: prepare
45+
permissions:
46+
id-token: write
47+
contents: read
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v4
51+
- uses: actions/setup-node@v4
52+
with:
53+
node-version: 24
54+
registry-url: https://registry.npmjs.org
55+
56+
- run: npm ci
57+
- run: npm run release
58+
59+
publish-github:
60+
needs: prepare
61+
runs-on: ubuntu-latest
62+
permissions:
63+
contents: read
64+
packages: write
65+
steps:
66+
- uses: actions/checkout@v4
67+
- uses: actions/setup-node@v4
68+
with:
69+
node-version: 24
70+
registry-url: 'https://npm.pkg.github.com'
71+
- run: npm ci
72+
- run: npm run release
73+
env:
74+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
},
2323
"scripts": {
2424
"test": "mocha --require tsx 'tests/**/*.ts'",
25-
"lint": "oxlint 'src/**/*.ts' 'tests/**/*.ts'",
26-
"build": "tsl -p tsconfig.build.json",
25+
"lint": "oxlint 'src/**/*.ts' 'tests/**/*.ts' && tsl -p tsconfig.json",
26+
"build": "tsc -p tsconfig.build.json",
2727
"release": "npm run build && cp package.json dist && cp README.md dist && npm publish ./dist",
2828
"prepare": "husky"
2929
},

0 commit comments

Comments
 (0)