diff --git a/bin/action.min.js b/bin/action.min.js index 3530b852..d263a08e 100644 --- a/bin/action.min.js +++ b/bin/action.min.js @@ -93151,6 +93151,17 @@ async function postChannelSuccessComment(github, context, result, commit) { core.endGroup(); } +function getProjectIdByAlias(alias) { + try { + const firebaserc = JSON.parse(fs.readFileSync(".firebaserc", { + encoding: 'utf-8' + })); + return firebaserc.projects[alias]; + } catch (e) { + return undefined; + } +} + /** * Copyright 2020 Google LLC * @@ -93216,7 +93227,9 @@ async function run() { throw Error(deployment.error); } core.endGroup(); - const hostname = target ? `${target}.web.app` : `${projectId}.web.app`; + // ProjectId may be an alias. Try to get the real project id from .firebaserc + const parsedProjectId = getProjectIdByAlias(projectId) || projectId; + const hostname = target ? `${target}.web.app` : `${parsedProjectId}.web.app`; const url = `https://${hostname}/`; await finish({ details_url: url, @@ -93226,6 +93239,9 @@ async function run() { summary: `[${hostname}](${url})` } }); + core.setOutput("urls", [url]); + core.setOutput("expire_time", undefined); + core.setOutput("details_url", url); return; } const channelId = getChannelId(configuredChannelId, github.context); diff --git a/src/getProjectIdByAlias.ts b/src/getProjectIdByAlias.ts new file mode 100644 index 00000000..7878248c --- /dev/null +++ b/src/getProjectIdByAlias.ts @@ -0,0 +1,10 @@ +import { readFileSync } from "fs"; + +export function getProjectIdByAlias(alias: string): string { + try { + const firebaserc = JSON.parse(readFileSync(".firebaserc", { encoding: 'utf-8' })); + return firebaserc.projects[alias]; + } catch (e) { + return undefined; + } +} diff --git a/src/index.ts b/src/index.ts index ef90f2db..749f5ff7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,6 +36,7 @@ import { getURLsMarkdownFromChannelDeployResult, postChannelSuccessComment, } from "./postOrUpdateComment"; +import { getProjectIdByAlias } from "./getProjectIdByAlias"; // Inputs defined in action.yml const expires = getInput("expires"); @@ -99,8 +100,13 @@ async function run() { } endGroup(); - const hostname = target ? `${target}.web.app` : `${projectId}.web.app`; + // ProjectId may be an alias. Try to get the real project id from .firebaserc + const parsedProjectId = getProjectIdByAlias(projectId) || projectId; + const hostname = target + ? `${target}.web.app` + : `${parsedProjectId}.web.app`; const url = `https://${hostname}/`; + await finish({ details_url: url, conclusion: "success", @@ -109,6 +115,11 @@ async function run() { summary: `[${hostname}](${url})`, }, }); + + setOutput("urls", [url]); + setOutput("expire_time", undefined); + setOutput("details_url", url); + return; }