Skip to content

Commit 188bcfb

Browse files
committed
chore add pr_check
1 parent f07f5af commit 188bcfb

File tree

1 file changed

+232
-0
lines changed

1 file changed

+232
-0
lines changed

.github/workflows/pr_check.yml

+232
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
name: Unit Test
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
7+
defaults:
8+
run:
9+
shell: bash
10+
11+
env:
12+
GO_VERSION: 1.23.4
13+
NODEJS_VERSION: 16.20.2
14+
PNAME: console
15+
16+
jobs:
17+
format_check:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout current repository
21+
uses: actions/checkout@v4
22+
with:
23+
path: ${{ env.PNAME }}
24+
25+
- name: Checkout framework repository
26+
uses: actions/checkout@v4
27+
with:
28+
repository: infinilabs/framework
29+
path: framework
30+
31+
- name: Checkout framework-vendor
32+
uses: actions/checkout@v4
33+
with:
34+
ref: main
35+
repository: infinilabs/framework-vendor
36+
path: vendor
37+
38+
- name: Set up go toolchain
39+
uses: actions/setup-go@v5
40+
with:
41+
go-version: ${{ env.GO_VERSION }}
42+
check-latest: false
43+
cache: true
44+
45+
- name: Check go toolchain
46+
run: go version
47+
48+
- name: Run make format
49+
shell: bash
50+
run: |
51+
echo Home path is $HOME
52+
export WORKBASE=$HOME/go/src/infini.sh
53+
export WORK=$WORKBASE/$PNAME
54+
55+
# for test workspace
56+
mkdir -p $HOME/go/src/
57+
ln -s $GITHUB_WORKSPACE $WORKBASE
58+
59+
# check work folder
60+
ls -lrt $WORKBASE/
61+
ls -alrt $WORK
62+
63+
# for unit test
64+
cd $WORK
65+
echo Formating code at $PWD ...
66+
make format
67+
if [ $? -ne 0 ]; then
68+
echo "make format failed, please check make output"
69+
exit 1
70+
fi
71+
72+
- name: Check for changes after format
73+
id: check-changes
74+
shell: bash
75+
run: |
76+
export WORKBASE=$HOME/go/src/infini.sh
77+
export WORK=$WORKBASE/$PNAME
78+
79+
# for foramt check
80+
cd $WORK
81+
if [[ $(git status --porcelain | grep -c " M .*\.go$") -gt 0 ]]; then
82+
echo "go format detected formatting changes"
83+
echo "changes=true" >> $GITHUB_OUTPUT
84+
else
85+
echo "go format no changes found"
86+
echo "changes=false" >> $GITHUB_OUTPUT
87+
fi
88+
89+
- name: Fail workflow if changes after format
90+
if: steps.check-changes.outputs.changes == 'true'
91+
run: exit 1
92+
93+
unit_test:
94+
runs-on: ubuntu-latest
95+
steps:
96+
- name: Checkout current repository
97+
uses: actions/checkout@v4
98+
with:
99+
path: console
100+
101+
- name: Checkout framework repository
102+
uses: actions/checkout@v4
103+
with:
104+
repository: infinilabs/framework
105+
path: framework
106+
107+
- name: Checkout framework-vendor
108+
uses: actions/checkout@v4
109+
with:
110+
ref: main
111+
repository: infinilabs/framework-vendor
112+
path: vendor
113+
114+
- name: Set up nodejs toolchain
115+
uses: actions/setup-node@v4
116+
with:
117+
node-version: ${{ env.NODEJS_VERSION }}
118+
119+
- name: Cache dependencies
120+
uses: actions/cache@v4
121+
with:
122+
path: |
123+
node_modules
124+
key: ${{ runner.os }}-cnpm-${{ hashFiles('**/package.json') }}
125+
restore-keys: |
126+
${{ runner.os }}-cnpm-
127+
128+
- name: Check nodejs toolchain
129+
run: |
130+
if ! command -v cnpm >/dev/null 2>&1; then
131+
npm install -g rimraf --quiet --no-progress
132+
npm install -g [email protected] --quiet --no-progress
133+
fi
134+
node -v && npm -v && cnpm -v
135+
136+
- name: Set up go toolchain
137+
uses: actions/setup-go@v5
138+
with:
139+
go-version: ${{ env.GO_VERSION }}
140+
check-latest: false
141+
cache: true
142+
143+
- name: Check go toolchain
144+
run: go version
145+
146+
- name: Cache Build Output
147+
uses: actions/cache@v4
148+
with:
149+
path: |
150+
.public
151+
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-${{ github.sha }}
152+
restore-keys: |
153+
${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-
154+
${{ runner.os }}-build-
155+
156+
- name: Unit test
157+
env:
158+
GOFLAGS: -tags=ci
159+
run: |
160+
echo Home path is $HOME
161+
export WORKBASE=$HOME/go/src/infini.sh
162+
export WORK=$WORKBASE/console
163+
164+
# for test workspace
165+
mkdir -p $HOME/go/src/
166+
ln -s $GITHUB_WORKSPACE $WORKBASE
167+
168+
# for web build
169+
cd $WORK/web
170+
cnpm install --quiet --no-progress
171+
cnpm run build --quiet
172+
173+
# check work folder
174+
ls -lrt $WORKBASE/
175+
ls -alrt $WORK
176+
177+
# for unit test
178+
cd $WORK
179+
echo Testing code at $PWD ...
180+
make test
181+
182+
code_lint:
183+
runs-on: ubuntu-latest
184+
steps:
185+
- name: Checkout current repository
186+
uses: actions/checkout@v4
187+
with:
188+
path: ${{ env.PNAME }}
189+
190+
- name: Checkout framework repository
191+
uses: actions/checkout@v4
192+
with:
193+
repository: infinilabs/framework
194+
path: framework
195+
196+
- name: Checkout framework-vendor
197+
uses: actions/checkout@v4
198+
with:
199+
ref: main
200+
repository: infinilabs/framework-vendor
201+
path: vendor
202+
203+
- name: Set up go toolchain
204+
uses: actions/setup-go@v5
205+
with:
206+
go-version: ${{ env.GO_VERSION }}
207+
check-latest: false
208+
cache: true
209+
210+
- name: Check go toolchain
211+
run: go version
212+
213+
- name: Code lint
214+
env:
215+
GOFLAGS: -tags=ci
216+
run: |
217+
echo Home path is $HOME
218+
export WORKBASE=$HOME/go/src/infini.sh
219+
export WORK=$WORKBASE/$PNAME
220+
221+
# for test workspace
222+
mkdir -p $HOME/go/src/
223+
ln -s $GITHUB_WORKSPACE $WORKBASE
224+
225+
# check work folder
226+
ls -lrt $WORKBASE/
227+
ls -alrt $WORK
228+
229+
# for unit test
230+
cd $WORK
231+
echo Linting code at $PWD ...
232+
make lint

0 commit comments

Comments
 (0)