Skip to content

Commit 46f86f7

Browse files
committed
ci: add publish and test workflows
1 parent f7f78e1 commit 46f86f7

2 files changed

Lines changed: 163 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: Publish Package
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version bump type'
8+
required: true
9+
type: choice
10+
options: [patch, minor, major, prepatch, preminor, premajor, prerelease]
11+
custom_version:
12+
description: 'Custom version (optional, overrides version type)'
13+
required: false
14+
type: string
15+
preid:
16+
description: 'Prerelease identifier'
17+
required: false
18+
type: choice
19+
options: [beta, alpha, rc, next]
20+
default: 'beta'
21+
dry_run:
22+
description: 'Dry run (do not actually publish)'
23+
required: false
24+
type: boolean
25+
default: false
26+
tag:
27+
description: 'NPM dist-tag'
28+
required: false
29+
type: choice
30+
options: [latest, next, beta, alpha]
31+
default: 'latest'
32+
33+
concurrency:
34+
group: publish-package
35+
cancel-in-progress: false
36+
37+
permissions:
38+
contents: write
39+
id-token: write
40+
41+
env:
42+
NPM_CONFIG_FUND: false
43+
44+
jobs:
45+
build:
46+
name: Build & Version
47+
runs-on: ubuntu-latest
48+
outputs:
49+
new_version: ${{ steps.bump.outputs.new_version }}
50+
51+
steps:
52+
- uses: actions/checkout@v4
53+
with:
54+
token: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- uses: actions/setup-node@v4
57+
with:
58+
node-version: '22.14.0'
59+
cache: 'npm'
60+
registry-url: 'https://registry.npmjs.org'
61+
62+
- run: npm ci
63+
64+
- name: Version package
65+
id: bump
66+
run: |
67+
CUSTOM="${{ github.event.inputs.custom_version }}"
68+
if [ -n "$CUSTOM" ]; then
69+
npm version "$CUSTOM" --no-git-tag-version --allow-same-version
70+
else
71+
npm version "${{ github.event.inputs.version }}" --no-git-tag-version --preid="${{ github.event.inputs.preid }}"
72+
fi
73+
NEW_VERSION=$(node -p "require('./package.json').version")
74+
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
75+
76+
- run: npm run build
77+
78+
- uses: actions/upload-artifact@v4
79+
with:
80+
name: build-output
81+
path: |
82+
package.json
83+
dist/
84+
retention-days: 1
85+
86+
publish:
87+
name: Publish to NPM
88+
needs: build
89+
runs-on: ubuntu-latest
90+
steps:
91+
- uses: actions/checkout@v4
92+
- uses: actions/setup-node@v4
93+
with:
94+
node-version: '22.14.0'
95+
registry-url: 'https://registry.npmjs.org'
96+
- run: npm install -g npm@latest
97+
98+
- uses: actions/download-artifact@v4
99+
with:
100+
name: build-output
101+
path: .
102+
103+
- name: Dry run
104+
if: github.event.inputs.dry_run == 'true'
105+
run: npm publish --dry-run --access public --tag ${{ github.event.inputs.tag }} --ignore-scripts
106+
107+
- name: Publish
108+
if: github.event.inputs.dry_run != 'true'
109+
run: npm publish --access public --provenance --tag ${{ github.event.inputs.tag }} --ignore-scripts
110+
env:
111+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
112+
113+
release:
114+
name: Create Release
115+
needs: [build, publish]
116+
runs-on: ubuntu-latest
117+
if: github.event.inputs.dry_run != 'true'
118+
steps:
119+
- uses: actions/checkout@v4
120+
with:
121+
fetch-depth: 0
122+
token: ${{ secrets.GITHUB_TOKEN }}
123+
- uses: actions/download-artifact@v4
124+
with:
125+
name: build-output
126+
path: .
127+
- name: Tag and push
128+
env:
129+
NEW_VERSION: ${{ needs.build.outputs.new_version }}
130+
run: |
131+
git config user.name "GitHub Actions"
132+
git config user.email "actions@github.com"
133+
git add package.json
134+
git diff --staged --quiet || git commit -m "chore(release): v${NEW_VERSION}"
135+
git push
136+
git tag -a "v${NEW_VERSION}" -m "Release v${NEW_VERSION}"
137+
git push origin "v${NEW_VERSION}"
138+
- uses: softprops/action-gh-release@v2
139+
with:
140+
tag_name: v${{ needs.build.outputs.new_version }}
141+
generate_release_notes: true
142+
env:
143+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: '22.14.0'
18+
cache: 'npm'
19+
- run: npm ci
20+
- run: npm test

0 commit comments

Comments
 (0)