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: allow spaces in vercel-args #237

Merged
merged 4 commits into from
Oct 14, 2023
Merged
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
24 changes: 22 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,25 @@ function addVercelMetadata(key, value, providedArgs) {
return ['-m', `${key}=${value}`];
}


/**
*
* The following regex is used to split the vercelArgs string into an array of arguments.
* It conserves strings wrapped in simple / double quotes, with nested different quotes, as a single argument.
*
* Example:
*
* parseArgs(`--env foo=bar "foo=bar baz" 'foo="bar baz"'`) => ['--env', 'foo=bar', 'foo=bar baz', 'foo="bar baz"']
*/
function parseArgs(s) {
const args = [];

for (const match of s.matchAll(/'([^']*)'|"([^"]*)"|[^\s]+/gm)) {
args.push(match[1] ?? match[2] ?? match[0]);
}
return args;
}

async function vercelDeploy(ref, commit) {
let myOutput = '';
// eslint-disable-next-line no-unused-vars
Expand All @@ -139,10 +158,10 @@ async function vercelDeploy(ref, commit) {
options.cwd = workingDirectory;
}

const providedArgs = vercelArgs.split(/ +/);
const providedArgs = parseArgs(vercelArgs);

const args = [
...vercelArgs.split(/ +/),
...providedArgs,
...['-t', vercelToken],
...addVercelMetadata('githubCommitSha', context.sha, providedArgs),
...addVercelMetadata('githubCommitAuthorName', context.actor, providedArgs),
Expand Down