@@ -18,7 +18,7 @@ import { exec } from "@actions/exec";
1818
1919export type SiteDeploy = {
2020 site : string ;
21- target : string | undefined ;
21+ target ? : string ;
2222 url : string ;
2323 expireTime : string ;
2424} ;
@@ -36,33 +36,47 @@ export type ChannelSuccessResult = {
3636export type ProductionSuccessResult = {
3737 status : "success" ;
3838 result : {
39- hosting : string ;
39+ hosting : string | string [ ] ;
4040 } ;
4141} ;
4242
4343export type DeployConfig = {
4444 projectId : string ;
4545 expires : string ;
4646 channelId : string ;
47- target : string ;
47+ target ? : string ;
4848} ;
4949
50- export type productionDeployConfig = {
50+ export type ProductionDeployConfig = {
5151 projectId : string ;
5252 target ?: string ;
5353} ;
5454
55+ export function interpretChannelDeployResult (
56+ deployResult : ChannelSuccessResult
57+ ) : { expireTime : string ; urls : string [ ] } {
58+ const allSiteResults = Object . values ( deployResult . result ) ;
59+
60+ const expireTime = allSiteResults [ 0 ] . expireTime ;
61+ const urls = allSiteResults . map ( ( siteResult ) => siteResult . url ) ;
62+
63+ return {
64+ expireTime,
65+ urls,
66+ } ;
67+ }
68+
5569async function execWithCredentials (
56- firebase ,
5770 args : string [ ] ,
5871 projectId ,
5972 gacFilename ,
6073 debug : boolean = false
6174) {
6275 let deployOutputBuf : Buffer [ ] = [ ] ;
76+
6377 try {
6478 await exec (
65- firebase ,
79+ "npx firebase-tools" ,
6680 [
6781 ...args ,
6882 ...( projectId ? [ "--project" , projectId ] : [ ] ) ,
@@ -91,7 +105,7 @@ async function execWithCredentials(
91105 console . log (
92106 "Retrying deploy with the --debug flag for better error output"
93107 ) ;
94- return execWithCredentials ( firebase , args , projectId , gacFilename , true ) ;
108+ await execWithCredentials ( args , projectId , gacFilename , true ) ;
95109 } else {
96110 throw e ;
97111 }
@@ -102,11 +116,13 @@ async function execWithCredentials(
102116 : "" ; // output from the CLI
103117}
104118
105- export async function deploy ( gacFilename : string , deployConfig : DeployConfig ) {
106- const { projectId, expires, channelId, target } = deployConfig ;
119+ export async function deployPreview (
120+ gacFilename : string ,
121+ deployConfig : DeployConfig
122+ ) {
123+ const { projectId, channelId, target, expires } = deployConfig ;
107124
108125 const deploymentText = await execWithCredentials (
109- "npx firebase-tools" ,
110126 [
111127 "hosting:channel:deploy" ,
112128 channelId ,
@@ -117,7 +133,7 @@ export async function deploy(gacFilename: string, deployConfig: DeployConfig) {
117133 gacFilename
118134 ) ;
119135
120- const deploymentResult = JSON . parse ( deploymentText ) as
136+ const deploymentResult = JSON . parse ( deploymentText . trim ( ) ) as
121137 | ChannelSuccessResult
122138 | ErrorResult ;
123139
@@ -126,12 +142,11 @@ export async function deploy(gacFilename: string, deployConfig: DeployConfig) {
126142
127143export async function deployProductionSite (
128144 gacFilename ,
129- productionDeployConfig : productionDeployConfig
145+ productionDeployConfig : ProductionDeployConfig
130146) {
131147 const { projectId, target } = productionDeployConfig ;
132148
133149 const deploymentText = await execWithCredentials (
134- "npx firebase-tools" ,
135150 [ "deploy" , "--only" , `hosting${ target ? ":" + target : "" } ` ] ,
136151 projectId ,
137152 gacFilename
0 commit comments