@@ -19,12 +19,13 @@ import fs from 'fs';
1919import {
2020 getInput ,
2121 info as logInfo ,
22+ debug as logDebug ,
2223 warning as logWarning ,
2324 setFailed ,
2425 setOutput ,
2526} from '@actions/core' ;
2627import { getExecOutput } from '@actions/exec' ;
27- import { parseDeployResponse } from './output-parser' ;
28+ import { parseDeployResponse , parseDescribeResponse } from './output-parser' ;
2829
2930import {
3031 getLatestGcloudSDKVersion ,
@@ -43,7 +44,8 @@ import {
4344 stubEnv ,
4445} from '@google-github-actions/actions-utils' ;
4546
46- // Do not listen to the linter - this can NOT be rewritten as an ES6 import statement.
47+ // Do not listen to the linter - this can NOT be rewritten as an ES6 import
48+ // statement.
4749// eslint-disable-next-line @typescript-eslint/no-var-requires
4850const { version : appVersion } = require ( '../package.json' ) ;
4951
@@ -60,7 +62,7 @@ export async function run(): Promise<void> {
6062
6163 // Warn if pinned to HEAD
6264 if ( isPinnedToHead ( ) ) {
63- logWarning ( pinnedToHeadWarning ( 'v0 ' ) ) ;
65+ logWarning ( pinnedToHeadWarning ( 'v1 ' ) ) ;
6466 }
6567
6668 try {
@@ -136,26 +138,53 @@ export async function run(): Promise<void> {
136138 }
137139
138140 const options = { silent : true , ignoreReturnCode : true } ;
139- const commandString = `${ toolCommand } ${ appDeployCmd . join ( ' ' ) } ` ;
140- logInfo ( `Running: ${ commandString } ` ) ;
141+ const deployCommandString = `${ toolCommand } ${ appDeployCmd . join ( ' ' ) } ` ;
142+ logInfo ( `Running: ${ deployCommandString } ` ) ;
141143
142144 // Get output of gcloud cmd.
143- const output = await getExecOutput ( toolCommand , appDeployCmd , options ) ;
144- if ( output . exitCode !== 0 ) {
145- const errMsg = output . stderr || `command exited ${ output . exitCode } , but stderr had no output` ;
146- throw new Error ( `failed to execute gcloud command \`${ commandString } \`: ${ errMsg } ` ) ;
145+ const deployOutput = await getExecOutput ( toolCommand , appDeployCmd , options ) ;
146+ if ( deployOutput . exitCode !== 0 ) {
147+ const errMsg =
148+ deployOutput . stderr || `command exited ${ deployOutput . exitCode } , but stderr had no output` ;
149+ throw new Error ( `failed to execute gcloud command \`${ deployCommandString } \`: ${ errMsg } ` ) ;
147150 }
148151
149- // Set url as output.
150- const response = parseDeployResponse ( output . stdout ) ;
151- if ( response ) {
152- setOutput ( 'name' , response . name ) ;
153- setOutput ( 'serviceAccountEmail' , response . serviceAccountEmail ) ;
154- setOutput ( 'versionURL' , response . versionURL ) ;
155- setOutput ( 'url' , response . versionURL ) ;
156- } else {
157- logWarning ( `no outputs were set, this usually happens with --no-promote` ) ;
152+ // Extract the version from the response.
153+ const deployResponse = parseDeployResponse ( deployOutput . stdout ) ;
154+ logDebug ( `Deployed new version: ${ JSON . stringify ( deployResponse ) } ` ) ;
155+
156+ // Look up the new version to get metadata.
157+ const appVersionsDescribeCmd = [ 'app' , 'versions' , 'describe' , '--quiet' , '--format' , 'json' ] ;
158+ appVersionsDescribeCmd . push ( '--project' , deployResponse . project ) ;
159+ appVersionsDescribeCmd . push ( '--service' , deployResponse . service ) ;
160+ appVersionsDescribeCmd . push ( deployResponse . versionID ) ;
161+
162+ const describeCommandString = `${ toolCommand } ${ appVersionsDescribeCmd . join ( ' ' ) } ` ;
163+ logInfo ( `Running: ${ describeCommandString } ` ) ;
164+
165+ const describeOutput = await getExecOutput ( toolCommand , appVersionsDescribeCmd , options ) ;
166+ if ( describeOutput . exitCode !== 0 ) {
167+ const errMsg =
168+ describeOutput . stderr ||
169+ `command exited ${ describeOutput . exitCode } , but stderr had no output` ;
170+ throw new Error ( `failed to execute gcloud command \`${ describeCommandString } \`: ${ errMsg } ` ) ;
158171 }
172+
173+ // Parse the describe response.
174+ const describeResponse = parseDescribeResponse ( describeOutput . stdout ) ;
175+
176+ // Set outputs.
177+ setOutput ( 'name' , describeResponse . name ) ;
178+ setOutput ( 'runtime' , describeResponse . runtime ) ;
179+ setOutput ( 'service_account_email' , describeResponse . serviceAccountEmail ) ;
180+ setOutput ( 'serving_status' , describeResponse . servingStatus ) ;
181+ setOutput ( 'version_id' , describeResponse . versionID ) ;
182+ setOutput ( 'version_url' , describeResponse . versionURL ) ;
183+
184+ // Backwards compatability.
185+ setOutput ( 'serviceAccountEmail' , describeResponse . serviceAccountEmail ) ;
186+ setOutput ( 'versionURL' , describeResponse . versionURL ) ;
187+ setOutput ( 'url' , describeResponse . versionURL ) ;
159188 } catch ( err ) {
160189 const msg = errorMessage ( err ) ;
161190 setFailed ( `google-github-actions/deploy-appengine failed with: ${ msg } ` ) ;
0 commit comments