Skip to content

Commit

Permalink
feat: deprecate personal Vercel id for team id
Browse files Browse the repository at this point in the history
  • Loading branch information
phidol committed Nov 10, 2024
1 parent a22bc8b commit 4856a33
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 36 deletions.
10 changes: 5 additions & 5 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: "<org-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 your Vercel Org.
The ID of your Vercel 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
46 changes: 22 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 @@ -142,10 +132,10 @@ async function run() {
"VERCEL_PROJECT_ID",
"Vercel Project Id"
);
const vercelOrgId = reconcileConfigurationInput(
"vercelOrgId",
"VERCEL_ORG_ID",
"Vercel Org Id"
const vercelTeamId = reconcileConfigurationInput(
"vercelTeamId",
"VERCEL_TEAM_ID",
"Vercel Team Id"
);
const vercelToken = reconcileConfigurationInput(
"vercelToken",
Expand All @@ -165,6 +155,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 @@ -241,8 +239,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, "-");
/**
Expand Down Expand Up @@ -304,7 +302,7 @@ async function run() {
stdout,
aliasHostname,
`--token=${vercelToken}`,
`--scope=${vercelOrgId}`,
`--scope=${vercelTeamId}`,
];
if (debug) {
vercelAliasArgs.push("--debug");
Expand Down
12 changes: 6 additions & 6 deletions vercel-deployment-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,
"Minor": 6,
"Patch": 4
"Major": 2,
"Minor": 0,
"Patch": 0
},
"instanceNameFormat": "Deploying $(vercelProject) to Vercel",
"inputs": [
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 your Vercel Org. Can also be set as the environment variable `VERCEL_ORG_ID`."
"helpMarkDown": "The ID of your Vercel Team. Starts with 'team_'. Can also be set as the environment variable `VERCEL_TEAM_ID`."
},
{
"name": "vercelToken",
Expand Down
2 changes: 1 addition & 1 deletion 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.6.4",
"version": "2.0.0",
"publisher": "Vercel",
"public": true,
"targets": [
Expand Down

0 comments on commit 4856a33

Please sign in to comment.