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 nodejs toolchain
39
+ uses : actions/setup-node@v4
40
+ with :
41
+ node-version : ${{ env.NODEJS_VERSION }}
42
+
43
+ - name : Cache dependencies
44
+ uses : actions/cache@v4
45
+ with :
46
+ path : |
47
+ node_modules
48
+ key : ${{ runner.os }}-cnpm-${{ hashFiles('**/package.json') }}
49
+ restore-keys : |
50
+ ${{ runner.os }}-cnpm-
51
+
52
+ - name : Check nodejs toolchain
53
+ run : |
54
+ if ! command -v cnpm >/dev/null 2>&1; then
55
+ npm install -g rimraf --quiet --no-progress
56
+ npm install -g [email protected] --quiet --no-progress
57
+ fi
58
+ node -v && npm -v && cnpm -v
59
+
60
+ - name : Set up go toolchain
61
+ uses : actions/setup-go@v5
62
+ with :
63
+ go-version : ${{ env.GO_VERSION }}
64
+ check-latest : false
65
+ cache : true
66
+
67
+ - name : Check go toolchain
68
+ run : go version
69
+
70
+ - name : Cache Build Output
71
+ uses : actions/cache@v4
72
+ with :
73
+ path : |
74
+ .public
75
+ key : ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-${{ github.sha }}
76
+ restore-keys : |
77
+ ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-
78
+ ${{ runner.os }}-build-
79
+
80
+ - name : Code format
81
+ env :
82
+ GOFLAGS : -tags=ci
83
+ run : |
84
+ echo Home path is $HOME
85
+ export WORKBASE=$HOME/go/src/infini.sh
86
+ export WORK=$WORKBASE/console
87
+
88
+ # for test workspace
89
+ mkdir -p $HOME/go/src/
90
+ ln -s $GITHUB_WORKSPACE $WORKBASE
91
+
92
+ # for web build
93
+ cd $WORK/web
94
+ cnpm install --quiet --no-progress
95
+ cnpm run build --quiet
96
+
97
+ # check work folder
98
+ ls -lrt $WORKBASE/
99
+ ls -alrt $WORK
100
+
101
+ # for code format
102
+ cd $WORK
103
+ echo Formating code at $PWD ...
104
+ make format
105
+ if [ $? -ne 0 ]; then
106
+ echo "make format failed, please check make output"
107
+ exit 1
108
+ fi
109
+
110
+ - name : Check for changes after format
111
+ id : check-changes
112
+ shell : bash
113
+ run : |
114
+ export WORKBASE=$HOME/go/src/infini.sh
115
+ export WORK=$WORKBASE/$PNAME
116
+
117
+ # for foramt check
118
+ cd $WORK
119
+ if [[ $(git status --porcelain | grep -c " M .*\.go$") -gt 0 ]]; then
120
+ echo "go format detected formatting changes"
121
+ echo "changes=true" >> $GITHUB_OUTPUT
122
+ else
123
+ echo "go format no changes found"
124
+ echo "changes=false" >> $GITHUB_OUTPUT
125
+ fi
126
+
127
+ - name : Fail workflow if changes after format
128
+ if : steps.check-changes.outputs.changes == 'true'
129
+ run : exit 1
130
+
131
+ unit_test :
132
+ runs-on : ubuntu-latest
133
+ steps :
134
+ - name : Checkout current repository
135
+ uses : actions/checkout@v4
136
+ with :
137
+ path : ${{ env.PNAME }}
138
+
139
+ - name : Checkout framework repository
140
+ uses : actions/checkout@v4
141
+ with :
142
+ repository : infinilabs/framework
143
+ path : framework
144
+
145
+ - name : Checkout framework-vendor
146
+ uses : actions/checkout@v4
147
+ with :
148
+ ref : main
149
+ repository : infinilabs/framework-vendor
150
+ path : vendor
151
+
152
+ - name : Set up nodejs toolchain
153
+ uses : actions/setup-node@v4
154
+ with :
155
+ node-version : ${{ env.NODEJS_VERSION }}
156
+
157
+ - name : Cache dependencies
158
+ uses : actions/cache@v4
159
+ with :
160
+ path : |
161
+ node_modules
162
+ key : ${{ runner.os }}-cnpm-${{ hashFiles('**/package.json') }}
163
+ restore-keys : |
164
+ ${{ runner.os }}-cnpm-
165
+
166
+ - name : Check nodejs toolchain
167
+ run : |
168
+ if ! command -v cnpm >/dev/null 2>&1; then
169
+ npm install -g rimraf --quiet --no-progress
170
+ npm install -g [email protected] --quiet --no-progress
171
+ fi
172
+ node -v && npm -v && cnpm -v
173
+
174
+ - name : Set up go toolchain
175
+ uses : actions/setup-go@v5
176
+ with :
177
+ go-version : ${{ env.GO_VERSION }}
178
+ check-latest : false
179
+ cache : true
180
+
181
+ - name : Check go toolchain
182
+ run : go version
183
+
184
+ - name : Cache Build Output
185
+ uses : actions/cache@v4
186
+ with :
187
+ path : |
188
+ .public
189
+ key : ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-${{ github.sha }}
190
+ restore-keys : |
191
+ ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-
192
+ ${{ runner.os }}-build-
193
+
194
+ - name : Unit test
195
+ env :
196
+ GOFLAGS : -tags=ci
197
+ run : |
198
+ echo Home path is $HOME
199
+ export WORKBASE=$HOME/go/src/infini.sh
200
+ export WORK=$WORKBASE/$PNAME
201
+
202
+ # for test workspace
203
+ mkdir -p $HOME/go/src/
204
+ ln -s $GITHUB_WORKSPACE $WORKBASE
205
+
206
+ # for web build
207
+ cd $WORK/web
208
+ cnpm install --quiet --no-progress
209
+ cnpm run build --quiet
210
+
211
+ # check work folder
212
+ ls -lrt $WORKBASE/
213
+ ls -alrt $WORK
214
+
215
+ # for unit test
216
+ cd $WORK
217
+ echo Testing code at $PWD ...
218
+ make test
219
+
220
+ code_lint :
221
+ runs-on : ubuntu-latest
222
+ steps :
223
+ - name : Checkout current repository
224
+ uses : actions/checkout@v4
225
+ with :
226
+ path : ${{ env.PNAME }}
227
+
228
+ - name : Checkout framework repository
229
+ uses : actions/checkout@v4
230
+ with :
231
+ repository : infinilabs/framework
232
+ path : framework
233
+
234
+ - name : Checkout framework-vendor
235
+ uses : actions/checkout@v4
236
+ with :
237
+ ref : main
238
+ repository : infinilabs/framework-vendor
239
+ path : vendor
240
+
241
+ - name : Set up nodejs toolchain
242
+ uses : actions/setup-node@v4
243
+ with :
244
+ node-version : ${{ env.NODEJS_VERSION }}
245
+
246
+ - name : Cache dependencies
247
+ uses : actions/cache@v4
248
+ with :
249
+ path : |
250
+ node_modules
251
+ key : ${{ runner.os }}-cnpm-${{ hashFiles('**/package.json') }}
252
+ restore-keys : |
253
+ ${{ runner.os }}-cnpm-
254
+
255
+ - name : Check nodejs toolchain
256
+ run : |
257
+ if ! command -v cnpm >/dev/null 2>&1; then
258
+ npm install -g rimraf --quiet --no-progress
259
+ npm install -g [email protected] --quiet --no-progress
260
+ fi
261
+ node -v && npm -v && cnpm -v
262
+
263
+ - name : Set up go toolchain
264
+ uses : actions/setup-go@v5
265
+ with :
266
+ go-version : ${{ env.GO_VERSION }}
267
+ check-latest : false
268
+ cache : true
269
+
270
+ - name : Check go toolchain
271
+ run : go version
272
+
273
+ - name : Cache Build Output
274
+ uses : actions/cache@v4
275
+ with :
276
+ path : |
277
+ .public
278
+ key : ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-${{ github.sha }}
279
+ restore-keys : |
280
+ ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-
281
+ ${{ runner.os }}-build-
282
+
283
+ - name : Code lint
284
+ env :
285
+ GOFLAGS : -tags=ci
286
+ run : |
287
+ echo Home path is $HOME
288
+ export WORKBASE=$HOME/go/src/infini.sh
289
+ export WORK=$WORKBASE/$PNAME
290
+
291
+ # for test workspace
292
+ mkdir -p $HOME/go/src/
293
+ ln -s $GITHUB_WORKSPACE $WORKBASE
294
+
295
+ # for web build
296
+ cd $WORK/web
297
+ cnpm install --quiet --no-progress
298
+ cnpm run build --quiet
299
+
300
+ # check work folder
301
+ ls -lrt $WORKBASE/
302
+ ls -alrt $WORK
303
+
304
+ # for code lint
305
+ cd $WORK
306
+ echo Testing code at $PWD ...
307
+ # make lint
0 commit comments