Skip to content

Commit cef8c07

Browse files
(Minor) Provide VERCEL_ALIASES_CREATED env variable (#12)
Co-authored-by: Hugo MARTIN <hugo.martin.69@gmail.com>
1 parent 3e71d3e commit cef8c07

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

.github/workflows/run-example-deployment.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ jobs:
1919
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
2020

2121
- run: "echo \"Found deployment url: ${{ env.VERCEL_DEPLOYMENT_URL }}\""
22+
- run: "echo \"Created aliases ${{ env.VERCEL_ALIASES_CREATED }}\""
23+
- run: "echo \"Created aliases (full) ${{ env.VERCEL_ALIASES_CREATED_FULL }}\""
24+
25+
- run: "echo \"Alias markdown generated: ${{ env.VERCEL_ALIASES_CREATED_URLS_MD }}\""

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ The below variables are available as outputs, but are also **injected as environ
8282
- `VERCEL_DEPLOYMENT_URL`: Full Vercel deployment url (parsed from the deployment logs), e.g: `https://xxx.vercel.app`
8383
- `VERCEL_DEPLOYMENT_DOMAIN`: Url without the protocol declaration, e.g: `xxx.vercel.app`
8484
- `VERCEL_ALIASES_ERROR`: _(optional)_ Vercel errors during domain aliasing
85-
85+
- `VERCEL_ALIASES_CREATED`: List of aliases created successfully, as a string separated by `, ` for each alias
86+
- `VERCEL_ALIASES_CREATED_FULL`: List of aliases created successfully, as a JSON array containing the Vercel's response
8687
> Hint: You can use `${{ env.VERCEL_DEPLOYMENT_URL }}` in you GitHub Action to read the deployment URL, after the action has run.
8788

8889
## :hugs: Community examples :heart:

lib/vercel.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,23 @@ const createAliases = (deploymentUrl, customDeploymentFile, failIfAliasNotLinked
9999
core.debug(`Resolving alias promises`);
100100
const aliasesResponse = yield Promise.all(aliasCreationPromises);
101101
core.debug(`Alias creation response: ${JSON.stringify(aliasesResponse)}`);
102-
if (aliasesResponse.filter((response) => response.error).length > 0) {
102+
const aliasesErrors = aliasesResponse.filter((response) => response.error);
103+
const aliasesSucceeded = aliasesResponse.filter((response) => !response.error);
104+
if (aliasesErrors.length > 0) {
103105
const failedAliases = aliasesResponse.filter((response) => response.error).map((response) => response.error);
104106
const message = `Got following errors: ${JSON.stringify(failedAliases)}`;
105107
failIfAliasNotLinked ? core.setFailed(message) : core.warning(message);
106108
core.debug(`Exporting this error...`);
107109
core.setOutput('VERCEL_ALIASES_ERROR', failedAliases);
108110
}
109-
for (const alias of aliasesResponse.filter((response) => !response.error)) {
110-
core.debug(`Created alias ${alias}`);
111+
for (const aliasSuccess of aliasesSucceeded) {
112+
core.debug(`Created alias "${aliasSuccess === null || aliasSuccess === void 0 ? void 0 : aliasSuccess.alias}".`);
111113
}
114+
const aliasesUrlsMarkdown = aliasesSucceeded.map((aliasSuccess) => `[aliasSuccess.alias](https://aliasSuccess.alias)`).join(', ');
115+
core.setOutput('VERCEL_ALIASES_CREATED', aliasesSucceeded);
116+
core.exportVariable('VERCEL_ALIASES_CREATED', aliasesSucceeded.map((aliasSuccess) => aliasSuccess.alias).join(', '));
117+
core.setOutput('VERCEL_ALIASES_CREATED_URLS_MD', aliasesUrlsMarkdown);
118+
core.exportVariable('VERCEL_ALIASES_CREATED_URLS_MD', aliasesUrlsMarkdown);
112119
}
113120
else {
114121
core.warning(`No "alias" key found in ${vercelConfigFile}`);
@@ -118,7 +125,7 @@ const createAliases = (deploymentUrl, customDeploymentFile, failIfAliasNotLinked
118125
core.setFailed(`You asked to link aliases but we cannot access to vercel config file "${vercelConfigFile}". Deployment succeeded but no aliases has been created.`);
119126
}
120127
});
121-
const deploy = (command, deployAlias, failIfAliasNotLinked) => __awaiter(void 0, void 0, void 0, function* () {
128+
const deploy = (command, applyDomainAliases, failIfAliasNotLinked) => __awaiter(void 0, void 0, void 0, function* () {
122129
var _a, _b, _c;
123130
/**
124131
* Executes the command provided and stores it into a variable, so we can parse the output and extract metadata from it.
@@ -164,7 +171,7 @@ const deploy = (command, deployAlias, failIfAliasNotLinked) => __awaiter(void 0,
164171
core.debug(`VERCEL_DEPLOYMENT_DOMAIN=${deploymentDomain}`);
165172
core.exportVariable('VERCEL_DEPLOYMENT_DOMAIN', deploymentDomain);
166173
core.setOutput('VERCEL_DEPLOYMENT_DOMAIN', deploymentDomain);
167-
if (deployAlias) {
174+
if (applyDomainAliases) {
168175
yield createAliases(deploymentUrl, customDeploymentFile, failIfAliasNotLinked);
169176
}
170177
}

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type VercelAliasResponse = {
3333
uid?: string;
3434
alias?: string;
3535
created?: string;
36+
oldDeploymentId?: string;
3637
}
3738

3839
/**
@@ -48,4 +49,4 @@ export type GenericObject<T = unknown> = Record<string, T>;
4849
export type ExecCommandOutput = {
4950
stdout: string;
5051
stderr: string;
51-
}
52+
}

src/vercel.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ const createAliases = async (deploymentUrl: string, customDeploymentFile: string
9393

9494
const aliasesResponse: VercelAliasResponse[] = await Promise.all<VercelAliasResponse>(aliasCreationPromises);
9595
core.debug(`Alias creation response: ${JSON.stringify(aliasesResponse)}`);
96+
const aliasesErrors = aliasesResponse.filter((response: VercelAliasResponse) => response.error);
97+
const aliasesSucceeded = aliasesResponse.filter((response: VercelAliasResponse) => !response.error);
9698

97-
if (aliasesResponse.filter((response) => response.error).length > 0) {
99+
if (aliasesErrors.length > 0) {
98100
const failedAliases: (VercelAliasResponseError | undefined)[] = aliasesResponse.filter((response: VercelAliasResponse) => response.error).map((response) => response.error);
99101
const message = `Got following errors: ${JSON.stringify(failedAliases)}`;
100102

@@ -103,9 +105,18 @@ const createAliases = async (deploymentUrl: string, customDeploymentFile: string
103105
core.setOutput('VERCEL_ALIASES_ERROR', failedAliases);
104106
}
105107

106-
for (const alias of aliasesResponse.filter((response) => !response.error)) {
107-
core.debug(`Created alias ${alias}`);
108+
for (const aliasSuccess of aliasesSucceeded) {
109+
core.debug(`Created alias "${aliasSuccess?.alias}".`);
108110
}
111+
112+
const aliasesUrlsMarkdown: string = aliasesSucceeded.map((aliasSuccess) => `[${aliasSuccess?.alias}](https://${aliasSuccess?.alias})`).join(', ');
113+
114+
core.setOutput('VERCEL_ALIASES_CREATED', aliasesSucceeded);
115+
core.exportVariable('VERCEL_ALIASES_CREATED', aliasesSucceeded.map((aliasSuccess) => aliasSuccess?.alias).join(', '));
116+
117+
core.setOutput('VERCEL_ALIASES_CREATED_URLS_MD', aliasesUrlsMarkdown);
118+
core.exportVariable('VERCEL_ALIASES_CREATED_URLS_MD', aliasesUrlsMarkdown);
119+
109120
} else {
110121
core.warning(`No "alias" key found in ${vercelConfigFile}`);
111122
}
@@ -114,7 +125,7 @@ const createAliases = async (deploymentUrl: string, customDeploymentFile: string
114125
}
115126
};
116127

117-
const deploy = async (command: string, deployAlias: boolean, failIfAliasNotLinked: boolean): Promise<void> => {
128+
const deploy = async (command: string, applyDomainAliases: boolean, failIfAliasNotLinked: boolean): Promise<void> => {
118129
/**
119130
* Executes the command provided and stores it into a variable, so we can parse the output and extract metadata from it.
120131
*
@@ -166,7 +177,7 @@ const deploy = async (command: string, deployAlias: boolean, failIfAliasNotLinke
166177
core.exportVariable('VERCEL_DEPLOYMENT_DOMAIN', deploymentDomain);
167178
core.setOutput('VERCEL_DEPLOYMENT_DOMAIN', deploymentDomain);
168179

169-
if (deployAlias) {
180+
if (applyDomainAliases) {
170181
await createAliases(deploymentUrl, customDeploymentFile, failIfAliasNotLinked);
171182
}
172183
} else {

0 commit comments

Comments
 (0)