|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 |
| -# Retrieve a short lived runner registration token using the PAT |
4 |
| -REGISTRATION_TOKEN="$(curl -X POST -fsSL \ |
5 |
| - -H 'Accept: application/vnd.github.v3+json' \ |
6 |
| - -H "Authorization: Bearer $GITHUB_PAT" \ |
7 |
| - -H 'X-GitHub-Api-Version: 2022-11-28' \ |
8 |
| - "$REGISTRATION_TOKEN_API_URL" \ |
9 |
| - | jq -r '.token')" |
10 |
| - |
11 |
| -./config.sh \ |
12 |
| - --url $REPO_URL \ |
13 |
| - --token $REGISTRATION_TOKEN \ |
14 |
| - --unattended \ |
15 |
| - --disableupdate \ |
16 |
| - --ephemeral \ |
17 |
| - --replace \ |
18 |
| - && ./run.sh |
19 |
| - |
20 |
| -export GITHUB_PAT=_REDACTED_ |
21 |
| -export REGISTRATION_TOKEN=_REDACTED_ |
| 3 | +INTERACTIVE="FALSE" |
| 4 | + |
| 5 | +# Verify some Repo URL and token have been given, otherwise we must be interactive mode. |
| 6 | +if [ -n "$GITHUB_REPOSITORY" ] && [ -n "$GITHUB_TOKEN" ]; then |
| 7 | + |
| 8 | + # |
| 9 | + # Legacy Container app configuration, with create and destroy agent |
| 10 | + # |
| 11 | + echo "🌊 start agent configuration" |
| 12 | + |
| 13 | + if [ "$(echo "$INTERACTIVE_MODE" | tr '[:upper:]' '[:lower:]')" == "true" ]; then |
| 14 | + INTERACTIVE="TRUE" |
| 15 | + fi |
| 16 | + |
| 17 | + # Calculate default configuration values. |
| 18 | + GITHUB_REPOSITORY_BANNER="$GITHUB_REPOSITORY" |
| 19 | + if [ -z "$GITHUB_REPOSITORY_BANNER" ]; then |
| 20 | + export GITHUB_REPOSITORY_BANNER="<empty repository url>" |
| 21 | + fi |
| 22 | + |
| 23 | + if [ -z "$RUNNER_NAME" ]; then |
| 24 | + RUNNER_NAME="$(hostname)" |
| 25 | + export RUNNER_NAME |
| 26 | + fi |
| 27 | + |
| 28 | + if [ -z "$WORK_DIR" ]; then |
| 29 | + export WORK_DIR=".workdir" |
| 30 | + fi |
| 31 | + |
| 32 | + # Calculate runner replacement policy. |
| 33 | + REPLACEMENT_POLICY="\n\n\n" |
| 34 | + REPLACEMENT_POLICY_LABEL="FALSE" |
| 35 | + if [ "$(echo "$REPLACE_EXISTING_RUNNER" | tr '[:upper:]' '[:lower:]')" == "true" ]; then |
| 36 | + REPLACEMENT_POLICY="Y\n\n" |
| 37 | + REPLACEMENT_POLICY_LABEL="TRUE" |
| 38 | + fi |
| 39 | + |
| 40 | + # Configure runner interactively, or with the given replacement policy. |
| 41 | + printf "ℹ️ Configuring GitHub Runner for %s\n\t" "$GITHUB_REPOSITORY_BANNER" |
| 42 | + printf "ℹ️ Runner Name: %s\n\t" "$RUNNER_NAME" |
| 43 | + printf "ℹ️ Working Directory: %s\n\t" "$WORK_DIR" |
| 44 | + printf "ℹ️ Replace Existing Runners: %s\n" "$REPLACEMENT_POLICY_LABEL" |
| 45 | + |
| 46 | + # actions-runner is a folder inside the github runner zip |
| 47 | + if [ "$INTERACTIVE" == "FALSE" ]; then |
| 48 | + echo -ne "$REPLACEMENT_POLICY" | ./config.sh --url "$GITHUB_REPOSITORY" --token "$GITHUB_TOKEN" --name "$RUNNER_NAME" --work "$WORK_DIR" --labels "$LABELS" --disableupdate |
| 49 | + else |
| 50 | + #<https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners> |
| 51 | + ./config.sh \ |
| 52 | + --url "$GITHUB_REPOSITORY" \ |
| 53 | + --token "$GITHUB_TOKEN" \ |
| 54 | + --name "$RUNNER_NAME" \ |
| 55 | + --work "$WORK_DIR" \ |
| 56 | + --labels "$LABELS" \ |
| 57 | + --disableupdate |
| 58 | + echo "✅ config.sh launched" |
| 59 | + fi |
| 60 | + |
| 61 | + # Start the runner. |
| 62 | + ./run.sh |
| 63 | + echo "🚀 Executing GitHub Runner for $GITHUB_REPOSITORY" |
| 64 | + |
| 65 | +else |
| 66 | + |
| 67 | + # |
| 68 | + # JOB Container app configuration |
| 69 | + # |
| 70 | + |
| 71 | + # Retrieve a short lived runner registration token using the PAT |
| 72 | + REGISTRATION_TOKEN="$(curl -X POST -fsSL \ |
| 73 | + -H 'Accept: application/vnd.github.v3+json' \ |
| 74 | + -H "Authorization: Bearer $GITHUB_PAT" \ |
| 75 | + -H 'X-GitHub-Api-Version: 2022-11-28' \ |
| 76 | + "$REGISTRATION_TOKEN_API_URL" \ |
| 77 | + | jq -r '.token')" |
| 78 | + |
| 79 | + #<https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners> |
| 80 | + ./config.sh \ |
| 81 | + --url "${REPO_URL}" \ |
| 82 | + --token "${REGISTRATION_TOKEN}" \ |
| 83 | + --unattended \ |
| 84 | + --disableupdate \ |
| 85 | + --ephemeral \ |
| 86 | + --replace \ |
| 87 | + && ./run.sh |
| 88 | + |
| 89 | + export GITHUB_PAT=_REDACTED_ |
| 90 | + export REGISTRATION_TOKEN=_REDACTED_ |
| 91 | + |
| 92 | +fi |
0 commit comments