@@ -19,12 +19,13 @@ import fs from 'fs';
19
19
import {
20
20
getInput ,
21
21
info as logInfo ,
22
+ debug as logDebug ,
22
23
warning as logWarning ,
23
24
setFailed ,
24
25
setOutput ,
25
26
} from '@actions/core' ;
26
27
import { getExecOutput } from '@actions/exec' ;
27
- import { parseDeployResponse } from './output-parser' ;
28
+ import { parseDeployResponse , parseDescribeResponse } from './output-parser' ;
28
29
29
30
import {
30
31
getLatestGcloudSDKVersion ,
@@ -43,7 +44,8 @@ import {
43
44
stubEnv ,
44
45
} from '@google-github-actions/actions-utils' ;
45
46
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.
47
49
// eslint-disable-next-line @typescript-eslint/no-var-requires
48
50
const { version : appVersion } = require ( '../package.json' ) ;
49
51
@@ -60,7 +62,7 @@ export async function run(): Promise<void> {
60
62
61
63
// Warn if pinned to HEAD
62
64
if ( isPinnedToHead ( ) ) {
63
- logWarning ( pinnedToHeadWarning ( 'v0 ' ) ) ;
65
+ logWarning ( pinnedToHeadWarning ( 'v1 ' ) ) ;
64
66
}
65
67
66
68
try {
@@ -136,26 +138,53 @@ export async function run(): Promise<void> {
136
138
}
137
139
138
140
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 } ` ) ;
141
143
142
144
// 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 } ` ) ;
147
150
}
148
151
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 } ` ) ;
158
171
}
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 ) ;
159
188
} catch ( err ) {
160
189
const msg = errorMessage ( err ) ;
161
190
setFailed ( `google-github-actions/deploy-appengine failed with: ${ msg } ` ) ;
0 commit comments