From 235cf3a64129216e8a91ba7cfe581f7c841ca2b4 Mon Sep 17 00:00:00 2001 From: Gustavo Lopes Date: Thu, 17 Aug 2023 11:01:25 -0300 Subject: [PATCH 1/3] Fix invalid url when being referenced by project id alias Closes FirebaseExtended/action-hosting-deploy#213 --- bin/action.min.js | 15 ++++++++++++++- src/getProjectIdByAlias.ts | 10 ++++++++++ src/index.ts | 6 +++++- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/getProjectIdByAlias.ts diff --git a/bin/action.min.js b/bin/action.min.js index 3530b852..9e374d5c 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`; + // Try to get the project id from an project alias + const parsedProjectId = getProjectIdByAlias(projectId) || projectId; + const hostname = target ? `${target}.web.app` : `${parsedProjectId}.web.app`; const url = `https://${hostname}/`; await finish({ details_url: url, 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..ccf0312d 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,11 @@ async function run() { } endGroup(); - const hostname = target ? `${target}.web.app` : `${projectId}.web.app`; + // Try to get the project id from an project alias + 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", From a9f4f5a233e71eb88b2b99c9427419e5ad580d75 Mon Sep 17 00:00:00 2001 From: Gustavo Lopes Date: Thu, 17 Aug 2023 11:52:16 -0300 Subject: [PATCH 2/3] Run format script --- src/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index ccf0312d..5f36e16c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -100,9 +100,11 @@ async function run() { } endGroup(); - // Try to get the project id from an project alias + // 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 hostname = target + ? `${target}.web.app` + : `${parsedProjectId}.web.app`; const url = `https://${hostname}/`; await finish({ From 59b8e1d97740f0cd9afac807a120d8d57235e4ad Mon Sep 17 00:00:00 2001 From: Gustavo Lopes Date: Thu, 17 Aug 2023 12:16:22 -0300 Subject: [PATCH 3/3] Add output to live deploy --- bin/action.min.js | 5 ++++- src/index.ts | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/action.min.js b/bin/action.min.js index 9e374d5c..d263a08e 100644 --- a/bin/action.min.js +++ b/bin/action.min.js @@ -93227,7 +93227,7 @@ async function run() { throw Error(deployment.error); } core.endGroup(); - // Try to get the project id from an project alias + // 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}/`; @@ -93239,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/index.ts b/src/index.ts index 5f36e16c..749f5ff7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -115,6 +115,11 @@ async function run() { summary: `[${hostname}](${url})`, }, }); + + setOutput("urls", [url]); + setOutput("expire_time", undefined); + setOutput("details_url", url); + return; }