Skip to content

Commit

Permalink
feat: allow spaces in vercel-args (#237)
Browse files Browse the repository at this point in the history
* feat: allow spaces in vercel-args

* fix: vercel args spliting

* fix: quotes selection

* chore: remove debug print
  • Loading branch information
skyf0l authored Oct 14, 2023
1 parent 7749da0 commit f790839
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
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

3 comments on commit f790839

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for team-scope-test ready!

✅ Preview
https://team-scope-test-oargfanz0-dietfriends.vercel.app

Built with commit f790839.
This pull request is being automatically deployed with vercel-action

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for zeit-now-deployment-action-example-static ready!

✅ Preview
https://zeit-now-deployment-action-example-static-fdqkupgbd-amond.vercel.app
https://master.static.vercel-action.amond.dev

Built with commit f790839.
This pull request is being automatically deployed with vercel-action

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for vercel-action-example-nextjs ready!

✅ Preview
https://vercel-action-example-nextjs-lmaq13vct-amond.vercel.app
https://master.nextjs.vercel-action.amond.dev

Built with commit f790839.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.