Skip to content

Commit fe04d8e

Browse files
committed
Implemented a mock workflow to test in local dev
1 parent 2252526 commit fe04d8e

20 files changed

+939
-40
lines changed

.env.example

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Token to be use during `yarn test:integration`
2+
VERCEL_TOKEN=XXX
3+
4+
# Deployment link than you own to use during `yarn test:integration`.
5+
# This allows you to test your code in local without any other project beside.
6+
# This variable is used to test aliases linking
7+
# For example: https://some-app.vercel.app
8+
VERCEL_DEPLOYMENT_URL=XXX
9+
10+
# If you need to link aliases to VERCEL_DEPLOYMENT_URL
11+
# default value is true but it's not required
12+
INPUT_APPLY_DOMAIN_ALIASES=true
13+
14+
# default value is false but it's not required
15+
INPUT_FAILIFALIASNOTLINKED=true
16+
17+
# Custom command to exec in local development
18+
# By default, it involves `yarn mocks:display` which use:
19+
# "export $(cat .env | xargs)" to retrieve informations needed to config mocks from dotenv.
20+
# "envsubst < mocks/deployment.txt" apply environment to the mock file.
21+
# This proccess allows us to use 'echo' command instead of a real vercel deploy, which can be few long minutes.
22+
INPUT_COMMAND="echo $(yarn mocks:display)"

lib/vercel.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ const node_fetch_1 = __importDefault(require("node-fetch"));
3737
const config_1 = require("./config");
3838
const exec = require('@actions/exec');
3939
const glob = require('@actions/glob');
40+
const generate_alias_promises = (deploymentId, teamId, aliases) => {
41+
let aliasCreationPromises = [];
42+
for (const alias of aliases) {
43+
console.log(`Creating alias ${alias}`);
44+
aliasCreationPromises.push(node_fetch_1.default(`https://api.vercel.com/v2/now/deployments/${deploymentId}/aliases?teamId=${teamId}`, {
45+
headers: {
46+
Authorization: `Bearer ${process.env.VERCEL_TOKEN}`,
47+
"Content-Type": "application/json"
48+
},
49+
body: JSON.stringify({
50+
alias: alias
51+
}),
52+
method: 'POST'
53+
}).then(data => data.json()));
54+
}
55+
return aliasCreationPromises;
56+
};
4057
const exec_command = (command) => __awaiter(void 0, void 0, void 0, function* () {
4158
/**
4259
* When we execute a program, it writes on two outputs : standard and error.
@@ -66,7 +83,7 @@ const create_aliases = (deploymentUrl, customDeploymentFile, failIfAliasNotLinke
6683
* It helps us to find the absolute path for a file. Indeed, because we don't know where the action will be run and we need to find this file, wherever it is.
6784
*/
6885
const globber = yield glob.create(customDeploymentFile);
69-
const vercelConfigFile = (yield globber.glob())[0] || config_1.VERCEL_CONFIG_FILE;
86+
const vercelConfigFile = (yield globber.glob())[0];
7087
if (vercelConfigFile && fs_1.default.existsSync(vercelConfigFile)) {
7188
core.debug(`Found custom config file: ${vercelConfigFile}`);
7289
core.debug(`Found real path: ${vercelConfigFile}`);
@@ -78,27 +95,14 @@ const create_aliases = (deploymentUrl, customDeploymentFile, failIfAliasNotLinke
7895
},
7996
method: 'GET'
8097
}).then(data => data.json()));
81-
let aliasCreationPromises = [];
82-
for (const alias of vercelConfig.alias) {
83-
console.log(`Creating alias ${alias}`);
84-
aliasCreationPromises.push(node_fetch_1.default(`https://api.vercel.com/v2/now/deployments/${id}/aliases?teamId=${ownerId}`, {
85-
headers: {
86-
Authorization: `Bearer ${process.env.VERCEL_TOKEN}`,
87-
"Content-Type": "application/json"
88-
},
89-
body: JSON.stringify({
90-
alias: alias
91-
}),
92-
method: 'POST'
93-
}).then(data => data.json()));
94-
}
98+
const aliasCreationPromises = generate_alias_promises(id, ownerId, vercelConfig.alias);
9599
core.debug(`Resolving alias promises`);
96100
const aliasesResponse = yield Promise.all(aliasCreationPromises);
97-
console.log(`Alias creation response: ${aliasesResponse}`);
98-
if (failIfAliasNotLinked && aliasesResponse) {
101+
console.log(`Alias creation response: ${JSON.stringify(aliasesResponse)}`);
102+
if (aliasesResponse.filter(response => response.error)) {
99103
const failedAliases = aliasesResponse.filter((response) => response.error).map((response) => response.error);
100-
core.setFailed(`Got following errors: ${JSON.stringify(failedAliases)}`);
101-
return;
104+
const message = `Got following errors: ${JSON.stringify(failedAliases)}`;
105+
failIfAliasNotLinked ? core.setFailed(message) : core.warning(message);
102106
}
103107
for (const alias of aliasesResponse.filter(response => !response.error)) {
104108
console.log(`Created alias ${alias}`);
@@ -138,7 +142,7 @@ const deploy = (command, deployAlias, failIfAliasNotLinked) => __awaiter(void 0,
138142
* split isolates the json file
139143
* find automatically finds the matching json file
140144
*/
141-
const customDeploymentFile = (_c = (_b = stdout.match(/--local-config=.[^$]+?.json/gs)) === null || _b === void 0 ? void 0 : _b.shift()) === null || _c === void 0 ? void 0 : _c.split("=").find(el => el.endsWith(".json"));
145+
const customDeploymentFile = ((_c = (_b = stdout.match(/--local-config=.[^$]+?.json/gs)) === null || _b === void 0 ? void 0 : _b.shift()) === null || _c === void 0 ? void 0 : _c.split("=").find(el => el.endsWith(".json"))) || config_1.VERCEL_CONFIG_FILE;
142146
core.debug(`Command: ${command}`);
143147
core.debug(`Custom deploy file: ${customDeploymentFile}`);
144148
if (deploymentUrl) {

mocks/deployment.txt

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
> [debug] [2021-02-24T12:09:54.756Z] Found config in provided --local-config path /home/runner/work/next-right-now/next-right-now/vercel.json
2+
Vercel CLI 21.2.3
3+
> [debug] [2021-02-24T12:09:54.769Z] user supplied a possible target for deployment
4+
> [debug] [2021-02-24T12:09:54.788Z] GET https://api.vercel.com/www/user
5+
> [debug] [2021-02-24T12:09:55.038Z] GET https://api.vercel.com/www/user : 250.112ms
6+
> [debug] [2021-02-24T12:09:55.043Z] GET https://api.vercel.com/v1/teams?
7+
> [debug] [2021-02-24T12:09:55.361Z] GET https://api.vercel.com/v1/teams? : 317.289ms
8+
> [debug] [2021-02-24T12:09:55.420Z] GET https://api.vercel.com/teams/team_qnVfSEVc2WwmOE1OYhZr4VST?teamId=team_qnVfSEVc2WwmOE1OYhZr4VST
9+
> [debug] [2021-02-24T12:09:55.659Z] GET https://api.vercel.com/teams/team_qnVfSEVc2WwmOE1OYhZr4VST?teamId=team_qnVfSEVc2WwmOE1OYhZr4VST : 237.81ms
10+
> [debug] [2021-02-24T12:09:55.664Z] Spinner stopped (Loading scopes…)
11+
> [debug] [2021-02-24T12:09:55.664Z] Spinner invoked (Loading scopes…) with a 1000ms delay
12+
> [debug] [2021-02-24T12:09:55.665Z] GET https://api.vercel.com/v1/teams?
13+
> [debug] [2021-02-24T12:09:55.899Z] GET https://api.vercel.com/v1/teams? : 234.18ms
14+
> [debug] [2021-02-24T12:09:55.906Z] Spinner stopped (Searching for existing projects…)
15+
> [debug] [2021-02-24T12:09:55.906Z] Spinner invoked (Searching for existing projects…) with a 1000ms delay
16+
> [debug] [2021-02-24T12:09:55.908Z] GET https://api.vercel.com/projects/nrn-v2-mst-aptd-at-lcz-sty-c1?teamId=team_qnVfSEVc2WwmOE1OYhZr4VST
17+
> [debug] [2021-02-24T12:09:56.237Z] GET https://api.vercel.com/projects/nrn-v2-mst-aptd-at-lcz-sty-c1?teamId=team_qnVfSEVc2WwmOE1OYhZr4VST : 328.696ms
18+
Linked to unly-oss/nrn-v2-mst-aptd-at-lcz-sty-c1 (created .vercel)
19+
The name property in vercel.json is deprecated (https://vercel.link/name-prop)
20+
> [debug] [2021-02-24T12:09:56.244Z] Spinner stopped (Deploying unly-oss/nrn-v2-mst-aptd-at-lcz-sty-c1)
21+
> [debug] [2021-02-24T12:09:56.244Z] Spinner invoked (Deploying unly-oss/nrn-v2-mst-aptd-at-lcz-sty-c1) with a 0ms delay
22+
[now-client-debug] 2021-02-24T12:09:56.245Z Creating deployment...
23+
[now-client-debug] 2021-02-24T12:09:56.245Z Provided 'path' is a directory. Reading subpaths...
24+
[now-client-debug] 2021-02-24T12:09:56.246Z Read 43 subpaths
25+
[now-client-debug] 2021-02-24T12:09:56.253Z Found 25 rules in .vercelignore
26+
[now-client-debug] 2021-02-24T12:09:56.253Z Building file tree...
27+
[now-client-debug] 2021-02-24T12:09:56.309Z Found 448 files in the specified directory
28+
[now-client-debug] 2021-02-24T12:09:56.346Z Yielding a 'hashes-calculated' event with 447 hashes
29+
[now-client-debug] 2021-02-24T12:09:56.347Z Using provided API URL: https://api.vercel.com
30+
[now-client-debug] 2021-02-24T12:09:56.347Z Using provided user agent: vercel 21.2.3 node-v14.15.5 linux (x64)
31+
[now-client-debug] 2021-02-24T12:09:56.347Z Setting platform version to harcoded value 2
32+
[now-client-debug] 2021-02-24T12:09:56.347Z Creating the deployment and starting upload...
33+
[now-client-debug] 2021-02-24T12:09:56.348Z Determining necessary files for upload...
34+
[now-client-debug] 2021-02-24T12:09:56.348Z Creating deployment
35+
[now-client-debug] 2021-02-24T12:09:56.353Z Sending deployment creation API request
36+
[now-client-debug] 2021-02-24T12:09:57.316Z Deployment response: {"error":{"code":"missing_files","message":"Missing files","missing":["10cf212bcc0b16787d58258f8e5d1e2a9627afc7","7d36448f860e47e36ef7350dac6496b3f3577056","d9d09922e1278f2c54964db685fd6c4162b147a5"]}}
37+
[now-client-debug] 2021-02-24T12:09:57.316Z Error: Deployment request status is 400
38+
[now-client-debug] 2021-02-24T12:09:57.316Z 3 files are required to upload
39+
[now-client-debug] 2021-02-24T12:09:57.316Z Yielding a 'file-count' event
40+
> [debug] [2021-02-24T12:09:57.316Z] Total files 447, 3 changed
41+
[now-client-debug] 2021-02-24T12:09:57.317Z Building an upload list...
42+
[now-client-debug] 2021-02-24T12:09:57.317Z Starting upload
43+
[now-client-debug] 2021-02-24T12:09:57.318Z POST https://api.vercel.com/v2/now/files?teamId=team_qnVfSEVc2WwmOE1OYhZr4VST
44+
[now-client-debug] 2021-02-24T12:09:57.319Z POST https://api.vercel.com/v2/now/files?teamId=team_qnVfSEVc2WwmOE1OYhZr4VST
45+
[now-client-debug] 2021-02-24T12:09:57.320Z POST https://api.vercel.com/v2/now/files?teamId=team_qnVfSEVc2WwmOE1OYhZr4VST
46+
[now-client-debug] 2021-02-24T12:09:58.042Z DONE in 724ms: POST https://api.vercel.com/v2/now/files?teamId=team_qnVfSEVc2WwmOE1OYhZr4VST
47+
[now-client-debug] 2021-02-24T12:09:58.042Z File 10cf212bcc0b16787d58258f8e5d1e2a9627afc7 (/home/runner/work/next-right-now/next-right-now/.github/workflows/deploy-vercel-staging.yml) uploaded
48+
[now-client-debug] 2021-02-24T12:09:58.042Z Yielding a 'file-uploaded' event
49+
> [debug] [2021-02-24T12:09:58.043Z] Uploaded: /home/runner/work/next-right-now/next-right-now/.github/workflows/deploy-vercel-staging.yml (25.61KB)
50+
[now-client-debug] 2021-02-24T12:09:58.047Z DONE in 727ms: POST https://api.vercel.com/v2/now/files?teamId=team_qnVfSEVc2WwmOE1OYhZr4VST
51+
[now-client-debug] 2021-02-24T12:09:58.047Z File d9d09922e1278f2c54964db685fd6c4162b147a5 (/home/runner/work/next-right-now/next-right-now/.github/workflows/deploy-vercel-production.yml) uploaded
52+
[now-client-debug] 2021-02-24T12:09:58.047Z Yielding a 'file-uploaded' event
53+
> [debug] [2021-02-24T12:09:58.047Z] Uploaded: /home/runner/work/next-right-now/next-right-now/.github/workflows/deploy-vercel-production.yml (21.8KB)
54+
[now-client-debug] 2021-02-24T12:09:58.055Z DONE in 736ms: POST https://api.vercel.com/v2/now/files?teamId=team_qnVfSEVc2WwmOE1OYhZr4VST
55+
[now-client-debug] 2021-02-24T12:09:58.055Z File 7d36448f860e47e36ef7350dac6496b3f3577056 (/home/runner/work/next-right-now/next-right-now/.github/workflows/deploy-vercel-storybook.yml) uploaded
56+
[now-client-debug] 2021-02-24T12:09:58.055Z Yielding a 'file-uploaded' event
57+
> [debug] [2021-02-24T12:09:58.055Z] Uploaded: /home/runner/work/next-right-now/next-right-now/.github/workflows/deploy-vercel-storybook.yml (15.39KB)
58+
[now-client-debug] 2021-02-24T12:09:58.055Z All files uploaded
59+
[now-client-debug] 2021-02-24T12:09:58.055Z Yielding a 'all-files-uploaded' event
60+
[now-client-debug] 2021-02-24T12:09:58.055Z Starting deployment creation
61+
[now-client-debug] 2021-02-24T12:09:58.055Z Creating deployment
62+
[now-client-debug] 2021-02-24T12:09:58.058Z Sending deployment creation API request
63+
[now-client-debug] 2021-02-24T12:10:00.883Z Deployment response: {"alias":["nrn-v2-mst-aptd-at-lcz-sty-c1-vercel-oss-bot.vercel.app"],"aliasAssigned":false,"bootedAt":1614168598621,"buildingAt":1614168598621,"createdAt":1614168598621,"creator":{"uid":"xdzqiYVb3oFkd6suD0QeNllg","username":"vercel-oss-bot"},"id":"dpl_8uUVXWFzKdE55wtnd55XF7XJo3wu","lambdas":[{"id":"bld_9ex0qz5ng","createdAt":1614168600703,"entrypoint":null,"readyState":"INITIALIZING","readyStateAt":1614168600704,"output":[]}],"name":"nrn-v2-mst-aptd-at-lcz-sty-c1","meta":{},"public":false,"readyState":"QUEUED","regions":["arn1","bom1","bru1","cdg1","cle1","dub1","gru1","hkg1","hnd1","icn1","iad1","lhr1","pdx1","sfo1","sin1","syd1"],"source":"cli","status":"QUEUED","team":{"id":"team_qnVfSEVc2WwmOE1OYhZr4VST","name":"Unly OSS","slug":"unly-oss"},"type":"LAMBDAS","url":"nrn-v2-mst-aptd-at-lcz-sty-c1-7u1iwwx5h-unly-oss.vercel.app","version":2,"build":{"env":["NEXT_PUBLIC_APP_STAGE","NEXT_PUBLIC_NRN_PRESET","NEXT_PUBLIC_CUSTOMER_REF","NEXT_PUBLIC_LOCIZE_PROJECT_ID","NEXT_PUBLIC_AMPLITUDE_API_KEY","AIRTABLE_API_KEY","AIRTABLE_BASE_ID","LOCIZE_API_KEY","SENTRY_DSN","GITHUB_DISPATCH_TOKEN","VERCEL_DEPLOYMENT_COMPLETED_WEBHOOK","GIT_COMMIT_TAGS","GIT_COMMIT_REF","GIT_COMMIT_SHA"]},"builds":[],"createdIn":"sfo1","env":[],"functions":null,"ownerId":"team_qnVfSEVc2WwmOE1OYhZr4VST","plan":"pro","projectId":"Qmdqfj3N1R2kTSZftoxw3pJ5tDfZwE4pYAxnG8cT43k9ME","routes":null,"target":null}
64+
[now-client-debug] 2021-02-24T12:10:00.886Z Deployment created with a notice: To deploy to production, run 'vercel --prod'
65+
[now-client-debug] 2021-02-24T12:10:00.886Z Yielding a 'notice' event
66+
[now-client-debug] 2021-02-24T12:10:00.886Z Deployment created
67+
[now-client-debug] 2021-02-24T12:10:00.887Z Yielding a 'created' event
68+
Inspect: https://vercel.com/unly-oss/nrn-v2-mst-aptd-at-lcz-sty-c1-7u1iwwx5h-unly/oss [5s]
69+
${VERCEL_DEPLOYMENT_URL}> [debug] [2021-02-24T12:10:00.933Z] Spinner stopped (Queued)
70+
> [debug] [2021-02-24T12:10:00.933Z] Spinner invoked (Queued) with a 0ms delay
71+
[now-client-debug] 2021-02-24T12:10:00.933Z Waiting for deployment to be ready...
72+
[now-client-debug] 2021-02-24T12:10:00.933Z Waiting for builds and the deployment to complete...
73+
[now-client-debug] 2021-02-24T12:15:56.518Z Deployment state changed to BUILDING
74+
[now-client-debug] 2021-02-24T12:15:56.518Z Yielding a 'building' event
75+
> [debug] [2021-02-24T12:15:56.518Z] Spinner stopped (Building)
76+
> [debug] [2021-02-24T12:15:56.518Z] Spinner invoked (Building) with a 0ms delay
77+
[now-client-debug] 2021-02-24T12:23:48.307Z Deployment state changed to READY
78+
[now-client-debug] 2021-02-24T12:23:48.307Z Yielding a 'ready' event
79+
> [debug] [2021-02-24T12:23:48.307Z] Spinner stopped (Completing)
80+
> [debug] [2021-02-24T12:23:48.307Z] Spinner invoked (Completing) with a 0ms delay
81+
[now-client-debug] 2021-02-24T12:23:50.022Z Deployment alias assigned
82+
[now-client-debug] 2021-02-24T12:23:50.022Z Deployment is ready
83+
[now-client-debug] 2021-02-24T12:23:50.022Z Yielding a 'alias-assigned' event
84+
> [debug] [2021-02-24T12:23:50.025Z] GET https://api.vercel.com/v10/now/deployments/dpl_8uUVXWFzKdE55wtnd55XF7XJo3wu?teamId=team_qnVfSEVc2WwmOE1OYhZr4VST
85+
> [debug] [2021-02-24T12:23:50.346Z] GET https://api.vercel.com/v10/now/deployments/dpl_8uUVXWFzKdE55wtnd55XF7XJo3wu?teamId=team_qnVfSEVc2WwmOE1OYhZr4VST : 320.867ms
86+
> [debug] [2021-02-24T12:23:50.478Z] Error copying to clipboard: Error: Couldn't find the 'xsel' binary and fallback didn't work. On Debian/Ubuntu you can install xsel with: sudo apt install xsel
87+
Preview: ${VERCEL_DEPLOYMENT_URL} [14m]
88+
To deploy to production, run 'vercel --prod'

node_modules/.yarn-integrity

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)