Skip to content

Commit

Permalink
feat: deprecate personal Vercel id for team id (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
phidol authored Feb 17, 2025
1 parent d23aa66 commit d88997f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 39 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This short guide will demonstrate how the extension can be used to automatically
name: Deploy
inputs:
vercelProjectId: "<project-id>"
vercelOrgId: "<team-id>"
vercelTeamId: "<team-id>"
vercelToken: "<vercel-token>" # '$(VERCEL_TOKEN)'
production: true
```
Expand Down Expand Up @@ -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

Expand All @@ -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`

Expand Down
4 changes: 2 additions & 2 deletions vercel-azdo-pr-comment-task-source/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
58 changes: 34 additions & 24 deletions vercel-deployment-task-source/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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<string> {
const { statusCode, body } = await request(`https://api.vercel.com/v2/teams/${teamId}`, {
headers: {
Authorization: `Bearer ${token}`,
},
Expand All @@ -45,20 +40,15 @@ async function getStagingPrefix(orgID: string, token: string): Promise<string> {
);
}

return isTeam ? result.stagingPrefix : result.user.stagingPrefix;
return result.stagingPrefix;
}

async function getProjectName(
projectId: string,
orgId: string,
teamId: string,
token: string
): Promise<string> {
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}`,
},
Expand Down Expand Up @@ -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",
Expand All @@ -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();
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -313,7 +323,7 @@ async function run() {
stdout,
aliasHostname,
`--token=${vercelToken}`,
`--scope=${vercelOrgId}`,
`--scope=${vercelTeamId}`,
];
if (debug) {
vercelAliasArgs.push("--debug");
Expand Down
10 changes: 5 additions & 5 deletions vercel-deployment-task-source/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
14 changes: 10 additions & 4 deletions vss-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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"
Expand Down Expand Up @@ -48,15 +50,19 @@
{
"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"
}
},
{
"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"
}
Expand Down

0 comments on commit d88997f

Please sign in to comment.