-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (111 loc) · 3.83 KB
/
golang-test.yaml
File metadata and controls
112 lines (111 loc) · 3.83 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
on:
workflow_call:
inputs:
go_version:
type: string
required: false
default: 1.17
run_static_check:
type: boolean
required: false
default: true
static_check_version:
type: string
required: false
default: v0.3.3
run_docker_login:
type: boolean
required: false
default: true
test_docker_compose_path:
required: false
type: string
secrets:
DOCKER_HUB_USERNAME:
required: false
DOCKER_HUB_ACCESS_TOKEN:
required: false
GITHUB_ACCESS_TOKEN:
required: true
env:
GOPATH: ${{ github.workspace }}/go
PROJECTPATH: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}
GOPRIVATE: "github.com/gamezop,github.com/Gamezop"
jobs:
test:
runs-on: ubuntu-latest
name: test
defaults:
run:
working-directory: ./go/src/github.com/${{ github.repository }}
steps:
- name: setup go
uses: actions/setup-go@v2
with:
go-version: ${{ inputs.go_version }}
- name: checkout ${{ github.repository }}
uses: actions/checkout@v2
with:
fetch-depth: 1
path: ./go/src/github.com/${{ github.repository }}
- name: Log in to Docker Hub
if: ${{ inputs.test_docker_compose_path != '' && inputs.run_docker_login }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Stackup
if: ${{ inputs.test_docker_compose_path != '' }}
run: |
docker compose -f "${{ inputs.test_docker_compose_path }}" up -d --build
shell: bash
- name: set up cache env paths
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
echo "::set-output name=go-bin::$GOPATH/bin"
- name: Go Mod Cache
id: golang-lib-cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- name: Go bin Cache
id: golang-bin-cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-bin }}
key: ${{ runner.os }}-go-bin-v1-${{ hashFiles('*') }} # change v1 to invalidate cache when adding bin
# Cache go build cache, used to speedup go test
- name: Go Build Cache
id: golang-build-cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
- name: prepare golang-lib-cache
if: steps.golang-lib-cache.outputs.cache-hit != 'true'
run: |
git config --global url."https://${{ secrets.GITHUB_ACCESS_TOKEN }}:[email protected]".insteadOf "https://github.com"
go mod vendor
- name: prepare golang-bin-cache
if: steps.golang-bin-cache.outputs.cache-hit != 'true'
run: |
go install honnef.co/go/tools/cmd/staticcheck@${{ inputs.static_check_version }}
# staticcheck version v0.4.x doesn't work with go 1.17
# alternative is golangci-lint
# 💡 shows only a few annotations, if there are thousands
# - name: revive
# uses: docker://morphy/revive-action:v2
- name: static checker
if: ${{ inputs.run_static_check }}
run: |
staticcheck ./...
- name: make test
run: |
make test
- name: Stop containers
if: ${{ (failure() || success()) && inputs.test_docker_compose_path != '' }}
run: |
docker compose -f "${{ inputs.test_docker_compose_path }}" down