Skip to content

Commit 48bc666

Browse files
debug: auth workflow (#2168)
* fix: auth workflow * enable: workflow_dispatch * Update .github/workflows/register-preview-url.yml
1 parent 84c35d3 commit 48bc666

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

.github/workflows/register-preview-url.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
# This workflow enables HashiCorp Oauth on Vercel preview deployments.
12
name: Register Preview URL with CloudIDP
23

34
on:
45
deployment_status:
5-
6+
# workflow_dispatch is here for supporting manual iteration
7+
workflow_dispatch:
8+
inputs:
9+
preview_url:
10+
description: 'A Vercel preview url. Only used during manual runs'
11+
required: true
612
jobs:
713
on-deploy:
814
runs-on: ubuntu-latest
@@ -26,8 +32,10 @@ jobs:
2632
- name: Add Preview URL to CloudIDP
2733
run: npx hc-tools ./scripts/add-preview-url-to-cloud-idp.ts
2834
env:
35+
# parameters
36+
PREVIEW_URL: ${{ inputs.preview_url || github.event.deployment_status.target_url }}
37+
# secrets
2938
CLOUD_IDP_DEPLOYMENT_PREVIEW_PRIVATE_KEY: ${{ secrets.CLOUD_IDP_DEPLOYMENT_PREVIEW_PRIVATE_KEY }}
30-
PREVIEW_URL: ${{ github.event.deployment_status.target_url }}
3139
FLOW_IDP_DEPLOYMENT_READY_URL: ${{ secrets.FLOW_IDP_DEPLOYMENT_READY_URL }}
3240
VERCEL_API_TOKEN: ${{ secrets.VERCEL_API_TOKEN }}
3341
VERCEL_TEAM_ID: ${{ secrets.VERCEL_TEAM_ID }}

scripts/add-preview-url-to-cloud-idp.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@ const fetch = createFetch()
1111
const vercelApiToken = process.env.VERCEL_API_TOKEN
1212
const vercelTeamId = process.env.VERCEL_TEAM_ID
1313

14+
// For Vercel API docs
15+
// see https://vercel.com/docs/rest-api/endpoints#get-a-deployment-by-id-or-url
16+
1417
/** A helper to fetch Vercel Deployment Aliases from Vercel Deploy Preview URLs */
1518
async function fetchDeploymentAlias(previewUrl: string): Promise<string[]> {
19+
console.log('fetchDeploymentAlias', previewUrl)
20+
1621
const previewHostname = new URL(previewUrl).hostname
1722
const url = new URL(
1823
`v13/deployments/${previewHostname}`,
1924
'https://api.vercel.com'
2025
)
2126

2227
url.searchParams.set('teamId', vercelTeamId)
23-
url.searchParams.set('withAutomaticAliases', '1')
2428

2529
const headers = { Authorization: `Bearer ${vercelApiToken}` }
2630

2731
const res = await fetch(url.toString(), { headers })
2832
const data = await res.json()
33+
console.log(data)
2934

3035
// NOTE: returned aliases only contain hostname, and no scheme
3136
// Scheme will need to be prepended before being passed in the

0 commit comments

Comments
 (0)