Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use personal token and add error handling #103

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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