Skip to content

Commit 1e814b5

Browse files
committed
ci.yml
1 parent c7564d8 commit 1e814b5

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

.github/workflows/ci.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
node-version:
17+
- 20.x
18+
- 22.x
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Use Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v1
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
- run: npm ci
26+
- run: npm run build
27+
- run: npm test
28+
- name: Save build
29+
if: matrix.node-version == '20.x'
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: build
33+
path: |
34+
.
35+
!node_modules
36+
retention-days: 1
37+
38+
gh-pages:
39+
needs: test
40+
runs-on: ubuntu-latest
41+
if: github.ref == 'refs/heads/main'
42+
permissions:
43+
contents: write
44+
pages: write
45+
steps:
46+
- uses: actions/download-artifact@v4
47+
with:
48+
name: build
49+
- uses: peaceiris/actions-gh-pages@v3
50+
with:
51+
github_token: ${{ github.token }}
52+
publish_dir: .
53+
54+
npm-publish-build:
55+
needs: test
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/download-artifact@v4
59+
with:
60+
name: build
61+
- uses: actions/setup-node@v1
62+
with:
63+
node-version: 20.x
64+
- uses: rlespinasse/github-slug-action@v3.x
65+
- name: Append commit hash to package version
66+
run: 'sed -i -E "s/(\"version\": *\"[^\"]+)/\1-${GITHUB_SHA_SHORT}/" package.json'
67+
- name: Disable pre- and post-publish actions
68+
run: 'sed -i -E "s/\"((pre|post)publish)/\"ignore:\1/" package.json'
69+
- uses: JS-DevTools/npm-publish@v1
70+
with:
71+
token: ${{ secrets.NPM_TOKEN }}
72+
tag: ${{ env.GITHUB_REF_SLUG }}
73+
npm-publish-latest:
74+
needs: test
75+
runs-on: ubuntu-latest
76+
if: github.ref == 'refs/heads/main'
77+
steps:
78+
- uses: actions/download-artifact@v4
79+
with:
80+
name: build
81+
- uses: actions/setup-node@v1
82+
with:
83+
node-version: 20.x
84+
- name: Disable pre- and post-publish actions
85+
run: 'sed -i -E "s/\"((pre|post)publish)/\"ignore:\1/" package.json'
86+
- uses: JS-DevTools/npm-publish@v1
87+
with:
88+
token: ${{ secrets.NPM_TOKEN }}
89+
tag: latest

0 commit comments

Comments
 (0)