-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (62 loc) · 2.2 KB
/
validate-code.yaml
File metadata and controls
66 lines (62 loc) · 2.2 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
name: 'Validate the code'
on:
push:
branches-ignore:
- 'master'
jobs:
validateCode:
runs-on: 'ubuntu-24.04'
permissions:
contents: 'read'
steps:
- name: 'checkout code'
uses: 'actions/checkout@v5.0.0'
with:
fetch-depth: 0
- name: 'populate env vars'
shell: 'bash'
run: |
#!/usr/bin/env bash
set -euo pipefail
GIT_COMMIT="$(git rev-parse HEAD)"
GIT_TAG="$(git name-rev --tags --name-only ${GIT_COMMIT})"
BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
LDFLAGS="-X 'github.com/sapcc/concourse-netbox-resource/internal/helper.gitCommit=${GIT_COMMIT}' -X 'github.com/sapcc/concourse-netbox-resource/internal/helper.buildDate=${BUILD_DATE}' -X 'github.com/sapcc/concourse-netbox-resource/internal/helper.gitVersion=${GIT_TAG}'"
GO_VERSION="$(go list -f {{.GoVersion}} -m)"
echo "GIT_COMMIT=${GIT_COMMIT}" >> "$GITHUB_ENV"
echo "GIT_TAG=${GIT_TAG}" >> "$GITHUB_ENV"
echo "BUILD_DATE=${BUILD_DATE}" >> "$GITHUB_ENV"
echo "LDFLAGS=${LDFLAGS}" >> "$GITHUB_ENV"
echo "GO_VERSION=${GO_VERSION}" >> "$GITHUB_ENV"
- name: 'setup go'
uses: 'actions/setup-go@v6.0.0'
with:
go-version: "${{ env.GO_VERSION }}"
- name: 'golangci-lint'
uses: 'golangci/golangci-lint-action@v8.0.0'
with:
version: 'v2.4.0'
- name: 'govulncheck'
shell: 'bash'
run: |
#!/usr/bin/env bash
set -euo pipefail
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck -format text -show verbose ./...
- name: 'go test'
shell: 'bash'
run: 'go test -ldflags "${LDFLAGS}" -cover ./...'
- name: 'go build'
shell: 'bash'
run: |
#!/usr/bin/env bash
set -euo pipefail
go build -ldflags "${LDFLAGS}" -o check main.go
- name: 'validate version'
shell: 'bash'
run: |
#!/usr/bin/env bash
set -euo pipefail
./check -v | grep -q "${GIT_TAG}"
./check -c in -v | grep -q "${GIT_TAG}"
./check -c out -v | grep -q "${GIT_TAG}"