-
Notifications
You must be signed in to change notification settings - Fork 30
277 lines (254 loc) · 12.5 KB
/
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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
name: PR E2E C
env:
TRIVY_SCAN_SKIP_CHART_LIST: "nmstate cert-manager contour ingress-nginx"
IMAGE_HINT_FILE_NAME: ".relok8s-images.yaml"
SCHEMA_FILE_NAME: "values.schema.json"
on:
pull_request_target:
branches:
- main
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: check chart config
run : |
TMP=`ls charts`
for ITEM in $TMP ; do
[ ! -d "charts/${ITEM}" ] && continue
echo "check config for chart $ITEM "
[ ! -f "charts/${ITEM}/config" ] && echo "error, miss charts/${ITEM}/config " && exit 1
for VAR in DAOCLOUD_REPO_PROJECT UPGRADE_METHOD ; do
VAL=` source charts/${ITEM}/config && echo ${!VAR} `
[ -n "$VAL" ] || { echo "error, miss $VAR in charts/${ITEM}/config"; exit 1 ; }
done
UPGRADE_METHOD=` source charts/${ITEM}/config && echo $UPGRADE_METHOD `
if [ "$UPGRADE_METHOD" == "pr" ] || [ "$UPGRADE_METHOD" == "issue" ] ; then
for VAR in REPO_URL REPO_NAME CHART_NAME VERSION UPGRADE_REVIWER ; do
VAL=` source charts/${ITEM}/config && echo ${!VAR} `
[ -n "$VAL" ] || { echo "error, miss $VAR in charts/${ITEM}/config"; exit 1 ; }
done
elif [ "$UPGRADE_METHOD" == "none" ] ; then
echo ""
else
echo "error, UPGRADE_METHOD=$UPGRADE_METHOD must be 'pr'/'issue'/'none' in charts/${ITEM}/config"
exit 1
fi
done
exit 0
check_change:
runs-on: ubuntu-latest
outputs:
project: ${{ steps.check_change.outputs.test_project }}
pro_version_changed: ${{ env.PRO_CHANGED_VERSION }}
steps:
- name: "Setup go"
uses: actions/setup-go@v3
with:
go-version: '1.19'
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: check change
id: check_change
run: |
set -x
# Using the Github API to detect the files changed as git merge-base stops working when the branch is behind
# and jitterbit/get-changed-files does not support pull_request_target
URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files"
files_changed_data=$(curl -s --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -X GET -G "$URL")
echo "files_changed_data: $files_changed_data"
files_changed="$(echo $files_changed_data | jq -r '.[] | .filename')"
echo "files_changed: $files_changed"
#--------------------
# Adding || true to avoid "Process exited with code 1" errors
charts_changed="$(echo "$files_changed" | xargs dirname | grep -o "charts/[^/]*" | sort | uniq | awk -F'/' '{print $2}' | tr '\n' ' ' || true)"
echo "charts_changed: $charts_changed"
#--------------------
# issue: just release one project
PRO_CHANGED_VERSION=""
for PRO in ${charts_changed} ; do
if [ -d "charts/${PRO}" ] ; then
if grep "charts/${PRO}/${PRO}/Chart.yaml" <<< "${files_changed}" &>/dev/null ; then
PRO_CHANGED_VERSION="${PRO}"
break
fi
fi
done
echo "PRO_CHANGED_VERSION=${PRO_CHANGED_VERSION}"
echo "PRO_CHANGED_VERSION=${PRO_CHANGED_VERSION}" >> $GITHUB_ENV
#-------------------
# for project test script
additionall_test_project=""
project_test_dir_changed="$(echo "$files_changed" | xargs dirname | grep -o "test/[^/]*" | sort | uniq | awk -F'/' '{print $2}' || true)"
for PRO in ${project_test_dir_changed} ; do
if ! grep " ${PRO} " <<< " ${charts_changed} " &>/dev/null ; then
additionall_test_project+=" $PRO "
echo "test script changes for ${PRO} "
fi
done
#--------------------
# when other files changed
test_dir_changed="$(echo "$files_changed" | grep -o "test/[^/]*" | sort | uniq || true)"
if [ -n "$test_dir_changed" ] && [ -z "${additionall_test_project}" ] && [ -z "$charts_changed" ] ; then
# add spiderppool for testing test changes
charts_changed=` echo "$charts_changed spiderpool" | tr -s ' ' | tr ' ' '\n' | sort | uniq | tr '\n' ' ' || true`
echo "detect test changes, add spiderpool, charts_changed: $charts_changed"
fi
charts_changed=` echo $charts_changed `
RES=""
for PRO in ${charts_changed} ; do
if [ -d "charts/${PRO}" ] ; then
RES+="${PRO} "
fi
done
echo ::set-output name=changed_project::${RES}
ALL_PRO=" ${RES} ${additionall_test_project} "
echo ::set-output name=test_project::${ALL_PRO}
- name: check chart override
run: |
BASE=$PWD
cd cmd/chart-override-check
for PROJECT in ${{ steps.check_change.outputs.changed_project }} ; do
PROJECT_PATH=${BASE}/charts/${PROJECT}
go run main.go -path ${PROJECT_PATH}/${PROJECT} -skipCPath ${PROJECT_PATH}/skip-check.yaml
done
- name: check image hint file
run: |
BASE=$PWD
for PROJECT in ${{ steps.check_change.outputs.changed_project }} ; do
source ${BASE}/charts/${PROJECT}/config && [ "${NO_IMAGE}" == "true" ] && continue
CHART_PATH=${BASE}/charts/${PROJECT}/${PROJECT}
[ -f "${CHART_PATH}/${{ env.IMAGE_HINT_FILE_NAME }}" ] \
|| { echo "error, miss ${{ env.IMAGE_HINT_FILE_NAME }} file in chart ${PROJECT} " ; exit 1 ; }
! grep -E '\-[[:space:]]+[^"].*[^"]' ${CHART_PATH}/${{ env.IMAGE_HINT_FILE_NAME }} \
|| { echo "error, must use Double quotation in ${PROJECT}/.relok8s-images.yaml " ; exit 1 ; }
done
- name: check Chart yaml
run: |
BASE=$PWD
for PROJECT in ${{ steps.check_change.outputs.changed_project }} ; do
CHART_PATH=${BASE}/charts/${PROJECT}/${PROJECT}
if ! grep "keywords:" ${CHART_PATH}/Chart.yaml &>/dev/null ;then
echo "error, please input 'keywords' into the Chart.yaml of ${PROJECT} "
exit 1
fi
NAME=` yq '.name' ${CHART_PATH}/Chart.yaml `
echo "chart NAME '${NAME}' in project '${PROJECT}' "
[ "${NAME}" == "${PROJECT}" ] || { echo "error, chart name is not ${PROJECT}" ; exit 1 ; }
done
- name: check image repo
run: |
BASE=$PWD
for PROJECT in ${{ steps.check_change.outputs.changed_project }} ; do
source ${BASE}/charts/${PROJECT}/config && [ "${NO_IMAGE}" == "true" ] && continue
CHART_PATH=${BASE}/charts/${PROJECT}/${PROJECT}
if helm template test ${CHART_PATH} | grep ' image: ' | cut -d ":" -f2,3 | grep -v "daocloud" &>/dev/null ; then
echo "error, ${PROJECT} image is not in daocloud repo"
helm template test ${CHART_PATH} | grep ' image: ' | cut -d ":" -f2,3 | grep -v "daocloud"
exit 1
fi
done
- name: check resource limit
run: |
BASE=$PWD
for PROJECT in ${{ steps.check_change.outputs.changed_project }} ; do
CHART_PATH=${BASE}/charts/${PROJECT}/${PROJECT}
if helm template test ${CHART_PATH} | grep -E "kind: DaemonSet|kind: Deployment|kind: Job|kind: CronJob" &>/dev/null ; then
echo "check resource limit and request"
if ! ( helm template test ${CHART_PATH} | grep ' limits:' &>/dev/null ) ; then
echo "error, did not find resource limits settings in ${PROJECT}"
exit 1
fi
if ! ( helm template test ${CHART_PATH} | grep ' requests:' &>/dev/null ) ; then
echo "error, did not find resource requests settings in ${PROJECT}"
exit 1
fi
fi
done
- name: check schema file
run: |
BASE=$PWD
for PROJECT in ${{ steps.check_change.outputs.changed_project }} ; do
CHART_PATH=${BASE}/charts/${PROJECT}/${PROJECT}
# skip schema check
source ${BASE}/charts/${PROJECT}/config && [ "${SKIP_SCHEMA}" == "true" ] && echo "ignore schema check" && continue
[ -f "${CHART_PATH}/${{ env.SCHEMA_FILE_NAME }}" ] \
|| { echo "error, miss ${{ env.SCHEMA_FILE_NAME }} file in chart ${PROJECT} " ; exit 1 ; }
done
- name: check chart trivy
run: |
BASE=$PWD
for PROJECT in ${{ steps.check_change.outputs.changed_project }} ; do
# skip chart trivy
source ${BASE}/charts/${PROJECT}/config && [ "${NO_TRIVY}" == "true" ] && echo "ignore trivy" && continue
docker run --rm \
-v /tmp/trivy:/root/trivy.cache/ \
-v ${BASE}:/tmp/src \
aquasec/trivy:latest config --exit-code 1 --severity CRITICAL /tmp/src/charts/${PROJECT}/${PROJECT}
(( $? == 0 )) || { echo "error, failed to check chart trivy" && exit 1 ; }
echo "chart trivy check: pass charts/${PROJECT}/${PROJECT} "
done
- name: check upgrade
run: |
for PROJECT in ${{ steps.check_change.outputs.changed_project }} ; do
make build_chart -e PROJECT=${PROJECT} \
|| { echo "error, failed to call 'make build_chart' to update ${PROJECT} " ; exit 1 ; }
if ! git diff --exit-code --quiet ; then
git status
git diff
echo "error, after 'make build_chart', chart is not updated"
exit 1
fi
done
- name: run validate schema test
run: |
BASE=$PWD
python -m unittest ${BASE}/scripts/validate_schema_keys/test_validate.py -v || { echo "error, failed to run test script" ; exit 1 ; }
- name: validate schema for value
run: |
BASE=$PWD
for PROJECT in ${{ steps.check_change.outputs.changed_project }} ; do
CHART_PATH=charts/${PROJECT}/${PROJECT}
SCHEMA_FILE=${CHART_PATH}/${{ env.SCHEMA_FILE_NAME }}
PARENT_SCHEMA_FILE=charts/${PROJECT}/parent/${{ env.SCHEMA_FILE_NAME }}
[ -f ${PARENT_SCHEMA_FILE} ] && SCHEMA_FILE=${PARENT_SCHEMA_FILE}
python ${BASE}/scripts/validate_schema_keys/validate.py ${SCHEMA_FILE} ${CHART_PATH}/values.yaml
[ $? -eq 0 ] || { echo "error, failed to validate ${CHART_PATH}/values.yaml with ${SCHEMA_FILE}" ; exit 1 ; }
PROJECT_SRC_CONFIG_PATH=charts/${PROJECT}/config
source $PROJECT_SRC_CONFIG_PATH
if [ -n "${APPEND_VALUES_FILE}" ] && [ -s ${PROJECT_SRC_DIR}/${APPEND_VALUES_FILE} ] ; then
python ${BASE}/scripts/validate_schema_keys/validate.py ${SCHEMA_FILE} ${PROJECT_SRC_DIR}/${APPEND_VALUES_FILE}
[ $? -eq 0 ] || { echo "error, failed to validate ${PROJECT_SRC_DIR}/${APPEND_VALUES_FILE} with ${SCHEMA_FILE}" ; exit 1 ; }
fi
done
call_e2e:
uses: ./.github/workflows/call-e2e.yml
needs: [check_change]
if: ${{ needs.check_change.outputs.project != '' }}
with:
project: ${{ needs.check_change.outputs.project }}
ref: ${{ github.event.pull_request.head.sha }}
secrets: inherit
# nofity_version_changed:
# runs-on: ubuntu-latest
# needs: [ check_change ]
# if: ${{ needs.check_change.outputs.pro_version_changed != '' }}
# steps:
# - name: create an issue
# uses: dacbd/create-issue-action@main
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# repo: DaoCloud/DaoCloud-docs
# title: "project ${{ needs.check_change.outputs.pro_version_changed }} update to version "
# body: my new issue
#
# - name: Print outputs
# run: |
# echo ${{ steps.create-issue.outputs.id }}
# echo ${{ steps.create-issue.outputs.number }}