Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/main/index.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ export async function run(): Promise<void> {

// Extract the version from the response.
const deployResponse = parseDeployResponse(deployOutput.stdout);

// Deploying only config files (cron.yaml, dispatch.yaml, index.yaml) does
// not create a version, so there is nothing to describe. Completing here
// leaves the version outputs unset instead of failing the step.
if (!deployResponse.versionID) {
logInfo(`Deployed configs: ${deployResponse.configs.join(', ')}`);
return;
}
logDebug(`Deployed new version: ${JSON.stringify(deployResponse)}`);

// Look up the new version to get metadata.
Expand Down
19 changes: 15 additions & 4 deletions src/output-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export interface DeployResponse {

// versionID is the unique version ID.
versionID: string;

// configs is the list of config files that were deployed, such as "cron" or
// "dispatch". Deploying only config files does not create a version, so for
// those deployments this is the only field with a value.
configs: string[];
}

/**
Expand All @@ -44,14 +49,20 @@ export function parseDeployResponse(stdout: string | undefined): DeployResponse

const outputJSON = JSON.parse(stdout);
const version = outputJSON?.versions?.at(0);
if (!version) {
const configs: string[] = Array.isArray(outputJSON?.configs) ? outputJSON.configs : [];

// gcloud returns an empty "versions" list when only config files, such as
// cron.yaml or dispatch.yaml, were deployed. Those deployments are still
// successful, they just don't create a new version.
if (!version && configs.length === 0) {
throw new Error(`missing or empty "versions"`);
}

return {
project: version['project'],
service: version['service'],
versionID: version['id'],
project: version?.['project'] ?? '',
service: version?.['service'] ?? '',
versionID: version?.['id'] ?? '',
configs: configs,
};
} catch (err) {
const msg = errorMessage(err);
Expand Down
30 changes: 25 additions & 5 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ const defaultMocks = (
};
}),

parseDeployResponse: m.method(outputParser, 'parseDeployResponse', async () => {
parseDeployResponse: m.method(outputParser, 'parseDeployResponse', () => {
return {
exitCode: 0,
stderr: '',
name: 'a',
link: 'b',
project: 'my-project',
service: 'default',
versionID: '123',
configs: [],
};
}),

Expand Down Expand Up @@ -263,6 +263,26 @@ test('#run', { concurrency: true }, async (suite) => {
]);
});

await suite.test('skips the version lookup for config-only deploys', async (t) => {
const mocks = defaultMocks(t.mock);

t.mock.method(outputParser, 'parseDeployResponse', () => {
return {
project: '',
service: '',
versionID: '',
configs: ['cron'],
};
});

await run();

// Only the deploy itself runs, there is no version to describe and no
// version outputs to set.
assert.deepStrictEqual(mocks.getExecOutput.mock.callCount(), 1);
assert.deepStrictEqual(mocks.setOutput.mock.callCount(), 0);
});

await suite.test('sets outputs', async (t) => {
const mocks = defaultMocks(t.mock);

Expand Down
65 changes: 65 additions & 0 deletions tests/output-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ test('#parseDeployResponse', { concurrency: true }, async (suite) => {
project: 'my-project',
service: 'default',
versionID: '20221117t121206',
configs: [],
},
},
{
Expand Down Expand Up @@ -157,6 +158,7 @@ test('#parseDeployResponse', { concurrency: true }, async (suite) => {
project: 'my-project',
service: 'default',
versionID: '123',
configs: [],
},
},
{
Expand All @@ -182,6 +184,64 @@ test('#parseDeployResponse', { concurrency: true }, async (suite) => {
project: 'my-project',
service: 'default',
versionID: '123',
configs: [],
},
},
{
name: 'with cron config only',
stdout: `
{
"configs": [
"cron"
],
"versions": []
}
`,
expected: {
project: '',
service: '',
versionID: '',
configs: ['cron'],
},
},
{
name: 'with dispatch config only',
stdout: `
{
"configs": [
"dispatch"
],
"versions": []
}
`,
expected: {
project: '',
service: '',
versionID: '',
configs: ['dispatch'],
},
},
{
name: 'with version and configs',
stdout: `
{
"configs": [
"cron"
],
"versions": [
{
"id": "123",
"project": "my-project",
"service": "default"
}
]
}
`,
expected: {
project: 'my-project',
service: 'default',
versionID: '123',
configs: ['cron'],
},
},
{
Expand All @@ -199,6 +259,11 @@ test('#parseDeployResponse', { concurrency: true }, async (suite) => {
stdout: `{}`,
error: `missing or empty "versions"`,
},
{
name: 'empty versions and configs from stdout',
stdout: `{"configs": [], "versions": []}`,
error: `missing or empty "versions"`,
},
{
name: 'invalid text from stdout',
stdout: `Some text to fail`,
Expand Down