-
Notifications
You must be signed in to change notification settings - Fork 9
187 lines (161 loc) · 6.15 KB
/
ci.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: Continuous Integration
on:
workflow_dispatch:
schedule:
- cron: '0 12 * * *'
push:
branches:
- 'main'
- 'renovate/**'
tags:
- 'v*.*.*'
pull_request:
branches:
- 'main'
permissions:
contents: read
jobs:
golangci-lint:
name: Lint Go files
runs-on: ubuntu-latest
steps:
- name: Checkout GitHub Repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: '0'
- name: Set up Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: './go.mod'
- name: Run golangci-lint
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1
with:
version: latest
args: --config=./.github/.golangci.yml
# Skip cache because of flaky behavior:
# https://github.com/golangci/golangci-lint/blob/master/.github/workflows/pr.yml#L49
skip-cache: true
skip-save-cache: true
lint-charts:
name: Lint Helm charts
runs-on: ubuntu-latest
steps:
- name: Checkout GitHub Repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/[email protected]
with:
version: v3.14.4
- name: Set up helm-unittest
run: helm plugin install https://github.com/helm-unittest/helm-unittest
- name: Set up chart-testing
uses: helm/[email protected]
- name: Lint charts
run: ct --config .github/ct.yaml lint --debug
- name: Run unit tests
run: |
for chart in $(ct list-changed --config .github/ct-lint.yaml); do
if [ -d "$chart/tests/" ]; then
helm unittest $chart
else
echo "No unit tests found for $chart"
fi
done
- name: Install Helm Docs
# Use syntax ${version} instead of $version
# In certain contexts, only the less ambiguous ${version} form works
# Source: https://tldp.org/LDP/abs/html/parameter-substitution.html
run: |
version="v1.14.2"
stripped=$( echo "${version}" | sed s'/v//' )
wget https://github.com/norwoodj/helm-docs/releases/download/${version}/helm-docs_${stripped}_Linux_x86_64.tar.gz
tar --extract --verbose --file="helm-docs_${stripped}_Linux_x86_64.tar.gz" helm-docs
sudo mv helm-docs /usr/local/sbin
- name: Verify Helm docs are up to date
run: |
helm-docs
git diff --exit-code -- charts/k8s-agents-operator/README.md
unit-tests:
name: Unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout GitHub Repository
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: Set up Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: './go.mod'
- name: Set up tests
run: |
make clean
make format
make modules
- name: Run unit tests for Go
run: |
make test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: ./tmp/cover.out
e2e-tests:
name: E2E tests
runs-on: ubuntu-latest
strategy:
max-parallel: 6 # len(k8sVersion)/2 is a good number to have here
matrix:
# Latest patch version can be found in https://github.com/kubernetes/website/blob/main/content/en/releases/patch-releases.md
# Some versions might not be available yet in https://storage.googleapis.com/kubernetes-release/release/v1.X.Y/bin/linux/amd64/kubelet
k8sVersion: [ "v1.31.1", "v1.30.5", "v1.29.9", "v1.28.14", "v1.27.16", "v1.26.15" ]
steps:
- name: Checkout GitHub Repository
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: Download minikube
run: |
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64
- name: Run E2E tests
run: |
cd tests/e2e
./e2e-tests.sh --k8s_version ${{ matrix.k8sVersion }} --license_key ${{ secrets.K8S_AGENTS_E2E_LICENSE_KEY }} --run_tests
build:
name: Build Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout GitHub Repository
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Docker metadata
id: metadata
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: |
newrelic/k8s-agents-operator
tags: |
# reflects the last commit of the active branch
type=edge
# nightly tag
type=schedule
# push tag event
type=semver,pattern={{version}}
# push tag event
type=semver,pattern={{major}}.{{minor}}
- name: Login to Docker Hub
if: github.event_name != 'pull_request' && !startsWith(github.ref, 'refs/heads/renovate')
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
username: ${{ secrets.K8S_AGENTS_DOCKERHUB_USERNAME }}
password: ${{ secrets.K8S_AGENTS_DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
- name: Build and push
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' && !startsWith(github.ref, 'refs/heads/renovate') }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}