Skip to content

Commit 5935818

Browse files
authored
Switch from bot PAT to GitHub App token via Azure Key Vault (#125)
1 parent c9fdb26 commit 5935818

3 files changed

Lines changed: 612 additions & 13 deletions

File tree

build/benchmark.yml

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ variables:
103103
azureSubscription: 'TypeScript Public CI'
104104
KeyVaultName: 'jststeam-passwords'
105105

106+
TYPESCRIPT_AUTOMATION_GITHUB_APP_CLIENT_ID: 'Iv23li4GolzJSEp1mzHI'
107+
TYPESCRIPT_AUTOMATION_GITHUB_APP_KEY_ID: 'https://jststeam-passwords.vault.azure.net/keys/typescript-automation'
108+
106109
${{ if eq(parameters.TS_GO, true) }}:
107110
REPO: 'typescript-go'
108111
REF: $[ replace(resources.repositories['typescript-go'].ref, 'heads/../', '') ]
@@ -348,13 +351,21 @@ jobs:
348351
MERGED_DIR: $(Pipeline.Workspace)/merged
349352

350353
steps:
351-
- task: AzureKeyVault@2
354+
- task: AzureCLI@2
352355
inputs:
353356
azureSubscription: $(azureSubscription)
354-
KeyVaultName: $(KeyVaultName)
355-
SecretsFilter: 'typescript-bot-github-PAT-typescript-benchmarking'
356-
displayName: Get secrets
357-
retryCountOnTaskFailure: 3
357+
scriptType: bash
358+
scriptLocation: inlineScript
359+
inlineScript: node scripts/create-github-app-token-from-keyvault.cjs
360+
displayName: Create GitHub App token
361+
env:
362+
APP_CLIENT_ID: $(TYPESCRIPT_AUTOMATION_GITHUB_APP_CLIENT_ID)
363+
KEY_ID: $(TYPESCRIPT_AUTOMATION_GITHUB_APP_KEY_ID)
364+
OWNER: microsoft
365+
REPOSITORIES: $(REPO)
366+
PERMISSIONS: contents:read,issues:write
367+
OUTPUT: azure-pipelines
368+
AZURE_TOKEN_VARIABLE: GH_TOKEN
358369

359370
- template: templates/setup.yml
360371

@@ -436,7 +447,7 @@ jobs:
436447
SOURCE_ISSUE: ${{ parameters.SOURCE_ISSUE }}
437448
REQUESTING_USER: ${{ parameters.REQUESTING_USER }}
438449
STATUS_COMMENT: ${{ parameters.STATUS_COMMENT }}
439-
GH_TOKEN: $(typescript-bot-github-PAT-typescript-benchmarking)
450+
GH_TOKEN: $(GH_TOKEN)
440451
441452
# Sets $(TSPERF_BLOB_LATEST)
442453
- bash: |
@@ -445,7 +456,7 @@ jobs:
445456
displayName: Check if commit is latest for ref
446457
condition: and(succeeded(), eq(variables['SHOULD_UPLOAD'], 'true'))
447458
env:
448-
GH_TOKEN: $(typescript-bot-github-PAT-typescript-benchmarking)
459+
GH_TOKEN: $(GH_TOKEN)
449460
450461
- task: AzureCLI@2
451462
inputs:
@@ -483,6 +494,12 @@ jobs:
483494
displayName: Upload benchmarks to blob store
484495
condition: and(succeeded(), eq(variables['SHOULD_UPLOAD'], 'true'))
485496

497+
- script: node scripts/create-github-app-token-from-keyvault.cjs
498+
displayName: Revoke GitHub App token
499+
condition: always()
500+
env:
501+
REVOKE_TOKEN: $(GH_TOKEN)
502+
486503
- job: OnFailedPRRun
487504
dependsOn:
488505
- Setup
@@ -498,13 +515,21 @@ jobs:
498515
clean: all # Always start with a clean slate.
499516

500517
steps:
501-
- task: AzureKeyVault@2
518+
- task: AzureCLI@2
502519
inputs:
503520
azureSubscription: $(azureSubscription)
504-
KeyVaultName: $(KeyVaultName)
505-
SecretsFilter: 'typescript-bot-github-PAT-typescript-benchmarking'
506-
displayName: Get secrets
507-
retryCountOnTaskFailure: 3
521+
scriptType: bash
522+
scriptLocation: inlineScript
523+
inlineScript: node scripts/create-github-app-token-from-keyvault.cjs
524+
displayName: Create GitHub App token
525+
env:
526+
APP_CLIENT_ID: $(TYPESCRIPT_AUTOMATION_GITHUB_APP_CLIENT_ID)
527+
KEY_ID: $(TYPESCRIPT_AUTOMATION_GITHUB_APP_KEY_ID)
528+
OWNER: microsoft
529+
REPOSITORIES: $(REPO)
530+
PERMISSIONS: contents:read,issues:write
531+
OUTPUT: azure-pipelines
532+
AZURE_TOKEN_VARIABLE: GH_TOKEN
508533

509534
- template: templates/setup.yml
510535
- template: templates/cloneAndBuildBenchmarkRepo.yml # Sets $(BENCH_SCRIPTS), $(TSPERF_EXE)
@@ -518,4 +543,10 @@ jobs:
518543
SOURCE_ISSUE: ${{ parameters.SOURCE_ISSUE }}
519544
REQUESTING_USER: ${{ parameters.REQUESTING_USER }}
520545
STATUS_COMMENT: ${{ parameters.STATUS_COMMENT }}
521-
GH_TOKEN: $(typescript-bot-github-PAT-typescript-benchmarking)
546+
GH_TOKEN: $(GH_TOKEN)
547+
548+
- script: node scripts/create-github-app-token-from-keyvault.cjs
549+
displayName: Revoke GitHub App token
550+
condition: always()
551+
env:
552+
REVOKE_TOKEN: $(GH_TOKEN)

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default tseslint.config(
1515
"**/dist/**",
1616
"vitest.workspace.mjs",
1717
"cases/**",
18+
"scripts/create-github-app-token-from-keyvault.cjs",
1819
],
1920
},
2021
eslint.configs.recommended,

0 commit comments

Comments
 (0)