Skip to content

Commit 881fadd

Browse files
authored
test: code format and lint (#6)
* test: code fmt and lint * test: remove unused code * test: reflactor env define * test: typo fo file * chore: code format * fix: format error * fix: action workflow warn * chore: remove unused code and typo * chore: typo not format files message out * chore: restore generated file
1 parent 6f44257 commit 881fadd

27 files changed

+356
-410
lines changed

.github/workflows/pr-check.yml

+200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
name: PR-Check
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+
PNAME: agent
14+
15+
jobs:
16+
format_check:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout current repository
20+
uses: actions/checkout@v4
21+
with:
22+
path: ${{ env.PNAME }}
23+
24+
- name: Checkout framework repository
25+
uses: actions/checkout@v4
26+
with:
27+
repository: infinilabs/framework
28+
path: framework
29+
30+
- name: Checkout framework-vendor
31+
uses: actions/checkout@v4
32+
with:
33+
ref: main
34+
repository: infinilabs/framework-vendor
35+
path: vendor
36+
37+
- name: Set up go toolchain
38+
uses: actions/setup-go@v5
39+
with:
40+
go-version: ${{ env.GO_VERSION }}
41+
check-latest: false
42+
cache: true
43+
44+
- name: Check go toolchain
45+
run: go version
46+
47+
- name: Code format
48+
shell: bash
49+
run: |
50+
echo Home path is $HOME
51+
export WORKBASE=$HOME/go/src/infini.sh
52+
export WORK=$WORKBASE/$PNAME
53+
54+
# for format workspace
55+
mkdir -p $HOME/go/src/
56+
ln -s $GITHUB_WORKSPACE $WORKBASE
57+
58+
# check work folder
59+
ls -lrt $WORKBASE/
60+
ls -alrt $WORK
61+
62+
# for code format
63+
cd $WORK
64+
echo Formating code at $PWD ...
65+
make format
66+
67+
- name: Check for changes after format
68+
id: check-changes
69+
shell: bash
70+
run: |
71+
export WORKBASE=$HOME/go/src/infini.sh
72+
export WORK=$WORKBASE/$PNAME
73+
74+
# for foramt check
75+
cd $WORK
76+
if [[ $(git status --porcelain | grep -c " M .*\.go$") -gt 0 ]]; then
77+
echo "go format detected formatting changes"
78+
echo "changes=true" >> $GITHUB_OUTPUT
79+
else
80+
echo "go format no changes found"
81+
echo "changes=false" >> $GITHUB_OUTPUT
82+
fi
83+
84+
- name: Fail workflow if changes after format
85+
if: steps.check-changes.outputs.changes == 'true'
86+
run: |
87+
export WORKBASE=$HOME/go/src/infini.sh
88+
export WORK=$WORKBASE/$PNAME
89+
90+
# for foramt check
91+
cd $WORK && echo
92+
git status --porcelain | grep " M .*\.go$"
93+
echo "----------------------------------------------------------------------------------"
94+
echo "IMPORTANT: Above files are not formatted, please run 'make format' to format them."
95+
echo "----------------------------------------------------------------------------------"
96+
exit 1
97+
98+
unit_test:
99+
runs-on: ubuntu-latest
100+
steps:
101+
- name: Checkout current repository
102+
uses: actions/checkout@v4
103+
with:
104+
path: ${{ env.PNAME }}
105+
106+
- name: Checkout framework repository
107+
uses: actions/checkout@v4
108+
with:
109+
repository: infinilabs/framework
110+
path: framework
111+
112+
- name: Checkout framework-vendor
113+
uses: actions/checkout@v4
114+
with:
115+
ref: main
116+
repository: infinilabs/framework-vendor
117+
path: vendor
118+
119+
- name: Set up go toolchain
120+
uses: actions/setup-go@v5
121+
with:
122+
go-version: ${{ env.GO_VERSION }}
123+
check-latest: false
124+
cache: true
125+
126+
- name: Check go toolchain
127+
run: go version
128+
129+
- name: Unit test
130+
env:
131+
GOFLAGS: -tags=ci
132+
run: |
133+
echo Home path is $HOME
134+
export WORKBASE=$HOME/go/src/infini.sh
135+
export WORK=$WORKBASE/$PNAME
136+
137+
# for test workspace
138+
mkdir -p $HOME/go/src/
139+
ln -s $GITHUB_WORKSPACE $WORKBASE
140+
141+
# check work folder
142+
ls -lrt $WORKBASE/
143+
ls -alrt $WORK
144+
145+
# for unit test
146+
cd $WORK
147+
echo Testing code at $PWD ...
148+
make test
149+
150+
code_lint:
151+
runs-on: ubuntu-latest
152+
steps:
153+
- name: Checkout current repository
154+
uses: actions/checkout@v4
155+
with:
156+
path: ${{ env.PNAME }}
157+
158+
- name: Checkout framework repository
159+
uses: actions/checkout@v4
160+
with:
161+
repository: infinilabs/framework
162+
path: framework
163+
164+
- name: Checkout framework-vendor
165+
uses: actions/checkout@v4
166+
with:
167+
ref: main
168+
repository: infinilabs/framework-vendor
169+
path: vendor
170+
171+
- name: Set up go toolchain
172+
uses: actions/setup-go@v5
173+
with:
174+
go-version: ${{ env.GO_VERSION }}
175+
check-latest: false
176+
cache: true
177+
178+
- name: Check go toolchain
179+
run: go version
180+
181+
- name: Code lint
182+
env:
183+
GOFLAGS: -tags=ci
184+
run: |
185+
echo Home path is $HOME
186+
export WORKBASE=$HOME/go/src/infini.sh
187+
export WORK=$WORKBASE/$PNAME
188+
189+
# for lint workspace
190+
mkdir -p $HOME/go/src/
191+
ln -s $GITHUB_WORKSPACE $WORKBASE
192+
193+
# check work folder
194+
ls -lrt $WORKBASE/
195+
ls -alrt $WORK
196+
197+
# for code lint
198+
cd $WORK
199+
echo Linting code at $PWD ...
200+
make lint

.github/workflows/unit_test.yml

-67
This file was deleted.

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ vendor
5050
trash
5151
*.so
5252
.public
53-
plugin/generated_plugins.go
53+
generated_*.go
54+
config/generated.go
55+
config/generat*.go
5456
config/*.tpl
5557
config/*.yml

0 commit comments

Comments
 (0)