Skip to content

Commit 4a32783

Browse files
committed
Fix runner deregistration on shutdown
Update token Fix? Escape Trap err Fix? Use REMOVE_TOKEN Escaping Test Test Test Rm label su Remove args Fix su Try runner token works! Cleanup main
1 parent 70e2568 commit 4a32783

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

action.sh

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ cleanup() {
173173
trap 'cleanup; exit 130' INT
174174
trap 'cleanup; exit 143' TERM
175175
176+
on_error() {
177+
echo "Error on line \$(caller)"
178+
}
179+
180+
trap on_error ERR
181+
176182
cat <<-EOF >/etc/environment
177183
PATH="/home/runner/go-packages/bin:/home/runner/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
178184
GOPATH="/home/runner/go-packages"
@@ -188,6 +194,7 @@ EOF
188194
189195
chmod +x /etc/systemd/system/shutdown.sh
190196
197+
echo "Registering runners ${RUNNER_ID}-1 and ${RUNNER_ID}-2..."
191198
su -s /bin/bash -c "cd /actions-runner-1/;/actions-runner-1/config.sh --url https://github.com/${GITHUB_REPOSITORY} --token ${RUNNER_TOKEN} --name ${RUNNER_ID}-1 --labels ${VM_ID} --unattended --disableupdate" runner
192199
su -s /bin/bash -c "cd /actions-runner-2/;/actions-runner-2/config.sh --url https://github.com/${GITHUB_REPOSITORY} --token ${RUNNER_TOKEN} --name ${RUNNER_ID}-2 --labels ${VM_ID} --unattended --disableupdate" runner
193200
@@ -203,19 +210,21 @@ FILE_EOF
203210
204211
set -e
205212
206-
echo "Removing runner..."
207-
REMOVE_TOKEN=\$(curl \
208-
-X POST \
209-
-H "Accept: application/vnd.github+json" \
210-
-H "Authorization: Bearer ${RUNNER_TOKEN}" \
211-
https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runners/remove-token | jq .token --raw-output)
212-
if [ -z "\$REMOVE_TOKEN" ]; then
213-
echo "❌ Failed to get a removal token"
214-
exit 0
215-
fi
216-
217-
su -s /bin/bash -c "cd /actions-runner-1/;/actions-runner-1/config.sh remove --token \${REMOVE_TOKEN}" runner
218-
su -s /bin/bash -c "cd /actions-runner-2/;/actions-runner-2/config.sh remove --token \${REMOVE_TOKEN}" runner
213+
on_error() {
214+
echo "Error on line \$(caller)"
215+
}
216+
217+
trap on_error ERR
218+
219+
echo "Removing runners ${RUNNER_ID}-1 and ${RUNNER_ID}-2..."
220+
221+
cd /actions-runner-1/
222+
su -s /bin/bash -c "/actions-runner-1/config.sh remove --token ${RUNNER_TOKEN}" runner
223+
224+
cd /actions-runner-2/
225+
su -s /bin/bash -c "/actions-runner-2/config.sh remove --token ${RUNNER_TOKEN}" runner
226+
227+
echo "Removed runners"
219228
220229
FILE_EOF
221230

0 commit comments

Comments
 (0)