Skip to content

Commit

Permalink
ci: enable vercel script to accept the vercel token as a param
Browse files Browse the repository at this point in the history
  • Loading branch information
neuodev committed Aug 3, 2024
1 parent 74457e6 commit a22588d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Build Uilib
run: yarn build:uilib
- name: Pull project from Vercel
run: yarn vercel pull "orbit" "./orbit/"
run: yarn vercel:ci pull "orbit" "./orbit/" --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Orbit using Vercel
run: yarn build:orbit:vercel
- name: Deploy to Vercel
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"build:uilib": "yarn workspace @litespace/uilib build",
"build:orbit:vercel": "yarn workspace @litespace/uilib build:vercel",
"deploy:orbit:vercel": "yarn workspace @litespace/uilib vercel:deploy",
"vercel": "env-cmd ts-node scripts/vercel.ts"
"vercel": "env-cmd ts-node scripts/vercel.ts",
"vercel:ci": "ts-node scripts/vercel.ts"
},
"workspaces": {
"packages": [
Expand Down
23 changes: 14 additions & 9 deletions scripts/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ async function safe<T>(callback: () => Promise<T>): Promise<T | Error> {
}
}

const client = axios.create({
baseURL: "https://api.vercel.com",
headers: { Authorization: `Bearer ${process.env.VERCEL_TOKEN}` },
});
function client(token?: string) {
return axios.create({
baseURL: "https://api.vercel.com",
headers: { Authorization: `Bearer ${token || process.env.VERCEL_TOKEN}` },
});
}

async function findProject(name: string): Promise<Project> {
return await client
async function findProject(name: string, token?: string): Promise<Project> {
return await client(token)
.get<Project>(`/v9/projects/${name}`)
.then((response) => response.data);
}
Expand All @@ -47,13 +49,15 @@ async function createProject({
buildCommand = "yarn build",
outputDirectory = "dist",
installCommand = "yarn",
token,
}: {
name: string;
buildCommand?: string;
outputDirectory?: string;
installCommand?: string;
token?: string;
}): Promise<Project> {
const { data } = await client.post<Project>("/v10/projects", {
const { data } = await client(token).post<Project>("/v10/projects", {
name,
buildCommand,
installCommand,
Expand Down Expand Up @@ -118,7 +122,8 @@ const pull = new Command()
.name("pull")
.argument("<name>", "Project name")
.argument("<path>", "Where to save project info after pulling it from vercel")
.action(async (name: string, path: string) => {
.option("-t, --token <token>", "Vercel token")
.action(async (name: string, path: string, options: { token?: string }) => {
if (!fs.existsSync(path)) throw new Error(`"${path}" not found`);

const vercel = asVercelDirectory(path);
Expand All @@ -127,7 +132,7 @@ const pull = new Command()

fs.mkdirSync(vercel);

const project = await safe(() => findProject(name));
const project = await safe(() => findProject(name, options.token));
if (project instanceof Error) throw project;

saveProject(vercel, project);
Expand Down

0 comments on commit a22588d

Please sign in to comment.