Skip to content

Commit 45e02cb

Browse files
updated action-runner script
1 parent 94cad81 commit 45e02cb

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

.github/scripts/ppc64le/self-hosted-builder/fs/usr/bin/actions-runner

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,45 @@
22

33
set -e -u
44

5+
trap cleanup EXIT
6+
7+
token_file=registration-token.json
8+
9+
# Function to clean up and unregister the runner
10+
cleanup() {
11+
echo "Cleaning up temporary files..."
12+
[ -f "$token_file" ] && rm -f "$token_file"
13+
[ -f "runner-id.json" ] && rm -f "runner-id.json"
14+
15+
echo "Unregistering the runner from GitHub..."
16+
ACCESS_TOKEN="$(cat /run/runner_secret)"
17+
runner_id=$(curl -s \
18+
-H "Accept: application/vnd.github.v3+json" \
19+
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
20+
"https://api.github.com/repos/${OWNER}/${REPO}/actions/runners" | \
21+
jq --raw-output '.runners[] | select(.name=="'"${NAME}"'") | .id')
22+
23+
if [ -n "$runner_id" ]; then
24+
curl -s \
25+
-X DELETE \
26+
-H "Accept: application/vnd.github.v3+json" \
27+
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
28+
"https://api.github.com/repos/${OWNER}/${REPO}/actions/runners/$runner_id"
29+
echo "Runner unregistered successfully."
30+
else
31+
echo "Warning: Runner ID for ${NAME} not found. It may already be removed."
32+
fi
33+
34+
unset ACCESS_TOKEN runner_id
35+
}
36+
537
# Fetch GitHub access token
638
if [ ! -f /run/runner_secret ]; then
739
echo "Error: Access token file not found at /run/runner_secret."
840
exit 1
941
fi
1042

11-
token_file=registration-token.json
43+
1244

1345
ACCESS_TOKEN="$(cat /run/runner_secret)"
1446

@@ -37,7 +69,7 @@ registration_token=$(jq --raw-output .token "$token_file")
3769
--labels self-hosted,linux.ppc64le
3870

3971
unset registration_token
40-
rm -f "$token_file"
72+
#rm -f "$token_file"
4173

4274
# enter into python virtual environment.
4375
# build workflows use "python -m pip install ...",
@@ -47,23 +79,4 @@ rm -f "$token_file"
4779
# Run one job.
4880
./run.sh
4981

50-
# Unregister runner after job completion
51-
echo "Unregistering runner from GitHub..."
52-
runner_id=$(curl -s \
53-
-H "Accept: application/vnd.github.v3+json" \
54-
-H "Authorization: Bearer $(cat /run/runner_secret)" \
55-
"https://api.github.com/repos/${OWNER}/${REPO}/actions/runners" | \
56-
jq --raw-output '.runners[] | select(.name=="'"${NAME}"'") | .id')
57-
58-
if [ -n "$runner_id" ]; then
59-
curl -s \
60-
-X DELETE \
61-
-H "Accept: application/vnd.github.v3+json" \
62-
-H "Authorization: Bearer $(cat /run/runner_secret)" \
63-
"https://api.github.com/repos/${OWNER}/${REPO}/actions/runners/$runner_id"
64-
echo "Runner unregistered successfully."
65-
else
66-
echo "Warning: Runner ID for ${NAME} not found. It may already be removed."
67-
fi
68-
6982
echo "Ephemeral runner workflow completed."

0 commit comments

Comments
 (0)