Skip to content

Commit 2f16879

Browse files
authored
feat(workflows): reusable unit test (#40)
1 parent 807b72d commit 2f16879

1 file changed

Lines changed: 123 additions & 0 deletions

File tree

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: reusable-unit-test
2+
on:
3+
workflow_call:
4+
inputs:
5+
skip-site:
6+
required: false
7+
type: boolean
8+
default: false
9+
node-version:
10+
required: false
11+
type: string
12+
default: '22'
13+
node-version-file:
14+
required: false
15+
type: string
16+
default: ''
17+
jobs:
18+
check:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: TDesignOteam/workflows/actions/check-email@main
22+
23+
test:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
with:
28+
submodules: recursive
29+
- uses: actions/setup-node@v4
30+
with:
31+
node-version: ${{ inputs.node-version }}
32+
node-version-file: ${{ inputs.node-version-file }}
33+
- uses: actions/cache@v4
34+
env:
35+
cache-name: cache-nodemodules
36+
with:
37+
path: ~/.npm
38+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
39+
restore-keys: |
40+
${{ runner.os }}-build-${{ env.cache-name }}-
41+
${{ runner.os }}-build-
42+
${{ runner.os }}-
43+
- run: npm install
44+
45+
- run: npm run lint
46+
- run: npm run test
47+
# upload report to codecov
48+
- uses: codecov/codecov-action@v2
49+
with:
50+
token: ${{ secrets.CODECOV_TOKEN }}
51+
52+
site:
53+
if: ${{ inputs.skip-site }}
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v4
57+
with:
58+
submodules: recursive
59+
- uses: actions/setup-node@v4
60+
with:
61+
node-version: ${{ inputs.node-version }}
62+
node-version-file: ${{ inputs.node-version-file }}
63+
64+
- uses: actions/cache@v4
65+
env:
66+
cache-name: cache-nodemodules
67+
with:
68+
path: ~/.npm
69+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
70+
restore-keys: |
71+
${{ runner.os }}-build-${{ env.cache-name }}-
72+
${{ runner.os }}-build-
73+
${{ runner.os }}-
74+
- run: npm install
75+
76+
- name: Build site
77+
run: npm run site:preview
78+
79+
- run: |
80+
zip -r _site.zip _site
81+
82+
- name: upload _site artifact
83+
uses: actions/upload-artifact@v4
84+
with:
85+
name: _site
86+
path: _site.zip
87+
retention-days: 5
88+
89+
- name: Save PR number
90+
if: ${{ always() }}
91+
run: echo ${{ github.event.number }} > ./pr-id.txt
92+
93+
- name: Upload PR number
94+
if: ${{ always() }}
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: pr
98+
path: ./pr-id.txt
99+
100+
build:
101+
runs-on: ubuntu-latest
102+
steps:
103+
- uses: actions/checkout@v4
104+
with:
105+
submodules: recursive
106+
- uses: actions/setup-node@v4
107+
with:
108+
node-version: ${{ inputs.node-version }}
109+
node-version-file: ${{ inputs.node-version-file }}
110+
- uses: actions/cache@v4
111+
env:
112+
cache-name: cache-nodemodules
113+
with:
114+
path: ~/.npm
115+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
116+
restore-keys: |
117+
${{ runner.os }}-build-${{ env.cache-name }}-
118+
${{ runner.os }}-build-
119+
${{ runner.os }}-
120+
- run: npm install
121+
122+
- name: Build
123+
run: npm run build

0 commit comments

Comments
 (0)