diff --git a/README.md b/README.md index 0db0cfe..f5ccce5 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 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-azdo-pr-comment-task-source/task.json b/vercel-azdo-pr-comment-task-source/task.json index b0787ce..9a61b01 100644 --- a/vercel-azdo-pr-comment-task-source/task.json +++ b/vercel-azdo-pr-comment-task-source/task.json @@ -9,9 +9,9 @@ "category": "Azure Pipelines", "author": "Vercel", "version": { - "Major": 1, + "Major": 2, "Minor": 0, - "Patch": 1 + "Patch": 0 }, "instanceNameFormat": "Commenting on Pull Request", "inputs": [ diff --git a/vercel-deployment-task-source/src/index.ts b/vercel-deployment-task-source/src/index.ts index cf76b37..c781c20 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}`, }, @@ -144,11 +134,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", @@ -167,6 +169,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(); @@ -246,8 +256,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, "-"); const escapedProjectName = projectName.replace( @@ -313,7 +323,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 2fbdd59..da5078a 100644 --- a/vercel-deployment-task-source/task.json +++ b/vercel-deployment-task-source/task.json @@ -9,8 +9,8 @@ "category": "Azure Pipelines", "author": "Vercel", "version": { - "Major": 1, - "Minor": 7, + "Major": 2, + "Minor": 0, "Patch": 0 }, "instanceNameFormat": "Deploying $(vercelProject) to Vercel", @@ -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 the Vercel Team your Vercel Project is associated with. Starts with `team_`. 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_TEAM_ID`." }, { "name": "vercelToken", diff --git a/vss-extension.json b/vss-extension.json index a94f3ae..5a0259c 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.7.0", + "version": "2.0.0", "publisher": "Vercel", "public": true, "targets": [ @@ -12,7 +12,9 @@ } ], "description": "An Azure Pipelines Task Extension for automatically deploying to Vercel", - "categories": ["Azure Pipelines"], + "categories": [ + "Azure Pipelines" + ], "content": { "details": { "path": "README.md" @@ -48,7 +50,9 @@ { "id": "vercel-deployment-task", "type": "ms.vss-distributed-task.task", - "targets": ["ms.vss-distributed-task.tasks"], + "targets": [ + "ms.vss-distributed-task.tasks" + ], "properties": { "name": "vercel-deployment-task" } @@ -56,7 +60,9 @@ { "id": "vercel-azdo-pr-comment-task", "type": "ms.vss-distributed-task.task", - "targets": ["ms.vss-distributed-task.tasks"], + "targets": [ + "ms.vss-distributed-task.tasks" + ], "properties": { "name": "vercel-azdo-pr-comment-task" }