From 26e0ff66a6b1478586800dad6d34d2c9b5fe5585 Mon Sep 17 00:00:00 2001 From: Philipp Dollst Date: Tue, 12 Nov 2024 19:58:21 +0100 Subject: [PATCH] docs: adjust wording around vercelOrgId to team id (#42) --- README.md | 10 ++-- vercel-deployment-task-source/src/index.ts | 58 +++++++++++++--------- vercel-deployment-task-source/task.json | 14 +++--- vss-extension.json | 2 +- 4 files changed, 47 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 4c63188..0feb622 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ This short guide will demonstrate how the extension can be used to automatically name: Deploy inputs: vercelProjectId: "" - vercelOrgId: "" + vercelTeamId: "" vercelToken: "" # '$(VERCEL_TOKEN)' production: true ``` @@ -98,7 +98,7 @@ This guide will demonstrate how to improve the [Basic Pipeline Set Up](#basic-pi An Azure Pipelines Task Extension for automatically deploying to Vercel. -The configuration inputs `vercelProjectID`, `vercelOrgID`, and `vercelToken` can all be replaced with environment variables. See their respective property sections for more details. +The configuration inputs `vercelProjectID`, `vercelTeamId`, and `vercelToken` can all be replaced with environment variables. See their respective property sections for more details. #### Properties @@ -112,11 +112,11 @@ The configuration inputs `vercelProjectID`, `vercelOrgID`, and `vercelToken` can Required: `false` -- `vercelOrgId` +- `vercelTeamId` - The ID of your Vercel Org. + The ID of the Vercel Team your Vercel Project is associated with. Starts with `team_`. - Can alternatively be set as the environment variable `VERCEL_ORG_ID`. + Can alternatively be set as the environment variable `VERCEL_TEAM_ID`. Type: `string` diff --git a/vercel-deployment-task-source/src/index.ts b/vercel-deployment-task-source/src/index.ts index 95256b7..7b599ac 100644 --- a/vercel-deployment-task-source/src/index.ts +++ b/vercel-deployment-task-source/src/index.ts @@ -20,17 +20,12 @@ function errorHandler(error: unknown) { process.on("unhandledRejection", errorHandler); process.on("unhandledException", errorHandler); -function isTeamID(orgID: string) { - return orgID.startsWith("team_"); +function isTeamID(teamId: string) { + return teamId.startsWith("team_"); } -async function getStagingPrefix(orgID: string, token: string): Promise { - const isTeam = isTeamID(orgID); - const apiURL = isTeam - ? `https://api.vercel.com/v2/teams/${orgID}` - : `https://api.vercel.com/v2/user`; - - const { statusCode, body } = await request(apiURL, { +async function getStagingPrefix(teamId: string, token: string): Promise { + const { statusCode, body } = await request(`https://api.vercel.com/v2/teams/${teamId}`, { headers: { Authorization: `Bearer ${token}`, }, @@ -45,20 +40,15 @@ async function getStagingPrefix(orgID: string, token: string): Promise { ); } - return isTeam ? result.stagingPrefix : result.user.stagingPrefix; + return result.stagingPrefix; } async function getProjectName( projectId: string, - orgId: string, + teamId: string, token: string ): Promise { - let apiURL = `https://api.vercel.com/v9/projects/${projectId}`; - if (isTeamID(orgId)) { - apiURL += `?teamId=${orgId}`; - } - - const { statusCode, body } = await request(apiURL, { + const { statusCode, body } = await request(`https://api.vercel.com/v9/projects/${projectId}?teamId=${teamId}`, { headers: { Authorization: `Bearer ${token}`, }, @@ -142,11 +132,23 @@ async function run() { "VERCEL_PROJECT_ID", "Vercel Project Id" ); - const vercelOrgId = reconcileConfigurationInput( - "vercelOrgId", - "VERCEL_ORG_ID", - "Vercel Org Id" + + let vercelTeamId = reconcileConfigurationInput( + "vercelTeamId", + "VERCEL_TEAM_ID", + "Vercel Team Id" ); + + if (!vercelTeamId) { + console.warn('Please set \'vercelTeamId\'. \'vercelOrgId\' is deprecated.'); + + vercelTeamId = reconcileConfigurationInput( + "vercelOrgId", + "VERCEL_ORG_ID", + "Vercel Org Id" + ); + } + const vercelToken = reconcileConfigurationInput( "vercelToken", "VERCEL_TOKEN", @@ -165,6 +167,14 @@ async function run() { const VERCEL_CLI_VERSION = getVariable("VERCEL_CLI_VERSION") ?? "vercel@latest"; + if (!isTeamID(vercelTeamId) && !deployToProduction) { + throw new Error('Usage of a Personal Vercel ID is deprecated as it breaks Preview Deployments. Exchange your Personal Vercel ID with the Team ID your Project is associated with. The Team ID starts with \'team_\''); + } + + if (!isTeamID(vercelTeamId)) { + console.warn('Usage of a Personal Vercel ID is deprecated. Consider switching to using your Team ID (starts with \'team_\') instead.') + } + const npm = tool(which("npm", true)); const npmInstall = npm.arg(["install", "-g", VERCEL_CLI_VERSION]); let { stdout, stderr, code } = npmInstall.execSync(); @@ -241,8 +251,8 @@ async function run() { if (branchName) { const [projectName, stagingPrefix] = await Promise.all([ - getProjectName(vercelProjectId, vercelOrgId, vercelToken), - getStagingPrefix(vercelOrgId, vercelToken), + getProjectName(vercelProjectId, vercelTeamId, vercelToken), + getStagingPrefix(vercelTeamId, vercelToken), ]); const escapedBranchName = branchName.replace(/[^a-zA-Z0-9\-]-?/g, "-"); /** @@ -304,7 +314,7 @@ async function run() { stdout, aliasHostname, `--token=${vercelToken}`, - `--scope=${vercelOrgId}`, + `--scope=${vercelTeamId}`, ]; if (debug) { vercelAliasArgs.push("--debug"); diff --git a/vercel-deployment-task-source/task.json b/vercel-deployment-task-source/task.json index 6075151..f646260 100644 --- a/vercel-deployment-task-source/task.json +++ b/vercel-deployment-task-source/task.json @@ -9,9 +9,9 @@ "category": "Azure Pipelines", "author": "Vercel", "version": { - "Major": 1, - "Minor": 6, - "Patch": 4 + "Major": 2, + "Minor": 0, + "Patch": 0 }, "instanceNameFormat": "Deploying $(vercelProject) to Vercel", "inputs": [ @@ -23,11 +23,11 @@ "helpMarkDown": "The ID of your Vercel Project. Can also be set as the environment variable `VERCEL_PROJECT_ID`." }, { - "name": "vercelOrgId", + "name": "vercelTeamId", "type": "string", - "label": "Vercel Org ID", + "label": "Vercel Team ID", "required": false, - "helpMarkDown": "The ID of your Vercel Org. Can also be set as the environment variable `VERCEL_ORG_ID`." + "helpMarkDown": "The ID of the Vercel Team your Vercel Project is associated with. Starts with `team_`. Can also be set as the environment variable `VERCEL_ORG_ID`." }, { "name": "vercelToken", @@ -113,4 +113,4 @@ "target": "dist/index.js" } } -} +} \ No newline at end of file diff --git a/vss-extension.json b/vss-extension.json index c576dc0..76c5778 100644 --- a/vss-extension.json +++ b/vss-extension.json @@ -3,7 +3,7 @@ "manifestVersion": 1, "id": "vercel-deployment-extension", "name": "Vercel Deployment Extension", - "version": "1.6.4", + "version": "2.0.0", "publisher": "Vercel", "public": true, "targets": [