mirror of
https://github.com/hanzoai/docker-github-actions-runner.git
synced 2026-09-30 21:42:55 +00:00
Somehow our Github enterprise server returns 411 when the "Content-Lenght" header is not set. The complete error message is (using curl -v): ``` HTTP/1.1 411 Length Required < Content-Type: text/html; charset=us-ascii < Server: Microsoft-HTTPAPI/2.0 < Date: Thu, 06 Jan 2022 15:36:55 GMT < Connection: close < Content-Length: 344 < <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"> <HTML><HEAD><TITLE>Length Required</TITLE> <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD> <BODY><h2>Length Required</h2> <hr><p>HTTP Error 411. The request must be chunked or have a content length.</p> </BODY></HTML> ``` By setting this Header explicitely, this error does no longer occur.
45 lines
1.2 KiB
Bash
45 lines
1.2 KiB
Bash
#!/bin/bash
|
|
|
|
_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}"
|
|
else
|
|
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}"
|
|
CONTENT_LENGTH_HEADER="Content-Length: 0"
|
|
|
|
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 "${CONTENT_LENGTH_HEADER}" \
|
|
-H "${AUTH_HEADER}" \
|
|
-H "${API_HEADER}" \
|
|
"${_FULL_URL}" \
|
|
| jq -r '.token')"
|
|
|
|
echo "{\"token\": \"${RUNNER_TOKEN}\", \"full_url\": \"${_FULL_URL}\"}"
|