-
Notifications
You must be signed in to change notification settings - Fork 594
115 lines (113 loc) · 3.38 KB
/
verify-go.yml
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
113
114
115
name: Go
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
unit:
runs-on: ubuntu-latest
steps:
- uses: styfle/[email protected]
- uses: actions/setup-go@v5
with:
go-version: '1.22.4'
- name: Cache Golang Packages
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-golang-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-golang-
- name: checkout
uses: actions/checkout@v4
- name: unit-test
id: unit-test
run: go test -tags=unit ./... -coverprofile cover.out
# run code coverage upload to code climate on main branch since PR branch will not have access to secret
- name: unit-test-code-climate-upload
if: ${{ (github.event_name != 'pull_request') || (github.event.pull_request.head.repo.full_name == github.repository) }}
uses: paambaati/codeclimate-action@v5
env:
CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE_REPORTER_ID }}
with:
coverageLocations: cover.out:gocov
# truncate package name from file paths in report
prefix: github.com/SAP/jenkins-library/
format:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.22.4'
- name: Cache Golang Packages
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-golang-format${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-golang-format
${{ runner.os }}-golang-
- name: checkout
uses: actions/checkout@v4
- name: format
run: go fmt ./...
- name: verify
run: git diff --exit-code
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.22.4'
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: staticcheck
uses: dominikh/[email protected]
with:
cache-key: ${{ runner.os }}-golang-staticcheck
install-go: false
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.22.4'
- name: Cache Golang Packages
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-golang-generate${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-golang-generate
${{ runner.os }}-golang-
- name: checkout
uses: actions/checkout@v4
- name: generate
run: go run pkg/generator/step-metadata.go
- name: verify
run: git diff --exit-code
dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.22.4'
- name: Cache Golang Packages
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-golang-dependencies${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-golang-dependencies
${{ runner.os }}-golang-
- name: checkout
uses: actions/checkout@v4
- name: cleanup dependencies
run: go mod tidy
- name: verify
run: git diff --name-only --exit-code