Skip to content

Commit b262353

Browse files
author
AstroAir
committed
ci: refactor release workflow and add package validation
## Changes - ci: Remove release job from ci.yml workflow - ci: Split release.yml into validate and publish jobs - ci: Add validate job with lint, typecheck, test, build, publint, and size checks - ci: Add publish-gpr job for GitHub Packages publishing - ci: Update Node.js version from 20 to 22 - ci: Add id-token write permission for npm provenance - ci: Add --provenance and --access public flags to npm publish - package: Add publint, size-
1 parent 19916cb commit b262353

5 files changed

Lines changed: 489 additions & 38 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,3 @@ jobs:
3939

4040
- name: Build
4141
run: pnpm build
42-
43-
release:
44-
needs: ci
45-
runs-on: ubuntu-latest
46-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
47-
48-
steps:
49-
- uses: actions/checkout@v4
50-
51-
- uses: pnpm/action-setup@v4
52-
53-
- name: Use Node.js 20
54-
uses: actions/setup-node@v4
55-
with:
56-
node-version: 20
57-
cache: pnpm
58-
registry-url: https://registry.npmjs.org
59-
60-
- name: Install dependencies
61-
run: pnpm install --frozen-lockfile
62-
63-
- name: Build
64-
run: pnpm build
65-
66-
- name: Publish to npm
67-
run: pnpm publish --no-git-checks
68-
env:
69-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/release.yml

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,58 @@ on:
77

88
permissions:
99
contents: write
10+
id-token: write
1011

1112
jobs:
12-
release:
13+
validate:
1314
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: pnpm/action-setup@v4
19+
20+
- name: Use Node.js 22
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 22
24+
cache: pnpm
25+
26+
- name: Install dependencies
27+
run: pnpm install --frozen-lockfile
1428

29+
- name: Lint
30+
run: pnpm lint
31+
32+
- name: Type check
33+
run: pnpm typecheck
34+
35+
- name: Test
36+
run: pnpm test
37+
38+
- name: Build
39+
run: pnpm build
40+
41+
- name: Validate package
42+
run: pnpm publint
43+
44+
- name: Check bundle size
45+
run: pnpm size
46+
47+
publish:
48+
needs: validate
49+
runs-on: ubuntu-latest
50+
environment: npm
1551
steps:
1652
- uses: actions/checkout@v4
1753
with:
1854
fetch-depth: 0
1955

2056
- uses: pnpm/action-setup@v4
2157

22-
- name: Use Node.js 20
58+
- name: Use Node.js 22
2359
uses: actions/setup-node@v4
2460
with:
25-
node-version: 20
61+
node-version: 22
2662
cache: pnpm
2763
registry-url: https://registry.npmjs.org
2864

@@ -32,15 +68,42 @@ jobs:
3268
- name: Build
3369
run: pnpm build
3470

35-
- name: Test
36-
run: pnpm test
37-
3871
- name: Publish to npm
39-
run: pnpm publish --no-git-checks
72+
run: pnpm publish --no-git-checks --provenance --access public
4073
env:
4174
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4275

4376
- name: Generate release notes
4477
uses: softprops/action-gh-release@v2
4578
with:
4679
generate_release_notes: true
80+
81+
publish-gpr:
82+
needs: validate
83+
runs-on: ubuntu-latest
84+
permissions:
85+
contents: read
86+
packages: write
87+
steps:
88+
- uses: actions/checkout@v4
89+
90+
- uses: pnpm/action-setup@v4
91+
92+
- name: Use Node.js 22
93+
uses: actions/setup-node@v4
94+
with:
95+
node-version: 22
96+
cache: pnpm
97+
registry-url: https://npm.pkg.github.com
98+
scope: '@elementastro'
99+
100+
- name: Install dependencies
101+
run: pnpm install --frozen-lockfile
102+
103+
- name: Build
104+
run: pnpm build
105+
106+
- name: Publish to GitHub Packages
107+
run: pnpm publish --no-git-checks --registry https://npm.pkg.github.com
108+
env:
109+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.npmrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
shamefully-hoist=false
22
strict-peer-dependencies=false
33
auto-install-peers=true
4+
5+
# Publish registry
6+
registry=https://registry.npmjs.org/
7+
8+
# GitHub Packages (uncomment to use as default publish target)
9+
# @elementastro:registry=https://npm.pkg.github.com

package.json

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,26 @@
3030
"test:coverage": "vitest run --coverage",
3131
"lint": "eslint .",
3232
"lint:fix": "eslint . --fix",
33-
"clean": "rm -rf dist docs/.vitepress/dist docs/.vitepress/cache coverage",
33+
"clean": "node -e \"const fs=require('fs');['dist','docs/.vitepress/dist','docs/.vitepress/cache','coverage'].forEach(d=>{fs.rmSync(d,{recursive:true,force:true})})\"",
3434
"format": "prettier --write \"src/**/*.ts\"",
3535
"format:check": "prettier --check \"src/**/*.ts\"",
3636
"typecheck": "tsc --noEmit",
3737
"docs:dev": "vitepress dev docs",
3838
"docs:build": "vitepress build docs",
3939
"docs:preview": "vitepress preview docs",
4040
"prepare": "husky",
41-
"prepublishOnly": "pnpm run build",
41+
"prepublishOnly": "pnpm run build && pnpm run publint",
42+
"prepack": "pnpm run clean && pnpm run build",
43+
"publint": "publint",
44+
"pack:check": "pnpm pack && node -e \"require('fs').unlinkSync(require('./package.json').name+'-'+require('./package.json').version+'.tgz')\"",
45+
"size": "size-limit",
46+
"size:analyze": "size-limit --why",
47+
"release:patch": "pnpm version patch && git push --follow-tags",
48+
"release:minor": "pnpm version minor && git push --follow-tags",
49+
"release:major": "pnpm version major && git push --follow-tags",
50+
"publish:dry": "pnpm publish --dry-run --no-git-checks",
51+
"publish:npm": "pnpm publish --no-git-checks --access public",
52+
"publish:gpr": "pnpm publish --no-git-checks --registry https://npm.pkg.github.com",
4253
"demo": "tsx demo/index.ts",
4354
"demo:web": "pnpm run build && pnpm dlx serve ."
4455
},
@@ -55,16 +66,30 @@
5566
"license": "MIT",
5667
"repository": {
5768
"type": "git",
58-
"url": "https://github.com/ElementAstro/fitsjs-ng.git"
69+
"url": "git+https://github.com/ElementAstro/fitsjs-ng.git"
5970
},
6071
"homepage": "https://github.com/ElementAstro/fitsjs-ng#readme",
6172
"bugs": {
6273
"url": "https://github.com/ElementAstro/fitsjs-ng/issues"
6374
},
75+
"publishConfig": {
76+
"registry": "https://registry.npmjs.org",
77+
"access": "public"
78+
},
6479
"engines": {
6580
"node": ">=18"
6681
},
6782
"packageManager": "pnpm@9.15.4",
83+
"size-limit": [
84+
{
85+
"path": "dist/index.js",
86+
"limit": "25 kB"
87+
},
88+
{
89+
"path": "dist/index.cjs",
90+
"limit": "25 kB"
91+
}
92+
],
6893
"devDependencies": {
6994
"@commitlint/cli": "^20.4.1",
7095
"@commitlint/config-conventional": "^20.4.1",
@@ -73,7 +98,10 @@
7398
"eslint": "^9.0.0",
7499
"husky": "^9.1.7",
75100
"lint-staged": "^16.2.7",
101+
"@size-limit/preset-small-lib": "^11.2.0",
76102
"prettier": "^3.8.1",
103+
"publint": "^0.3.12",
104+
"size-limit": "^11.2.0",
77105
"tsup": "^8.5.1",
78106
"tsx": "^4.19.0",
79107
"typescript": "^5.9.3",

0 commit comments

Comments
 (0)