-
Notifications
You must be signed in to change notification settings - Fork 0
91 lines (91 loc) · 2.66 KB
/
go-ci.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Continuous Integration
on:
workflow_call:
inputs:
submodules:
required: false
type: boolean
default: false
working-directory:
required: false
type: string
default: '.'
make:
required: false
type: boolean
default: true
go-version:
required: false
type: string
default: ''
govulncheck-ignore-error:
required: false
type: boolean
default: false
govulncheck-go:
required: false
type: string
default: 'go'
secrets:
CI_ACCESS_TOKEN:
required: false
SLACK_FAILURE_WEBHOOK_URL:
required: false
jobs:
go-ci:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.working-directory }}
env:
HAS_SLACK_FAILURE_WEBHOOK_URL: ${{ secrets.SLACK_FAILURE_WEBHOOK_URL != '' }}
steps:
- run: env
working-directory: .
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: ${{ inputs.submodules }}
token: ${{ secrets.CI_ACCESS_TOKEN || github.token }}
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
go-version-file: |
${{
inputs.go-version == '' &&
format('{0}/go.mod', inputs.working-directory) ||
''
}}
cache-dependency-path: ${{ inputs.working-directory }}/go.sum
- name: Run build
run: ${{ inputs.make && 'make all' || 'go build ./...' }}
- name: Run govulncheck
run: |
if [[ ${{ inputs.govulncheck-go }} != 'go' ]]; then
go install golang.org/dl/${{ inputs.govulncheck-go }}@latest
${{ inputs.govulncheck-go }} download
fi
${{ inputs.govulncheck-go }} install golang.org/x/vuln/cmd/govulncheck@latest
if [[ ${{ inputs.govulncheck-ignore-error }} == 'true' ]]; then
govulncheck ./... || true
else
govulncheck ./...
fi
- name: Run test
run: ${{ inputs.make && 'make test' || 'go test -v -race ./...' }}
- name: Run lint
uses: golangci/golangci-lint-action@v6
with:
working-directory: ${{ inputs.working-directory }}
version: latest
- name: Send to Slack
if: ${{ failure() && env.HAS_SLACK_FAILURE_WEBHOOK_URL == 'true' }}
uses: slackapi/slack-github-action@v1.27.0
with:
payload: |
{
"run_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_FAILURE_WEBHOOK_URL }}