summaryrefslogtreecommitdiff
path: root/neozip/arch/s390/self-hosted-builder/actions-runner
diff options
context:
space:
mode:
Diffstat (limited to 'neozip/arch/s390/self-hosted-builder/actions-runner')
-rwxr-xr-xneozip/arch/s390/self-hosted-builder/actions-runner62
1 files changed, 62 insertions, 0 deletions
diff --git a/neozip/arch/s390/self-hosted-builder/actions-runner b/neozip/arch/s390/self-hosted-builder/actions-runner
new file mode 100755
index 0000000000..aabc802547
--- /dev/null
+++ b/neozip/arch/s390/self-hosted-builder/actions-runner
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+#
+# Ephemeral runner startup script.
+#
+# Expects the following environment variables:
+#
+# - REPO=<owner>
+# - PAT_TOKEN=<github_pat_***>
+#
+
+set -e -u
+
+# Validate required environment variables
+if [ -z "${REPO:-}" ] || [ -z "${PAT_TOKEN:-}" ]; then
+ echo "Error: REPO and/or PAT_TOKEN environment variables not found"
+ exit 1
+fi
+
+# Check the cached registration token.
+TOKEN_FILE=registration-token.json
+if [ -f $TOKEN_FILE ]; then
+ set +e
+ EXPIRES=$(jq --raw-output .expires_at "$TOKEN_FILE" 2>/dev/null)
+ STATUS=$?
+ set -e
+else
+ STATUS=1
+ EXPIRES=""
+fi
+
+if [[ $STATUS -ne 0 || -z "$EXPIRES" || "$EXPIRES" == "null" || $(date +%s) -ge $(date -d "$EXPIRES" +%s) ]]; then
+ # Refresh the cached registration token.
+ curl \
+ -sS \
+ -X POST \
+ -H "Accept: application/vnd.github+json" \
+ -H "Authorization: Bearer $PAT_TOKEN" \
+ "https://api.github.com/repos/$REPO/actions/runners/registration-token" \
+ -o "$TOKEN_FILE"
+fi
+
+REG_TOKEN=$(jq --raw-output .token "$TOKEN_FILE")
+if [ $REG_TOKEN = "null" ]; then
+ echo "Failed to get registration token"
+ exit 1
+fi
+
+# (Re-)register the runner.
+./config.sh remove --token "$REG_TOKEN" || true
+set -x
+./config.sh \
+ --url "https://github.com/$REPO" \
+ --token "$REG_TOKEN" \
+ --unattended \
+ --disableupdate \
+ --replace \
+ --labels z15 \
+ --ephemeral
+
+# Run one job.
+./run.sh