-
Notifications
You must be signed in to change notification settings - Fork 42
214 lines (188 loc) · 6.97 KB
/
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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: Code testing
on:
push:
branches:
- master
tags:
- "v*"
pull_request:
types:
- opened
- reopened
- synchronize
jobs:
configure:
name: Preliminary configuration
runs-on: ubuntu-latest
outputs:
ref: ${{ steps.configure.outputs.ref }}
repo-name: ${{ steps.configure.outputs.repo-name }}
version: ${{ steps.version.outputs.version }}
steps:
- name: Get version
id: version
run: echo "version=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
if: |
github.event_name == 'push' &&
github.event.repository.full_name == github.repository &&
startsWith(github.ref, 'refs/tags/v')
- name: Configure
id: configure
run: |
# The ref of the commit to checkout (do not use the merge commit if pull request)
if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
echo "ref=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
echo "repo-name=${{ github.event.pull_request.head.repo.full_name }}" >> $GITHUB_OUTPUT
elif [[ "${{ steps.version.outputs.version }}" != "" ]]; then
echo "ref=${{ steps.version.outputs.version }}" >> $GITHUB_OUTPUT
echo "repo-name=${{ github.repository }}" >> $GITHUB_OUTPUT
else
echo "ref=${{ github.sha }}" >> $GITHUB_OUTPUT
echo "repo-name=${{ github.repository }}" >> $GITHUB_OUTPUT
fi
operators:
name: Operators
runs-on: ubuntu-latest
needs: configure
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: "${{ needs.configure.outputs.ref }}"
repository: "${{ needs.configure.outputs.repo-name }}"
persist-credentials: false
- name: Check if /operators files changed
uses: dorny/paths-filter@v2
id: pathFilter
with:
filters: |
operators:
- 'operators/**'
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install Kubebuilder
run: |
version=2.3.1 # latest stable version
kubernetes_version=1.25.0
curl -L -O "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${version}/kubebuilder_${version}_linux_$(go env GOARCH).tar.gz"
tar -zxvf kubebuilder_${version}_linux_$(go env GOARCH).tar.gz
mv kubebuilder_${version}_linux_$(go env GOARCH) kubebuilder
curl --fail -sSLo envtest-bins.tar.gz "https://go.kubebuilder.io/test-tools/${kubernetes_version}/$(go env GOOS)/$(go env GOARCH)"
tar -zxvf envtest-bins.tar.gz kubebuilder/bin/kube-apiserver --overwrite -C kubebuilder/bin
sudo mv kubebuilder /usr/local/
- name: Perform the tests
working-directory: operators/
run: |
make test
make test-python
- name: Send coverage
if: steps.pathFilter.outputs.operators == 'true'
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out
working-directory: operators/
operators-generated:
name: Operators (Generated manifests)
runs-on: ubuntu-latest
needs: configure
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: "${{ needs.configure.outputs.ref }}"
repository: "${{ needs.configure.outputs.repo-name }}"
persist-credentials: false
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Run the automatic generation
working-directory: operators/
run: |
make generate
make manifests
- name: Gather the differences
id: git-diff
run: |
# Ensure new files are also considered in the diff
git add --intent-to-add .
output=$(git diff | head -n 100)
exit_code=$([ "${output}" ] && echo 1 || echo 0)
# Required to correctly manage multi-line outputs
output="${output//'%'/'%25'}"
output="${output//$'\n'/'%0A'}"
output="${output//$'\r'/'%0D'}"
echo "diff=${output}" >> $GITHUB_OUTPUT
# Trigger a failure in case the diff is not empty
exit ${exit_code}
- name: Log the error if the diff is not empty (in case the comment cannot be generated)
run: |
echo "The generated artifacts appear to be out-of-date."
echo
echo "Here it is an excerpt of the diff:"
echo "${{ steps.git-diff.outputs.diff }}"
if: failure()
- name: Issue a comment in case the diff is not empty
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.CI_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
The generated files in the `operators/` folder appear to be out-of-date.
Please, ensure you are using the correct version of `controller-gen` and re-run:
```
make generate
make manifests
```
<details>
<summary>Here it is an excerpt of the diff:</summary>
```diff
${{ steps.git-diff.outputs.diff }}
```
</details>
reactions: confused
if: |
github.event_name != 'push' && failure() &&
github.event.pull_request.head.repo.full_name == github.repository
kubernetes-manifests:
name: Kubernetes manifests
runs-on: ubuntu-latest
needs: configure
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: "${{ needs.configure.outputs.ref }}"
repository: "${{ needs.configure.outputs.repo-name }}"
persist-credentials: false
- name: Update the Helm chart dependencies
uses: WyriHaximus/github-action-helm3@v2
with:
exec:
helm dependency update ./deploy/crownlabs
- name: Verify that the helm chart is well-formed
uses: WyriHaximus/github-action-helm3@v2
with:
exec:
helm lint ./deploy/crownlabs --with-subcharts
- name: Render the yaml manifests
id: helm-template
uses: WyriHaximus/github-action-helm3@v2
with:
exec:
helm template crownlabs ./deploy/crownlabs
--namespace crownlabs-production
--set global.version=v0.0.1
- name: Save the rendered manifests
run: |
echo '${{ steps.helm-template.outputs.helm_output }}' > ./deploy/crownlabs/rendered.yaml
- name: KubeScore Check
run: |
docker run -v ${{ github.workspace }}:/CrownLabs zegl/kube-score:v1.11.0 score \
--ignore-test=pod-networkpolicy,container-security-context,container-image-pull-policy \
/CrownLabs/deploy/crownlabs/rendered.yaml