Skip to content

Commit

Permalink
feat: Vercel Metadata Override (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgosiak authored Mar 8, 2022
1 parent 675e62e commit e871873
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 45 deletions.
58 changes: 36 additions & 22 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,21 @@ async function setEnv() {
}
}

function addVercelMetadata(key, value, providedArgs) {
// returns a list for the metadata commands if key was not supplied by user in action parameters
// returns an empty list if key was provided by user
const pattern = `^${key}=.+`;
const metadataRegex = new RegExp(pattern, 'g');
// eslint-disable-next-line no-restricted-syntax
for (const arg of providedArgs) {
if (arg.match(metadataRegex)) {
return [];
}
}

return ['-m', `${key}=${value}`];
}

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

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

const args = [
...vercelArgs.split(/ +/),
'-t',
vercelToken,
'-m',
`githubCommitSha=${context.sha}`,
'-m',
`githubCommitAuthorName=${context.actor}`,
'-m',
`githubCommitAuthorLogin=${context.actor}`,
'-m',
'githubDeployment=1',
'-m',
`githubOrg=${context.repo.owner}`,
'-m',
`githubRepo=${context.repo.repo}`,
'-m',
`githubCommitOrg=${context.repo.owner}`,
'-m',
`githubCommitRepo=${context.repo.repo}`,
'-m',
`githubCommitMessage=${commit}`,
'-m',
`githubCommitRef=${ref.replace('refs/heads/', '')}`,
...['-t', vercelToken],
...addVercelMetadata('githubCommitSha', context.sha, providedArgs),
...addVercelMetadata('githubCommitAuthorName', context.actor, providedArgs),
...addVercelMetadata(
'githubCommitAuthorLogin',
context.actor,
providedArgs,
),
...addVercelMetadata('githubDeployment', 1, providedArgs),
...addVercelMetadata('githubOrg', context.repo.owner, providedArgs),
...addVercelMetadata('githubRepo', context.repo.repo, providedArgs),
...addVercelMetadata('githubCommitOrg', context.repo.owner, providedArgs),
...addVercelMetadata('githubCommitRepo', context.repo.repo, providedArgs),
...addVercelMetadata('githubCommitMessage', commit, providedArgs),
...addVercelMetadata(
'githubCommitRef',
ref.replace('refs/heads/', ''),
providedArgs,
),
];

if (vercelScope) {
Expand Down
58 changes: 36 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ async function setEnv() {
}
}

function addVercelMetadata(key, value, providedArgs) {
// returns a list for the metadata commands if key was not supplied by user in action parameters
// returns an empty list if key was provided by user
const pattern = `^${key}=.+`;
const metadataRegex = new RegExp(pattern, 'g');
// eslint-disable-next-line no-restricted-syntax
for (const arg of providedArgs) {
if (arg.match(metadataRegex)) {
return [];
}
}

return ['-m', `${key}=${value}`];
}

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

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

const args = [
...vercelArgs.split(/ +/),
'-t',
vercelToken,
'-m',
`githubCommitSha=${context.sha}`,
'-m',
`githubCommitAuthorName=${context.actor}`,
'-m',
`githubCommitAuthorLogin=${context.actor}`,
'-m',
'githubDeployment=1',
'-m',
`githubOrg=${context.repo.owner}`,
'-m',
`githubRepo=${context.repo.repo}`,
'-m',
`githubCommitOrg=${context.repo.owner}`,
'-m',
`githubCommitRepo=${context.repo.repo}`,
'-m',
`githubCommitMessage=${commit}`,
'-m',
`githubCommitRef=${ref.replace('refs/heads/', '')}`,
...['-t', vercelToken],
...addVercelMetadata('githubCommitSha', context.sha, providedArgs),
...addVercelMetadata('githubCommitAuthorName', context.actor, providedArgs),
...addVercelMetadata(
'githubCommitAuthorLogin',
context.actor,
providedArgs,
),
...addVercelMetadata('githubDeployment', 1, providedArgs),
...addVercelMetadata('githubOrg', context.repo.owner, providedArgs),
...addVercelMetadata('githubRepo', context.repo.repo, providedArgs),
...addVercelMetadata('githubCommitOrg', context.repo.owner, providedArgs),
...addVercelMetadata('githubCommitRepo', context.repo.repo, providedArgs),
...addVercelMetadata('githubCommitMessage', commit, providedArgs),
...addVercelMetadata(
'githubCommitRef',
ref.replace('refs/heads/', ''),
providedArgs,
),
];

if (vercelScope) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"email": "[email protected]",
"url": "https://amond.dev"
},
"version": "20.0.0",
"version": "20.0.1",
"main": "index.js",
"scripts": {
"lint": "eslint index.js",
Expand Down

4 comments on commit e871873

@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-o7sv8qx1s-amond.vercel.app
https://master.static.vercel-action.amond.dev

Built with commit e871873.
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 team-scope-test ready!

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

Built with commit e871873.
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 express-basic-auth ready!

✅ Preview
https://express-basic-auth-h60qjqt19-amond.vercel.app

Built with commit e871873.
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-angular ready!

✅ Preview
https://zeit-now-deployment-action-example-angular-b1smllj9s-amond.vercel.app

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

Please sign in to comment.