File: actions-runner

package info (click to toggle)
node-yarnpkg 4.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 24,752 kB
  • sloc: javascript: 38,953; ansic: 26,035; cpp: 7,247; sh: 2,829; makefile: 724; perl: 493
file content (59 lines) | stat: -rwxr-xr-x 1,352 bytes parent folder | download
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
#!/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 "$TOKEN_FILE" 2>/dev/null)
    STATUS=$?
    set -e
else
    STATUS=1
fi
if [[ $STATUS -ne 0 || $(date +%s) -ge $(date -d "$EXPIRES" +%s) ]]; then
    # Refresh the cached registration token.
    curl \
        -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