-
Notifications
You must be signed in to change notification settings - Fork 42
147 lines (122 loc) · 3.88 KB
/
unit-test.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: UnitTests
on:
pull_request:
branches:
- main
- "[0-9]+.[0-9]+"
types: [opened, synchronize, reopened]
push:
branches:
- main
env:
K8S_MANIFEST_DIR: deploy
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
unit_tests:
name: Unit Tests
runs-on: ubuntu-20.04
timeout-minutes: 40
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up GO (with caching)
uses: magnetikonline/action-golang-cache@v4
with:
go-version-file: .go-version
- name: Mage build bundle before unit tests
uses: magefile/mage-action@v3
with:
args: buildOpaBundle
- name: Copy bundle to required dirs
run: |
cp bundle.tar.gz evaluator/
- name: Unit-Test
run: |
go install gotest.tools/gotestsum
GOOS=linux TEST_DIRECTORY=./... gotestsum --format pkgname -- -race -coverpkg=./... -coverprofile=cover.out.tmp
cat cover.out.tmp | grep -v "mock_.*.go" > cover.out # remove mock files from coverage report
- name: Upload coverage artifact
uses: actions/upload-artifact@v3
with:
name: coverage-file
path: cover.out
coverage:
name: Coverage report
needs: unit_tests
runs-on: ubuntu-20.04
timeout-minutes: 10
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Init Hermit
run: ./bin/hermit env -r >> $GITHUB_ENV
- name: Install goveralls
run: go install github.com/mattn/goveralls@latest
- name: Download coverage artifact
uses: actions/download-artifact@v3
with:
name: coverage-file
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=cover.out -service=github
manifest_tests:
name: Manifest Tests
runs-on: ubuntu-20.04
timeout-minutes: 15
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Get diff k8s manifests
uses: technote-space/get-diff-action@v6
with:
PATTERNS: ${{ env.K8S_MANIFEST_DIR }}/**
- name: Run K8s manifest tests
if: env.GIT_DIFF
uses: stefanprodan/kube-tools@v1
with:
kubectl: 1.18.4
kubeval: v0.16.1
command: |
kubeval --strict -d ${{ env.K8S_MANIFEST_DIR }} --ignore-missing-schemas --ignored-filename-patterns kustomization,kind,patch,cloudbeat,cloudformation,deployment-manager --skip-kinds ClusterConfig
golangci:
name: golangci-lint
runs-on: ubuntu-20.04
timeout-minutes: 15
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ (github.event.pull_request_target || github.event.pull_request).head.repo.full_name }}
ref: ${{ (github.event.pull_request_target || github.event.pull_request).head.sha }}
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: .go-version
cache: false
- name: Go linter
uses: golangci/[email protected]
with:
version: latest
args: --whole-files --verbose
dependency-review:
runs-on: ubuntu-20.04
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Dependency Review
uses: actions/dependency-review-action@v3
terraform-linter:
name: terraform-lint
runs-on: ubuntu-20.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Init Hermit
run: ./bin/hermit env -r >> $GITHUB_ENV
- name: Terraform fmt
run: terraform fmt -check -recursive