-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rewind-commit.sh
executable file
·147 lines (128 loc) · 5.35 KB
/
rewind-commit.sh
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
#!/usr/bin/env bash
## Rewind the NuttX Build for One Single Commit.
## Read the article: https://lupyuen.github.io/articles/ci6
## sudo ./rewind-commit.sh ox64:nsh 7f84a64109f94787d92c2f44465e43fde6f3d28f d6edbd0cec72cb44ceb9d0f5b932cbd7a2b96288 2024-11-24T00:00:00 7f84a64109f94787d92c2f44465e43fde6f3d28f 7f84a64109f94787d92c2f44465e43fde6f3d28f
## sudo ./rewind-commit.sh rv-virt:citest 656883fec5561ca91502a26bf018473ca0229aa4 3c4ddd2802a189fccc802230ab946d50a97cb93c
## Given a NuttX Target (ox64:nsh):
## Build the Target for the Commit
## If it fails: Rebuild with Previous Commit and Next Commit
echo Now running https://github.com/lupyuen/nuttx-build-farm/blob/main/rewind-commit.sh $1 $2 $3 $4 $5 $6
echo Called by https://github.com/lupyuen/nuttx-build-farm/blob/main/rewind-build.sh
set -e ## Exit when any command fails
set -x ## Echo commands
## First Parameter is Target, like "ox64:nsh"
target=$1
if [[ "$target" == "" ]]; then
echo "ERROR: Target is missing (e.g. ox64:nsh)"
exit 1
fi
## Second Parameter is the Commit Hash of NuttX Repo, like "7f84a64109f94787d92c2f44465e43fde6f3d28f"
nuttx_hash=$2
if [[ "$nuttx_hash" == "" ]]; then
echo "ERROR: NuttX Hash is missing (e.g. 7f84a64109f94787d92c2f44465e43fde6f3d28f)"
exit 1
fi
## Third Parameter is the Commit Hash of NuttX Apps Repo, like "d6edbd0cec72cb44ceb9d0f5b932cbd7a2b96288"
apps_hash=$3
if [[ "$apps_hash" == "" ]]; then
echo "ERROR: NuttX Apps Hash is missing (e.g. d6edbd0cec72cb44ceb9d0f5b932cbd7a2b96288)"
exit 1
fi
## (Optional) Fourth Parameter is the Timestamp of the NuttX Commit, like "2024-11-24T00:00:00"
timestamp=$4
if [[ "$timestamp" == "" ]]; then
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%S")
fi
## (Optional) Fifth Parameter is the Previous Commit Hash of NuttX Repo, like "7f84a64109f94787d92c2f44465e43fde6f3d28f"
prev_hash=$5
if [[ "$prev_hash" == "" ]]; then
prev_hash=$nuttx_hash
fi
## (Optional) Sixth Parameter is the Next Commit Hash of NuttX Repo, like "7f84a64109f94787d92c2f44465e43fde6f3d28f"
next_hash=$6
if [[ "$next_hash" == "" ]]; then
next_hash=$nuttx_hash
fi
## Show the System Info
set | grep TMUX || true
neofetch
## Download the Docker Image
sudo docker pull \
ghcr.io/apache/nuttx/apache-nuttx-ci-linux:latest
## Build NuttX in Docker Container
## If CI Test Hangs: Kill it after 1 hour
## We follow the CI Log Format, so that ingest-nuttx-builds will
## ingest our log into NuttX Dashboard and appear in NuttX Build History
## https://github.com/lupyuen/ingest-nuttx-builds/blob/main/src/main.rs
## ====================================================================================
## Configuration/Tool: adafruit-kb2040/nshsram,
## 2024-11-25 03:25:20
## ------------------------------------------------------------------------------------
function build_nuttx {
local nuttx_commit=$1
local apps_commit=$2
local target_slash=$(echo $target | tr ':' '/')
local timestamp_space=$(echo $timestamp | tr 'T' ' ')
set +x ## Disable Echo
echo "===================================================================================="
echo "Configuration/Tool: $target_slash,"
echo "$timestamp_space"
echo "------------------------------------------------------------------------------------"
set -x ## Enable Echo
set +e ## Ignore errors
sudo docker run -it \
ghcr.io/apache/nuttx/apache-nuttx-ci-linux:latest \
/bin/bash -c "
set -e ;
set -x ;
uname -a ;
cd ;
pwd ;
git clone https://github.com/apache/nuttx ;
git clone https://github.com/apache/nuttx-apps apps ;
echo Building nuttx @ $nuttx_commit / nuttx-apps @ $apps_commit ;
pushd nuttx ; git reset --hard $nuttx_commit ; popd ;
pushd apps ; git reset --hard $apps_commit ; popd ;
pushd nuttx ; echo NuttX Source: https://github.com/apache/nuttx/tree/\$(git rev-parse HEAD) ; popd ;
pushd apps ; echo NuttX Apps: https://github.com/apache/nuttx-apps/tree/\$(git rev-parse HEAD) ; popd ;
cd nuttx ;
( sleep 3600 ; echo Killing pytest after timeout... ; pkill -f pytest )&
(
(./tools/configure.sh $target && make -j) || (res=\$? ; echo '***** BUILD FAILED' ; exit \$res)
)
"
res=$?
set -e ## Exit when any command fails
set +x ## Disable Echo
echo res=$res
echo "===================================================================================="
set -x ## Enable Echo
}
## Build the Target for the Commit
echo "Building This Commit: nuttx @ $nuttx_hash / nuttx-apps @ $apps_hash"
build_nuttx $nuttx_hash $apps_hash
echo res=$res
## If it fails: Rebuild with Previous Commit and Next Commit
if [[ "$res" != "0" ]]; then
echo "***** BUILD FAILED FOR THIS COMMIT: nuttx @ $nuttx_hash / nuttx-apps @ $apps_hash"
if [[ "$prev_hash" != "$nuttx_hash" ]]; then
echo "Building Previous Commit: nuttx @ $prev_hash / nuttx-apps @ $apps_hash"
res=
build_nuttx $prev_hash $apps_hash
echo res=$res
if [[ "$res" != "0" ]]; then
echo "***** BUILD FAILED FOR PREVIOUS COMMIT: nuttx @ $prev_hash / nuttx-apps @ $apps_hash"
fi
fi
if [[ "$next_hash" != "$nuttx_hash" ]]; then
echo "Building Next Commit: nuttx @ $next_hash / nuttx-apps @ $apps_hash"
res=
build_nuttx $next_hash $apps_hash
echo res=$res
if [[ "$res" != "0" ]]; then
echo "***** BUILD FAILED FOR NEXT COMMIT: nuttx @ $next_hash / nuttx-apps @ $apps_hash"
fi
fi
fi
## Monitor the Disk Space (in case Docker takes too much)
df -H