Skip to content

Commit b09684a

Browse files
committed
self-hosted-runners: use the App's repository access token
In git-for-windows-automation, we want to act as the GitForWindowsHelper GitHub App as much as possible. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent cf522f2 commit b09684a

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

.github/workflows/create-azure-self-hosted-runners.yml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ env:
3333
POST_DEPLOYMENT_SCRIPT_URL: https://raw.githubusercontent.com/${{ github.repository }}/${{ github.ref_name }}/azure-self-hosted-runners/post-deployment-script.ps1
3434

3535
# The following secrets are required for this workflow to run:
36-
# GH_API_PAT - PAT to create a runner registration token using GitHub's API
3736
# AZURE_CREDENTIALS - Credentials for the Azure CLI. It's recommended to set up a resource
3837
# group specifically for self-hosted Actions Runners.
3938
# az ad sp create-for-rbac --name "{YOUR_DESCRIPTIVE_NAME_HERE}" --role contributor \
@@ -70,7 +69,34 @@ jobs:
7069
VM_NAME="actions-runner-$(date +%Y%m%d%H%M%S%N)"
7170
echo "Will be using $VM_NAME as the VM name"
7271
echo "vm_name=$VM_NAME" >> $GITHUB_OUTPUT
72+
- uses: actions/checkout@v3
73+
- name: Obtain installation token
74+
id: setup
75+
uses: actions/github-script@v6
76+
with:
77+
script: |
78+
const appId = ${{ secrets.GH_APP_ID }}
79+
const privateKey = `${{ secrets.GH_APP_PRIVATE_KEY }}`
80+
81+
const getAppInstallationId = require('./get-app-installation-id')
82+
const installationId = await getAppInstallationId(
83+
console,
84+
appId,
85+
privateKey,
86+
process.env.ACTIONS_RUNNER_ORG,
87+
process.env.ACTIONS_RUNNER_REPO
88+
)
7389
90+
const getInstallationAccessToken = require('./get-installation-access-token')
91+
const accessToken = await getInstallationAccessToken(
92+
console,
93+
appId,
94+
privateKey,
95+
installationId
96+
)
97+
98+
core.setSecret(accessToken)
99+
core.setOutput('token', accessToken)
74100
# We can't use the octokit/request-action as we can't properly mask the runner token with it
75101
# https://github.com/actions/runner/issues/475
76102
- name: Generate Actions Runner token and registration URL
@@ -93,7 +119,7 @@ jobs:
93119
ACTIONS_RUNNER_TOKEN=$(curl \
94120
-X POST \
95121
-H "Accept: application/vnd.github+json" \
96-
-H "Authorization: Bearer ${{ secrets.GH_API_PAT }}"\
122+
-H "Authorization: Bearer ${{ steps.setup.outputs.token }}"\
97123
-H "X-GitHub-Api-Version: 2022-11-28" \
98124
$ACTIONS_API_URL \
99125
| jq --raw-output .token)
@@ -105,9 +131,6 @@ jobs:
105131
with:
106132
creds: ${{ secrets.AZURE_CREDENTIALS }}
107133

108-
# Checkout the repo so that we can access the template files
109-
- uses: actions/checkout@v3
110-
111134
- uses: azure/arm-deploy@v1
112135
with:
113136
resourceGroupName: ${{ secrets.AZURE_RESOURCE_GROUP }}

0 commit comments

Comments
 (0)