Skip to content

Commit

Permalink
use personal token and add error handling (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-harvey authored Sep 29, 2022
1 parent 87e5f8e commit 8ae1067
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
docker run --rm \
-e REPO_OWNER=CMSgov \
-e REPO_NAME=github-actions-runner-aws \
-e PERSONAL_ACCESS_TOKEN=${{ secrets.ROBOT_MAC_FC_TOKEN}} \
-e PERSONAL_ACCESS_TOKEN=${{ secrets.BHARVEY_GITHUB_TOKEN}} \
-e RUNNER_UUID=${{ needs.set-runner-uuid.outputs.runner-uuid }} \
${{ env.SHA_TAG }}
Expand All @@ -95,7 +95,7 @@ jobs:
until \
curl -s \
-H "Accept: application/vnd.github.v3+json" \
-u robot-mac-fc:${{ secrets.ROBOT_MAC_FC_TOKEN }} \
-u robot-mac-fc:${{ secrets.BHARVEY_GITHUB_TOKEN }} \
https://api.github.com/repos/CMSgov/github-actions-runner-aws/actions/runners \
| jq -e '.runners | .[] | select(.name == "${{ needs.set-runner-uuid.outputs.runner-uuid }}") | .status == "online"' >/dev/null
do
Expand Down
19 changes: 17 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,24 @@ mkdir work-dir
cd actions-runner

# Grab a runner registration token
REGISTRATION_TOKEN=$(curl -s -X POST \
# https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-a-repository
status_code=$(curl \
-s \
-w "%{http_code}" \
-o /tmp/token_response.json \
-X POST \
-H "Authorization: token ${PERSONAL_ACCESS_TOKEN}" \
"https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/actions/runners/registration-token" | jq -r .token)
"https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/actions/runners/registration-token" \
)

if [[ $status_code == "201" ]]
then
REGISTRATION_TOKEN=$(jq -r ".token" /tmp/token_response.json)
else
echo "Got status code $status_code trying to create a GitHub repo registration token."
echo "Response: $(cat /tmp/token_response.json)"
exit 1
fi

# Use the RUNNER_UUID env var if it exists
UNIQUE_ID=${RUNNER_UUID:-$(uuidgen)}
Expand Down

0 comments on commit 8ae1067

Please sign in to comment.