Skip to content

Commit 50bbfcf

Browse files
authored
refactor: remove appendProjectArgs and simplify personal account retry (#299)
* refactor: remove appendProjectArgs and simplify retry logic The --project flag fallback was added as a workaround for personal account scope errors, but VERCEL_PROJECT_ID set in env is sufficient for the retry path. Remove the helper and update the warning message to reflect that VERCEL_PROJECT_ID remains active after clearing VERCEL_ORG_ID. * chore(example): update static example vercel.json Add \$schema reference, remove deprecated version field and github.enabled config that is no longer needed in modern Vercel config. * fix: mask vercel token in logs, sanitize commit metadata, and preserve retry error context - Add core.setSecret(vercelToken) to prevent token leakage in action logs - Sanitize commit message (strip newlines/quotes) before passing as metadata - Preserve original error output when retry path also fails - Remove core.exportVariable for VERCEL_ORG_ID (process.env delete suffices)
1 parent 1b0001f commit 50bbfcf

File tree

3 files changed

+21
-42
lines changed

3 files changed

+21
-42
lines changed

dist/index.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59652,6 +59652,7 @@ function getVercelBin() {
5965259652
}
5965359653

5965459654
const vercelToken = core.getInput('vercel-token', { required: true })
59655+
core.setSecret(vercelToken)
5965559656
const vercelArgs = core.getInput('vercel-args')
5965659657
const vercelOrgId = core.getInput('vercel-org-id')
5965759658
const vercelProjectId = core.getInput('vercel-project-id')
@@ -59745,7 +59746,7 @@ function buildDeployArgs(providedArgs, ref, commit, sha, commitOrg, commitRepo)
5974559746
...addVercelMetadata('githubRepo', context.repo.repo, providedArgs),
5974659747
...addVercelMetadata('githubCommitOrg', commitOrg, providedArgs),
5974759748
...addVercelMetadata('githubCommitRepo', commitRepo, providedArgs),
59748-
...addVercelMetadata('githubCommitMessage', `"${commit}"`, providedArgs),
59749+
...addVercelMetadata('githubCommitMessage', `"${commit.replace(/[\r\n]+/g, ' ').replace(/"/g, '')}"`, providedArgs),
5974959750
...addVercelMetadata(
5975059751
'githubCommitRef',
5975159752
ref.replace('refs/heads/', ''),
@@ -59754,17 +59755,6 @@ function buildDeployArgs(providedArgs, ref, commit, sha, commitOrg, commitRepo)
5975459755
]
5975559756
}
5975659757

59757-
function appendProjectArgs(args, providedArgs) {
59758-
const hasProjectArg = providedArgs.some(
59759-
arg => arg === '--project' || arg.startsWith('--project='),
59760-
)
59761-
59762-
if (!hasProjectArg && vercelProjectId) {
59763-
core.info('using --project flag (personal account fallback)')
59764-
args.push('--project', vercelProjectId)
59765-
}
59766-
}
59767-
5976859758
async function vercelDeploy(ref, commit, sha, commitOrg, commitRepo) {
5976959759
let myOutput = ''
5977059760
let myError = ''
@@ -59789,10 +59779,6 @@ async function vercelDeploy(ref, commit, sha, commitOrg, commitRepo) {
5978959779

5979059780
const args = buildDeployArgs(providedArgs, ref, commit, sha, commitOrg, commitRepo)
5979159781

59792-
if (vercelProjectId && !vercelOrgId) {
59793-
appendProjectArgs(args, providedArgs)
59794-
}
59795-
5979659782
if (vercelScope) {
5979759783
core.info('using scope')
5979859784
args.push('--scope', vercelScope)
@@ -59812,18 +59798,23 @@ async function vercelDeploy(ref, commit, sha, commitOrg, commitRepo) {
5981259798
}
5981359799
core.warning(
5981459800
'Vercel CLI rejected the org ID as a personal account scope. '
59815-
+ 'Retrying without VERCEL_ORG_ID using --project flag instead.',
59801+
+ 'Retrying without VERCEL_ORG_ID (VERCEL_PROJECT_ID is still set).',
5981659802
)
59817-
core.exportVariable('VERCEL_ORG_ID', '')
5981859803
delete process.env.VERCEL_ORG_ID
5981959804

59805+
const originalOutput = myOutput
59806+
const originalError = myError
5982059807
myOutput = ''
5982159808
myError = ''
5982259809
const retryArgs = buildDeployArgs(providedArgs, ref, commit, sha, commitOrg, commitRepo)
59823-
appendProjectArgs(retryArgs, providedArgs)
5982459810
// Don't re-add --scope on retry — it may have caused the personal account error
5982559811

5982659812
exitCode = await exec.exec('npx', [vercelBin, ...retryArgs], options)
59813+
59814+
if (exitCode !== 0) {
59815+
core.error(`Original attempt output:\n${originalOutput}`)
59816+
core.error(`Original attempt errors:\n${originalError}`)
59817+
}
5982759818
}
5982859819

5982959820
if (exitCode !== 0) {

example/static/vercel.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
{
2+
"$schema": "https://openapi.vercel.sh/vercel.json",
23
"name": "zeit-now-deployment-action-example-static",
3-
"version": 2,
44
"scope": "amond",
55
"public": false,
6-
"github": {
7-
"enabled": false
8-
},
96
"builds": [
107
{ "src": "./**", "use": "@vercel/static" }
118
]

index.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function getVercelBin() {
6767
}
6868

6969
const vercelToken = core.getInput('vercel-token', { required: true })
70+
core.setSecret(vercelToken)
7071
const vercelArgs = core.getInput('vercel-args')
7172
const vercelOrgId = core.getInput('vercel-org-id')
7273
const vercelProjectId = core.getInput('vercel-project-id')
@@ -160,7 +161,7 @@ function buildDeployArgs(providedArgs, ref, commit, sha, commitOrg, commitRepo)
160161
...addVercelMetadata('githubRepo', context.repo.repo, providedArgs),
161162
...addVercelMetadata('githubCommitOrg', commitOrg, providedArgs),
162163
...addVercelMetadata('githubCommitRepo', commitRepo, providedArgs),
163-
...addVercelMetadata('githubCommitMessage', `"${commit}"`, providedArgs),
164+
...addVercelMetadata('githubCommitMessage', `"${commit.replace(/[\r\n]+/g, ' ').replace(/"/g, '')}"`, providedArgs),
164165
...addVercelMetadata(
165166
'githubCommitRef',
166167
ref.replace('refs/heads/', ''),
@@ -169,17 +170,6 @@ function buildDeployArgs(providedArgs, ref, commit, sha, commitOrg, commitRepo)
169170
]
170171
}
171172

172-
function appendProjectArgs(args, providedArgs) {
173-
const hasProjectArg = providedArgs.some(
174-
arg => arg === '--project' || arg.startsWith('--project='),
175-
)
176-
177-
if (!hasProjectArg && vercelProjectId) {
178-
core.info('using --project flag (personal account fallback)')
179-
args.push('--project', vercelProjectId)
180-
}
181-
}
182-
183173
async function vercelDeploy(ref, commit, sha, commitOrg, commitRepo) {
184174
let myOutput = ''
185175
let myError = ''
@@ -204,10 +194,6 @@ async function vercelDeploy(ref, commit, sha, commitOrg, commitRepo) {
204194

205195
const args = buildDeployArgs(providedArgs, ref, commit, sha, commitOrg, commitRepo)
206196

207-
if (vercelProjectId && !vercelOrgId) {
208-
appendProjectArgs(args, providedArgs)
209-
}
210-
211197
if (vercelScope) {
212198
core.info('using scope')
213199
args.push('--scope', vercelScope)
@@ -227,18 +213,23 @@ async function vercelDeploy(ref, commit, sha, commitOrg, commitRepo) {
227213
}
228214
core.warning(
229215
'Vercel CLI rejected the org ID as a personal account scope. '
230-
+ 'Retrying without VERCEL_ORG_ID using --project flag instead.',
216+
+ 'Retrying without VERCEL_ORG_ID (VERCEL_PROJECT_ID is still set).',
231217
)
232-
core.exportVariable('VERCEL_ORG_ID', '')
233218
delete process.env.VERCEL_ORG_ID
234219

220+
const originalOutput = myOutput
221+
const originalError = myError
235222
myOutput = ''
236223
myError = ''
237224
const retryArgs = buildDeployArgs(providedArgs, ref, commit, sha, commitOrg, commitRepo)
238-
appendProjectArgs(retryArgs, providedArgs)
239225
// Don't re-add --scope on retry — it may have caused the personal account error
240226

241227
exitCode = await exec.exec('npx', [vercelBin, ...retryArgs], options)
228+
229+
if (exitCode !== 0) {
230+
core.error(`Original attempt output:\n${originalOutput}`)
231+
core.error(`Original attempt errors:\n${originalError}`)
232+
}
242233
}
243234

244235
if (exitCode !== 0) {

0 commit comments

Comments
 (0)