Skip to content

Commit 6f56f05

Browse files
committed
Add test & gofmt workflows
1 parent 90bd85d commit 6f56f05

3 files changed

Lines changed: 92 additions & 0 deletions

File tree

.github/workflows/gofmt.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
if [ -z "$1" ]; then
4+
rm -f ./gofmterr
5+
find . -iname '*.go' ! -name '*.pb.go' -exec "$0" {} \;
6+
[ -f ./gofmterr ] && exit 1
7+
exit 0
8+
fi
9+
10+
OUT="$(./goimports -d "$1" | awk '{printf "%s%%0A",$0}')"
11+
if [ -n "$OUT" ]; then
12+
echo "::error file=$1::$OUT"
13+
touch ./gofmterr
14+
fi

.github/workflows/gofmt.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: gofmt
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
paths:
8+
- ".github/workflows/gofmt.yml"
9+
- ".github/workflows/gofmt.sh"
10+
- "**.go"
11+
12+
jobs:
13+
gofmt:
14+
name: Run gofmt
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Set up Go 1.19
18+
uses: actions/setup-go@v2
19+
with:
20+
go-version: 1.19
21+
id: go
22+
23+
- name: Check out code into the Go module directory
24+
uses: actions/checkout@v2
25+
26+
- uses: actions/cache@v2
27+
with:
28+
path: ~/go/pkg/mod
29+
key: ${{ runner.os }}-gofmt1.19-${{ hashFiles('**/go.sum') }}
30+
restore-keys: |
31+
${{ runner.os }}-gofmt1.19-
32+
33+
- name: Install goimports
34+
run: |
35+
go get golang.org/x/tools/cmd/goimports
36+
go build golang.org/x/tools/cmd/goimports
37+
38+
- name: gofmt
39+
run: $GITHUB_WORKSPACE/.github/workflows/gofmt.sh

.github/workflows/test.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build and test
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
paths:
8+
- ".github/workflows/test.yml"
9+
- "**Makefile"
10+
- "**.go"
11+
- "**.proto"
12+
- "go.mod"
13+
- "go.sum"
14+
15+
jobs:
16+
test-linux:
17+
name: Build and test on Ubuntu
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Set up Go 1.19
21+
uses: actions/setup-go@v2
22+
with:
23+
go-version: 1.19
24+
id: go
25+
26+
- name: Check out code
27+
uses: actions/checkout@v3
28+
29+
- uses: actions/cache@v2
30+
with:
31+
path: ~/go/pkg/mod
32+
key: ${{ runner.os }}-go1.19-${{ hashFiles('**/go.sum') }}
33+
restore-keys: |
34+
${{ runner.os }}-go1.19-
35+
36+
- name: Run unit tests
37+
run: make testvv
38+
env:
39+
TEST_FLAGS: -race

0 commit comments

Comments
 (0)