Skip to content

Commit 051bc96

Browse files
committed
ci: test and build
Signed-off-by: Yves Brissaud <[email protected]>
1 parent 6d92b4b commit 051bc96

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

.github/workflows/go.yml

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
name: Build and test
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
push:
9+
branches:
10+
- 'main'
11+
pull_request:
12+
branches:
13+
- 'main'
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout merge commit if on PR
20+
if: ${{ !startsWith(github.ref, 'refs/heads/release/') }}
21+
uses: actions/checkout@v3
22+
- name: Checkout HEAD commit
23+
if: startsWith(github.ref, 'refs/heads/release/')
24+
uses: actions/checkout@v3
25+
with:
26+
ref: ${{ github.event.pull_request.head.sha }}
27+
28+
- name: Set up Go
29+
uses: actions/setup-go@v5
30+
with:
31+
go-version-file: './go.mod'
32+
cache: true
33+
34+
- name: Install Task
35+
uses: arduino/setup-task@v1
36+
with:
37+
repo-token: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Set up containerd
40+
uses: crazy-max/ghaction-setup-docker@v3
41+
with:
42+
set-host: true
43+
daemon-config: |
44+
{
45+
"features": {
46+
"containerd-snapshotter": true
47+
}
48+
}
49+
50+
- name: Go dependencies
51+
run: task go:checkmodules
52+
53+
- name: Test
54+
run: task go:test
55+
56+
lint:
57+
runs-on: ubuntu-latest
58+
steps:
59+
- name: Checkout merge commit if on PR
60+
if: ${{ !startsWith(github.ref, 'refs/heads/release/') }}
61+
uses: actions/checkout@v3
62+
- name: Checkout HEAD commit
63+
if: startsWith(github.ref, 'refs/heads/release/')
64+
uses: actions/checkout@v3
65+
with:
66+
ref: ${{ github.event.pull_request.head.sha }}
67+
68+
- name: Set up Go
69+
uses: actions/setup-go@v5
70+
with:
71+
go-version-file: './go.mod'
72+
cache: true
73+
74+
- name: Install Task
75+
uses: arduino/setup-task@v1
76+
with:
77+
repo-token: ${{ secrets.GITHUB_TOKEN }}
78+
79+
- name: Set up containerd
80+
uses: crazy-max/ghaction-setup-docker@v3
81+
with:
82+
set-host: true
83+
daemon-config: |
84+
{
85+
"features": {
86+
"containerd-snapshotter": true
87+
}
88+
}
89+
90+
- name: Go dependencies
91+
run: task go:checkmodules
92+
93+
- name: CI dependencies
94+
run: task ci:install
95+
96+
- name: golangci-lint
97+
run: task go:lint
98+
99+
- name: Run checks
100+
run: |
101+
STATUS=0
102+
assert-nothing-changed() {
103+
local diff
104+
"$@" >/dev/null || return 1
105+
if ! diff="$(git diff -U1 --color --exit-code)"; then
106+
printf '\e[31mError: running `\e[1m%s\e[22m` results in modifications that you must check into version control:\e[0m\n%s\n\n' "$*" "$diff" >&2
107+
git checkout -- .
108+
STATUS=1
109+
fi
110+
}
111+
assert-nothing-changed task go:fmt
112+
assert-nothing-changed task go:tidy
113+
assert-nothing-changed task go:gendocs
114+
115+
build:
116+
runs-on: ubuntu-latest
117+
steps:
118+
- name: Checkout merge commit if on PR
119+
if: ${{ !startsWith(github.ref, 'refs/heads/release/') }}
120+
uses: actions/checkout@v3
121+
- name: Checkout HEAD commit
122+
if: startsWith(github.ref, 'refs/heads/release/')
123+
uses: actions/checkout@v3
124+
with:
125+
ref: ${{ github.event.pull_request.head.sha }}
126+
127+
- name: Set up Go
128+
uses: actions/setup-go@v5
129+
with:
130+
go-version-file: './go.mod'
131+
cache: true
132+
133+
- name: Install Task
134+
uses: arduino/setup-task@v1
135+
with:
136+
repo-token: ${{ secrets.GITHUB_TOKEN }}
137+
138+
- name: Set up containerd
139+
uses: crazy-max/ghaction-setup-docker@v3
140+
with:
141+
set-host: true
142+
daemon-config: |
143+
{
144+
"features": {
145+
"containerd-snapshotter": true
146+
}
147+
}
148+
149+
- name: Go dependencies
150+
run: task go:checkmodules
151+
152+
- name: Test
153+
run: task go:bin

0 commit comments

Comments
 (0)