@@ -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,21 +43,13 @@ 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" ) ;
5149const target = getInput ( "target" ) ;
5250const firebaseToolsVersion = getInput ( "firebaseToolsVersion" ) ;
5351
5452async function run ( ) {
55- const isPullRequest = ! ! context . payload . pull_request ;
56-
57- let finish = ( details : Object ) => console . log ( details ) ;
58- if ( token && isPullRequest ) {
59- finish = await createCheck ( octokit , context ) ;
60- }
61-
6253 try {
6354 startGroup ( "Verifying firebase.json exists" ) ;
6455
@@ -74,96 +65,93 @@ async function run() {
7465 if ( existsSync ( "./firebase.json" ) ) {
7566 console . log ( "firebase.json file found. Continuing deploy." ) ;
7667 } else {
77- throw Error (
78- "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."
79- ) ;
68+ 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." ) ;
8069 }
8170 endGroup ( ) ;
8271
8372 startGroup ( "Setting up CLI credentials" ) ;
8473 const gacFilename = await createGacFile ( googleApplicationCredentials ) ;
85- console . log (
86- "Created a temporary file with Application Default Credentials."
87- ) ;
74+ if ( gacFilename != googleApplicationCredentials ) {
75+ console . log (
76+ "Created a temporary file with Application Default Credentials."
77+ ) ;
78+ }
8879 endGroup ( ) ;
8980
90- if ( isProductionDeploy ) {
81+ if ( configuredChannelId === "live" ) {
9182 startGroup ( "Deploying to production site" ) ;
92- const deployment = await deployProductionSite ( gacFilename , {
93- projectId,
94- target,
95- firebaseToolsVersion,
96- } ) ;
97- if ( deployment . status === "error" ) {
98- throw Error ( ( deployment as ErrorResult ) . error ) ;
99- }
83+ await deployToProduction ( gacFilename ) ;
84+ endGroup ( ) ;
85+ } else {
86+ const channelId = getChannelId ( configuredChannelId , context ) ;
87+ startGroup ( `Deploying to Firebase preview channel ${ channelId } ` ) ;
88+ await deployToPreviewChannel ( gacFilename , channelId ) ;
10089 endGroup ( ) ;
101-
102- const hostname = target ? `${ target } .web.app` : `${ projectId } .web.app` ;
103- const url = `https://${ hostname } /` ;
104- await finish ( {
105- details_url : url ,
106- conclusion : "success" ,
107- output : {
108- title : `Production deploy succeeded` ,
109- summary : `[${ hostname } ](${ url } )` ,
110- } ,
111- } ) ;
112- return ;
113- }
114-
115- const channelId = getChannelId ( configuredChannelId , context ) ;
116-
117- startGroup ( `Deploying to Firebase preview channel ${ channelId } ` ) ;
118- const deployment = await deployPreview ( gacFilename , {
119- projectId,
120- expires,
121- channelId,
122- target,
123- firebaseToolsVersion,
124- } ) ;
125-
126- if ( deployment . status === "error" ) {
127- throw Error ( ( deployment as ErrorResult ) . error ) ;
12890 }
129- endGroup ( ) ;
130-
131- const { expireTime, urls } = interpretChannelDeployResult ( deployment ) ;
91+ } catch ( e ) {
92+ setFailed ( e . message ) ;
93+ }
94+ return undefined ;
95+ }
13296
133- setOutput ( "urls" , urls ) ;
134- setOutput ( "expire_time" , expireTime ) ;
135- setOutput ( "details_url" , urls [ 0 ] ) ;
97+ async function deployToProduction ( gacFilePath : string ) {
98+ const deployment = await deployProductionSite ( gacFilePath , {
99+ projectId,
100+ target,
101+ firebaseToolsVersion,
102+ } ) ;
103+ if ( deployment . status === "error" ) {
104+ throw Error ( ( deployment as ErrorResult ) . error ) ;
105+ }
106+ const hostname = target ? `${ target } .web.app` : `${ projectId } .web.app` ;
107+ const url = `https://${ hostname } /` ;
108+ console . log ( {
109+ details_url : url ,
110+ conclusion : "success" ,
111+ output : {
112+ title : `Production deploy succeeded` ,
113+ summary : `[${ hostname } ](${ url } )` ,
114+ } ,
115+ } ) ;
116+ return undefined ;
117+ }
136118
137- const urlsListMarkdown =
138- urls . length === 1
139- ? `[${ urls [ 0 ] } ](${ urls [ 0 ] } )`
140- : urls . map ( ( url ) => `- [${ url } ](${ url } )` ) . join ( "\n" ) ;
119+ async function deployToPreviewChannel ( gacFilePath : string , channelId : string ) {
120+ const deployment = await deployPreview ( gacFilePath , {
121+ projectId,
122+ expires,
123+ channelId,
124+ target,
125+ firebaseToolsVersion,
126+ } ) ;
127+ if ( deployment . status === "error" ) {
128+ throw Error ( ( deployment as ErrorResult ) . error ) ;
129+ }
141130
142- if ( token && isPullRequest && ! ! octokit ) {
143- const commitId = context . payload . pull_request ?. head . sha . substring ( 0 , 7 ) ;
131+ const { expireTime, urls } = interpretChannelDeployResult ( deployment ) ;
132+ setOutput ( "urls" , urls ) ;
133+ setOutput ( "expire_time" , expireTime ) ;
134+ setOutput ( "details_url" , urls [ 0 ] ) ;
144135
145- await postChannelSuccessComment ( octokit , context , deployment , commitId ) ;
146- }
136+ const urlsListMarkdown =
137+ urls . length === 1
138+ ? `[${ urls [ 0 ] } ](${ urls [ 0 ] } )`
139+ : urls . map ( ( url ) => `- [${ url } ](${ url } )` ) . join ( "\n" ) ;
147140
148- await finish ( {
149- details_url : urls [ 0 ] ,
150- conclusion : "success" ,
151- output : {
152- title : `Deploy preview succeeded` ,
153- summary : getURLsMarkdownFromChannelDeployResult ( deployment ) ,
154- } ,
155- } ) ;
156- } catch ( e ) {
157- setFailed ( e . message ) ;
141+ if ( token && ! ! context . payload . pull_request && ! ! octokit ) {
142+ const commitId = context . payload . pull_request ?. head . sha . substring ( 0 , 7 ) ;
158143
159- await finish ( {
160- conclusion : "failure" ,
161- output : {
162- title : "Deploy preview failed" ,
163- summary : `Error: ${ e . message } ` ,
164- } ,
165- } ) ;
144+ await postChannelSuccessComment ( octokit , context , deployment , commitId ) ;
166145 }
146+ console . log ( {
147+ details_url : urls [ 0 ] ,
148+ conclusion : "success" ,
149+ output : {
150+ title : `Deploy preview succeeded` ,
151+ summary : getURLsMarkdownFromChannelDeployResult ( deployment ) ,
152+ } ,
153+ } ) ;
154+ return undefined ;
167155}
168156
169157run ( ) ;
0 commit comments