-
Notifications
You must be signed in to change notification settings - Fork 0
70 lines (61 loc) · 1.55 KB
/
go-unit-tests.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Go unit tests
on:
pull_request:
types: [ opened, edited, reopened, synchronize ]
paths:
- 'src/**'
push:
branches:
- master
paths:
- 'src/**'
workflow_dispatch:
jobs:
test:
strategy:
matrix:
go-version: [ 1.22.x ]
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
env:
SKIP: 0
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for changes in src
id: changes
run: |
if git diff --quiet HEAD^ HEAD -- ./src; then
echo "SKIP=1" >> $GITHUB_ENV
fi
- name: Install Go
if: env.SKIP == '0'
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Restore cache
if: env.SKIP == '0'
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Gofmt
if: env.SKIP == '0' && matrix.os == 'ubuntu-latest'
working-directory: ${{ github.workspace }}/src
run: |
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ];
then
gofmt -w .
git diff
exit 1
fi
- name: Build
if: env.SKIP == '0'
working-directory: ${{ github.workspace }}/src
run: go build -v ./...
- name: Test
if: env.SKIP == '0'
working-directory: ${{ github.workspace }}/src
run: go test -v ./...