Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deprecate personal Vercel id for team id #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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
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 @@ -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",
Expand All @@ -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();
Expand Down Expand Up @@ -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, "-");
/**
Expand Down Expand Up @@ -304,7 +314,7 @@ async function run() {
stdout,
aliasHostname,
`--token=${vercelToken}`,
`--scope=${vercelOrgId}`,
`--scope=${vercelTeamId}`,
];
if (debug) {
vercelAliasArgs.push("--debug");
Expand Down
14 changes: 7 additions & 7 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 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",
Expand Down Expand Up @@ -113,4 +113,4 @@
"target": "dist/index.js"
}
}
}
}
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