forked from myoung34/docker-github-actions-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The backwards compatibility with ORG_RUNNER is ensured. If RUNNER_SCOPE is present, it overrides what is imposed by ORG_RUNNER.
- Loading branch information
1 parent
e4a4891
commit 856296f
Showing
3 changed files
with
61 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,42 @@ | ||
#!/bin/bash | ||
|
||
_ORG_RUNNER=${ORG_RUNNER:-false} | ||
_ENTERPRISE_RUNNER=${ENTERPRISE_RUNNER:-false} | ||
_GITHUB_HOST=${GITHUB_HOST:="github.com"} | ||
|
||
# If URL is not github.com then use the enterprise api endpoint | ||
if [[ ${GITHUB_HOST} = "github.com" ]]; then | ||
URI="https://api.${_GITHUB_HOST}" | ||
URI="https://api.${_GITHUB_HOST}" | ||
else | ||
URI="https://${_GITHUB_HOST}/api/v3" | ||
URI="https://${_GITHUB_HOST}/api/v3" | ||
fi | ||
|
||
API_VERSION=v3 | ||
API_HEADER="Accept: application/vnd.github.${API_VERSION}+json" | ||
AUTH_HEADER="Authorization: token ${ACCESS_TOKEN}" | ||
|
||
REPO_URL=${REPO_URL:-${URI}} | ||
_PROTO="$(echo "${REPO_URL}" | grep :// | sed -e's,^\(.*://\).*,\1,g')" | ||
# shellcheck disable=SC2116 | ||
_URL="$(echo "${REPO_URL/${_PROTO}/}")" | ||
_PATH="$(echo "${_URL}" | grep / | cut -d/ -f2-)" | ||
_ACCOUNT="$(echo "${_PATH}" | cut -d/ -f1)" | ||
_REPO="$(echo "${_PATH}" | cut -d/ -f2)" | ||
|
||
_FULL_URL="${URI}/repos/${_ACCOUNT}/${_REPO}/actions/runners/registration-token" | ||
if [[ ${_ORG_RUNNER} == "true" ]]; then | ||
[[ -z ${ORG_NAME} ]] && ( echo "ORG_NAME required for org runners"; exit 1 ) | ||
_FULL_URL="${URI}/orgs/${ORG_NAME}/actions/runners/registration-token" | ||
_SHORT_URL="${_PROTO}${_GITHUB_HOST}/${ORG_NAME}" | ||
elif [[ ${_ENTERPRISE_RUNNER} == "true" ]]; then | ||
[[ -z ${ENTERPRISE_NAME} ]] && ( echo "ENTERPRISE_NAME required for enterprise runners"; exit 1 ) | ||
_FULL_URL="${URI}/enterprises/${ENTERPRISE_NAME}/actions/runners/registration-token" | ||
_SHORT_URL="${_PROTO}${_GITHUB_HOST}/enterprises/${ENTERPRISE_NAME}" | ||
else | ||
_SHORT_URL=$REPO_URL | ||
fi | ||
case ${RUNNER_SCOPE} in | ||
org*) | ||
_FULL_URL="${URI}/orgs/${ORG_NAME}/actions/runners/registration-token" | ||
;; | ||
|
||
ent*) | ||
_FULL_URL="${URI}/enterprises/${ENTERPRISE_NAME}/actions/runners/registration-token" | ||
;; | ||
|
||
*) | ||
_PROTO="https://" | ||
# shellcheck disable=SC2116 | ||
_URL="$(echo "${REPO_URL/${_PROTO}/}")" | ||
_PATH="$(echo "${_URL}" | grep / | cut -d/ -f2-)" | ||
_ACCOUNT="$(echo "${_PATH}" | cut -d/ -f1)" | ||
_REPO="$(echo "${_PATH}" | cut -d/ -f2)" | ||
_FULL_URL="${URI}/repos/${_ACCOUNT}/${_REPO}/actions/runners/registration-token" | ||
;; | ||
esac | ||
|
||
RUNNER_TOKEN="$(curl -XPOST -fsSL \ | ||
-H "${AUTH_HEADER}" \ | ||
-H "${API_HEADER}" \ | ||
"${_FULL_URL}" \ | ||
| jq -r '.token')" | ||
|
||
echo "{\"token\": \"${RUNNER_TOKEN}\", \"short_url\": \"${_SHORT_URL}\", \"full_url\": \"${_FULL_URL}\"}" | ||
echo "{\"token\": \"${RUNNER_TOKEN}\", \"full_url\": \"${_FULL_URL}\"}" |