@@ -23,7 +23,6 @@ import {
2323} from "@actions/core" ;
2424import { context , getOctokit } from "@actions/github" ;
2525import { existsSync } from "fs" ;
26- import { createCheck } from "./createCheck" ;
2726import { createGacFile } from "./createGACFile" ;
2827import {
2928 deployPreview ,
@@ -44,7 +43,6 @@ const googleApplicationCredentials = getInput("firebaseServiceAccount", {
4443 required : true ,
4544} ) ;
4645const configuredChannelId = getInput ( "channelId" ) ;
47- const isProductionDeploy = configuredChannelId === "live" ;
4846const token = process . env . GITHUB_TOKEN || getInput ( "repoToken" ) ;
4947const octokit = token ? getOctokit ( token ) : undefined ;
5048const entryPoint = getInput ( "entryPoint" ) ;
@@ -53,13 +51,6 @@ const firebaseToolsVersion = getInput("firebaseToolsVersion");
5351const disableComment = getInput ( "disableComment" ) ;
5452
5553async function run ( ) {
56- const isPullRequest = ! ! context . payload . pull_request ;
57-
58- let finish = ( details : Object ) => console . log ( details ) ;
59- if ( token && isPullRequest ) {
60- finish = await createCheck ( octokit , context ) ;
61- }
62-
6354 try {
6455 startGroup ( "Verifying firebase.json exists" ) ;
6556
@@ -75,97 +66,93 @@ async function run() {
7566 if ( existsSync ( "./firebase.json" ) ) {
7667 console . log ( "firebase.json file found. Continuing deploy." ) ;
7768 } else {
78- throw Error (
79- "firebase.json file not found. If your firebase.json file is not in the root of your repo, edit the entryPoint option of this GitHub action."
80- ) ;
69+ console . warn ( "firebase.json file not found. If your firebase.json file is not in the root of your repo, edit the entryPoint option of this GitHub action." ) ;
8170 }
8271 endGroup ( ) ;
8372
8473 startGroup ( "Setting up CLI credentials" ) ;
8574 const gacFilename = await createGacFile ( googleApplicationCredentials ) ;
86- console . log (
87- "Created a temporary file with Application Default Credentials."
88- ) ;
75+ if ( gacFilename != googleApplicationCredentials ) {
76+ console . log (
77+ "Created a temporary file with Application Default Credentials."
78+ ) ;
79+ }
8980 endGroup ( ) ;
9081
91- if ( isProductionDeploy ) {
82+ if ( configuredChannelId === "live" ) {
9283 startGroup ( "Deploying to production site" ) ;
93- const deployment = await deployProductionSite ( gacFilename , {
94- projectId,
95- target,
96- firebaseToolsVersion,
97- } ) ;
98- if ( deployment . status === "error" ) {
99- throw Error ( ( deployment as ErrorResult ) . error ) ;
100- }
84+ await deployToProduction ( gacFilename ) ;
85+ endGroup ( ) ;
86+ } else {
87+ const channelId = getChannelId ( configuredChannelId , context ) ;
88+ startGroup ( `Deploying to Firebase preview channel ${ channelId } ` ) ;
89+ await deployToPreviewChannel ( gacFilename , channelId ) ;
10190 endGroup ( ) ;
102-
103- const hostname = target ? `${ target } .web.app` : `${ projectId } .web.app` ;
104- const url = `https://${ hostname } /` ;
105- await finish ( {
106- details_url : url ,
107- conclusion : "success" ,
108- output : {
109- title : `Production deploy succeeded` ,
110- summary : `[${ hostname } ](${ url } )` ,
111- } ,
112- } ) ;
113- return ;
114- }
115-
116- const channelId = getChannelId ( configuredChannelId , context ) ;
117-
118- startGroup ( `Deploying to Firebase preview channel ${ channelId } ` ) ;
119- const deployment = await deployPreview ( gacFilename , {
120- projectId,
121- expires,
122- channelId,
123- target,
124- firebaseToolsVersion,
125- } ) ;
126-
127- if ( deployment . status === "error" ) {
128- throw Error ( ( deployment as ErrorResult ) . error ) ;
12991 }
130- endGroup ( ) ;
92+ } catch ( e ) {
93+ setFailed ( e . message ) ;
94+ }
95+ return undefined ;
96+ }
13197
132- const { expireTime, expire_time_formatted, urls } =
133- interpretChannelDeployResult ( deployment ) ;
98+ async function deployToProduction ( gacFilePath : string ) {
99+ const deployment = await deployProductionSite ( gacFilePath , {
100+ projectId,
101+ target,
102+ firebaseToolsVersion,
103+ } ) ;
104+ if ( deployment . status === "error" ) {
105+ throw Error ( ( deployment as ErrorResult ) . error ) ;
106+ }
107+ const hostname = target ? `${ target } .web.app` : `${ projectId } .web.app` ;
108+ const url = `https://${ hostname } /` ;
109+ console . log ( {
110+ details_url : url ,
111+ conclusion : "success" ,
112+ output : {
113+ title : `Production deploy succeeded` ,
114+ summary : `[${ hostname } ](${ url } )` ,
115+ } ,
116+ } ) ;
117+ return undefined ;
118+ }
134119
135- setOutput ( "urls" , urls ) ;
136- setOutput ( "expire_time" , expireTime ) ;
137- setOutput ( "expire_time_formatted" , expire_time_formatted ) ;
138- setOutput ( "details_url" , urls [ 0 ] ) ;
120+ async function deployToPreviewChannel ( gacFilePath : string , channelId : string ) {
121+ const deployment = await deployPreview ( gacFilePath , {
122+ projectId,
123+ expires,
124+ channelId,
125+ target,
126+ firebaseToolsVersion,
127+ } ) ;
128+ if ( deployment . status === "error" ) {
129+ throw Error ( ( deployment as ErrorResult ) . error ) ;
130+ }
139131
140- if ( disableComment === "true" ) {
141- console . log (
142- `Commenting on PR is disabled with "disableComment: ${ disableComment } "`
143- ) ;
144- } else if ( token && isPullRequest && ! ! octokit ) {
145- const commitId = context . payload . pull_request ?. head . sha . substring ( 0 , 7 ) ;
132+ const { expireTime, urls } = interpretChannelDeployResult ( deployment ) ;
133+ setOutput ( "urls" , urls ) ;
134+ setOutput ( "expire_time" , expireTime ) ;
135+ setOutput ( "details_url" , urls [ 0 ] ) ;
146136
147- await postChannelSuccessComment ( octokit , context , deployment , commitId ) ;
148- }
137+ const urlsListMarkdown =
138+ urls . length === 1
139+ ? `[${ urls [ 0 ] } ](${ urls [ 0 ] } )`
140+ : urls . map ( ( url ) => `- [${ url } ](${ url } )` ) . join ( "\n" ) ;
149141
150- await finish ( {
151- details_url : urls [ 0 ] ,
152- conclusion : "success" ,
153- output : {
154- title : `Deploy preview succeeded` ,
155- summary : getURLsMarkdownFromChannelDeployResult ( deployment ) ,
156- } ,
157- } ) ;
158- } catch ( e ) {
159- setFailed ( e . message ) ;
142+ if ( token && ! ! context . payload . pull_request && ! ! octokit ) {
143+ const commitId = context . payload . pull_request ?. head . sha . substring ( 0 , 7 ) ;
160144
161- await finish ( {
162- conclusion : "failure" ,
163- output : {
164- title : "Deploy preview failed" ,
165- summary : `Error: ${ e . message } ` ,
166- } ,
167- } ) ;
145+ await postChannelSuccessComment ( octokit , context , deployment , commitId ) ;
168146 }
147+ console . log ( {
148+ details_url : urls [ 0 ] ,
149+ conclusion : "success" ,
150+ output : {
151+ title : `Deploy preview succeeded` ,
152+ summary : getURLsMarkdownFromChannelDeployResult ( deployment ) ,
153+ } ,
154+ } ) ;
155+ return undefined ;
169156}
170157
171158run ( ) ;
0 commit comments