22
33set -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
638if [ ! -f /run/runner_secret ]; then
739 echo " Error: Access token file not found at /run/runner_secret."
840 exit 1
941fi
1042
11- token_file=registration-token.json
43+
1244
1345ACCESS_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
3971unset 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-
6982echo " Ephemeral runner workflow completed."
0 commit comments