-
Notifications
You must be signed in to change notification settings - Fork 2
309 lines (281 loc) · 13.7 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
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
pull_request:
types: [opened, reopened, synchronize]
# reusable
workflow_call:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
CI:
runs-on: ubuntu-latest
steps:
- name: Get Repo Name
run: |
echo "REPO_NAME=$(basename ${{ github.repository }})" >> $GITHUB_ENV
- name: Set up Python 3.8
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Get Current Action URL
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_RUN_ID: ${{ github.run_id }}
GITHUB_SERVER_URL: ${{ github.server_url }}
run: |
echo "Current Action URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
echo "CURRENT_ACTION_URL=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV
- name: Parse PR Description for Dependencies
id: parse-dependencies
run: |
set -x
# 获取当前 PR 的描述
cat > pull_request.body.txt <<EOF
${{ github.event.pull_request.body }}
EOF
DEPENDS_ON=$(grep -oP 'depends-on:\K(.*)' pull_request.body.txt | sed 's/^ *//;s/ *$//')
echo "PR DEPENDS_ON: $DEPENDS_ON"
ALL_PR="$DEPENDS_ON ${{ github.repository }}:${{ github.event.pull_request.number }}"
manifest_part=$(echo "$ALL_PR" | grep -o 'open-vela/manifests[^ ]*') || true
if [ "$manifest_part"X != ""X ]; then
without_manifest_pr=$(echo "$ALL_PR" | sed "s|$manifest_part||" | xargs)
ALL_PR="$manifest_part $without_manifest_pr"
fi
echo "ALL_PR=$ALL_PR" >> $GITHUB_ENV
echo "DEPENDS_ON=$DEPENDS_ON" >> $GITHUB_ENV
for DEPENDENCY in $DEPENDS_ON; do
REPO_NAME=$(echo $DEPENDENCY | cut -d ':' -f 1)
PR_NUMBER=$(echo $DEPENDENCY | cut -d ':' -f 2)
PR_COMMITS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$REPO_NAME/pulls/$PR_NUMBER")
LATEST_SHA=$(echo "$PR_COMMITS" | jq -r '.head.sha')
if [[ -z "$LATEST_SHA" ]]; then
echo "No commits found for PR #$PR_NUMBER or invalid API response."
exit 1
fi
curl -X POST \
-H "Authorization: token ${{ secrets.CI_PAT_ROBOT }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$REPO_NAME/statuses/$LATEST_SHA \
-d '{
"state": "pending",
"description": "In progress",
"context": "CI triggered by ${{ github.repository }}#${{ github.event.pull_request.number }}",
"target_url": "${{ env.CURRENT_ACTION_URL }}"
}'
done
- name: Download and install repo
run: |
mkdir ~/bin
echo 'export PATH=~/bin:$PATH' >> $HOME/.bashrc
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
- name: Clean up disk space
run: |
sudo apt-get clean
sudo rm -rf /var/lib/apt/lists/*
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo rm -rf /etc/apt/sources.list.d/* /usr/local/lib/android /etc/mysql /etc/php /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force
sudo docker builder prune -a
sudo docker system prune -af
sudo -E apt-get -y purge azure-cli* docker* ghc* zulu* hhvm* llvm* firefox* google* dotnet* aspnetcore* powershell* openjdk* adoptopenjdk* mysql* php* mongodb* moby* snap* || true
sudo -E apt-get -qq update
sudo -E apt-get -qq install libfuse-dev $(curl -fsSL git.io/depends-ubuntu-2204)
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
df -h
- name: Verify repo installation
run: |
~/bin/repo --version
- name: Get PR source branch name
id: get_branch_name
run: |
PR_BRANCH=$(jq -r '.pull_request.head.ref' "$GITHUB_EVENT_PATH")
echo "branch_name=$PR_BRANCH" >> $GITHUB_OUTPUT
- name: Repo Init
run: |
~/bin/repo init -u https://github.com/open-vela/manifests -b ${{ github.event.pull_request.base.ref }} -m openvela.xml --depth=1 --git-lfs
echo "REPO_INIT=true" >> $GITHUB_ENV
- name: Repo Sync
run: |
df -h
~/bin/repo sync -c -d --no-tags -j12
df -h
- name: Fetch PR
if: ${{ github.event_name == 'pull_request' }}
run: |
current_path=$(pwd)
echo "REPO_ROOT=$current_path" >> $GITHUB_ENV
echo $(ls -atl)
git config --global user.email "[email protected]"
git config --global user.name "openvela-robot"
set -x
repo_sync_code=0
cp_code=0
cp_log=$current_path/cp.log
for DEPENDENCY in ${{ env.ALL_PR }}; do
REPO_FULL_PATH=$(echo $DEPENDENCY | cut -d ':' -f 1)
PR_NUMBER=$(echo $DEPENDENCY | cut -d ':' -f 2)
PROJECT_NAME=$(echo $REPO_FULL_PATH | cut -d '/' -f 2)
if [ $PROJECT_NAME == "manifests" ]; then
cd .repo/manifests
echo "git fetch origin pull/$PR_NUMBER/head:pr-branch"
git fetch origin pull/$PR_NUMBER/head:pr-branch
echo "git cherry-pick $(git rev-list --reverse HEAD..pr-branch)"
set +e
cp_pr_result=$(git cherry-pick $(git rev-list --reverse HEAD..pr-branch) >> $cp_log 2>&1)
cp_pr_code=$?
if [ $cp_pr_code -ne 0 ]; then
cp_code=1
fi
echo $cp_pr_result
cd -
~/bin/repo sync -c -d --no-tags -j12
if [ $? -ne 0 ]; then
repo_sync_code=1
fi
else
manifest_content=$(cat .repo/manifests/openvela.xml)
echo $manifest_content
REPO_PATH=$(cat .repo/manifests/openvela.xml | grep "\"$PROJECT_NAME\"" | awk -F'"' '{print $2}')
echo $REPO_PATH
cd $REPO_PATH
echo "git fetch openvela pull/$PR_NUMBER/head:pr-branch"
git fetch openvela pull/$PR_NUMBER/head:pr-branch
echo "git cherry-pick $(git rev-list --reverse HEAD..pr-branch)"
set +e
cp_pr_result=$(git cherry-pick $(git rev-list --reverse HEAD..pr-branch) >> $cp_log 2>&1)
cp_pr_code=$?
if [ $cp_pr_code -ne 0 ]; then
cp_code=1
fi
echo $cp_pr_result
cd -
fi
done
echo "REPO_SYNC_CODE=$repo_sync_code" >> $GITHUB_ENV
echo "CP_PR_CODE=$cp_code" >> $GITHUB_ENV
continue-on-error: true
- name: check cherry-pick pr result
run: |
if [ -n "${{ env.REPO_SYNC_CODE }}" ] && [ ${{ env.REPO_SYNC_CODE }} != 0 ]; then
echo "repo sync after cherry-pick manifest PR failed."
exit 1
else
echo "repo sync after cherry-pick manifest PR success."
fi
if [ ${{ env.CP_PR_CODE }} == 0 ]; then
echo "cherry-pick PR success and continue."
else
cat ${{ env.REPO_ROOT }}/cp.log | grep "is a merge"
if [ $? -eq 0 ]; then
echo "There's merge commit in your PR. Please use rebase insteadof merge."
exit 1
else
echo "cherry-pick PR failed with error message: ${{ env.CP_PR_RESULT }}"
exit 1
fi
fi
- name: Docker Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Pull
run: docker pull ghcr.io/open-vela/openvela-ci-linux
- name: Run CI tasks inside Docker container
run: |
docker run --rm \
-v ${{ github.workspace }}:/workspace \
-w /workspace \
ghcr.io/open-vela/openvela-ci-linux:latest \
/bin/bash -c "ls -atl && ./build.sh vendor/openvela/boards/vela/configs/goldfish-armeabi-v7a-ap -e -Werror -j8"
- name: Upload goldfish-armeabi-v7a-ap Artifact
uses: actions/upload-artifact@v3
with:
name: goldfish-armeabi-v7a-ap_${{ env.REPO_NAME }}-${{ github.event.pull_request.number }}
path: nuttx/nuttx
- name: Clean
run: |
echo 'export PATH=~/bin:$PATH' >> $HOME/.bashrc
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
sudo ~/bin/repo forall -v -c git clean -dfx; git reset --hard HEAD
continue-on-error: true
- name: Run test build inside Docker container
run: |
docker run --rm \
-v ${{ github.workspace }}:/workspace \
-w /workspace \
ghcr.io/open-vela/openvela-ci-linux:latest \
/bin/bash -c "./build.sh vendor/openvela/boards/vela/configs/goldfish-armeabi-v7a-ap-citest -e -Werror -j8"
- name: Run autotest tasks inside Docker container
run: |
docker run --rm \
-v ${{ github.workspace }}:/workspace \
-w /workspace \
ghcr.io/open-vela/openvela-ci-linux:latest \
/bin/bash -c "cd tests/scripts/script && pytest -m 'common or goldfish_armeabi_v7a_ap' ./ -B goldfish-armeabi-v7a-ap -L /workspace -P /workspace -F /tmp -R qemu -v --disable-warnings --count=1 --json=/workspace/autotest.json"
- name: Check autotest result
id: autotest_result
run: |
cd ${{ github.workspace }}
mkdir output
cp nuttx/nuttx ./*.log ./autotest.json output
failed=$(cat autotest.json | jq '.report.summary.failed')
if [ "$failed" != "null" ] && [ "$failed" != "0" ]; then
echo "autotest failed: $failed"
result="failed"
else
echo "autotest passed"
result="success"
fi
echo "::set-output name=AUTOTEST_RESULT::${result}"
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: goldfish-armeabi-v7a-ap-citest_${{ env.REPO_NAME }}-${{ github.event.pull_request.number }}
path: output/
- name: Exit with autotest exit code
run: |
if [ ${{ steps.autotest_result.outputs.AUTOTEST_RESULT }} == "success" ]; then
exit 0;
else
exit 1;
fi
- name: Post Processing
if: always() # 确保无论之前的步骤成功或失败,都会执行
run: |
echo "Job status: ${{ job.status }}"
if [[ "${{ job.status }}" == "success" ]]; then
ci_status="success"
else
ci_status="failure"
fi
for DEPENDENCY in ${{ env.DEPENDS_ON }}; do
REPO_NAME=$(echo $DEPENDENCY | cut -d ':' -f 1)
PR_NUMBER=$(echo $DEPENDENCY | cut -d ':' -f 2)
PR_COMMITS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$REPO_NAME/pulls/$PR_NUMBER")
LATEST_SHA=$(echo "$PR_COMMITS" | jq -r '.head.sha')
if [[ -z "$LATEST_SHA" ]]; then
echo "No commits found for PR #$PR_NUMBER or invalid API response."
exit 1
fi
set -x
curl -X POST \
-H "Authorization: token ${{ secrets.CI_PAT_ROBOT }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$REPO_NAME/statuses/$LATEST_SHA \
-d '{
"state": '"\"$ci_status\""',
"description": "CI '"$ci_status"'",
"context": "CI triggered by ${{ github.repository }}#${{ github.event.pull_request.number }}",
"target_url": "${{ env.CURRENT_ACTION_URL }}"
}'
set +x
done