-
Notifications
You must be signed in to change notification settings - Fork 2
125 lines (117 loc) · 5.11 KB
/
auto-pr-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
name: PR E2E C
on:
pull_request_target:
branches:
- main
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
check_change:
runs-on: ubuntu-latest
outputs:
project: ${{ env.test_project }}
changed_project: ${{ env.changed_project }}
steps:
- name: "Setup go"
uses: actions/setup-go@v3
with:
go-version: '1.22'
- 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 "./[^/]*" | 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 "${PRO}/chart/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 charts 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 "${PRO}" ] ; then
RES+="${PRO} "
fi
done
echo "changed_project=${RES}" >> $GITHUB_ENV
ALL_PRO=" ${RES} ${additionall_test_project} "
echo "test_project=${ALL_PRO}" >> $GITHUB_ENV
- name: check Chart yaml
run: |
BASE=$PWD
for PROJECT in ${{ env.changed_project }} ; do
CHART_PATH=${BASE}/${PROJECT}/chart
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 resource
run: |
BASE=$PWD
for PROJECT in ${{ env.changed_project }} ; do
CHART_PATH=${BASE}/${PROJECT}/chart
if helm template test ${CHART_PATH} | grep -E "kind: DaemonSet|kind: Deployment|kind: Job|kind: CronJob" &>/dev/null ; then
echo "check resource request"
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
call_e2e:
uses: ./.github/workflows/call-e2e.yaml
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