Skip to content

Commit 1830167

Browse files
Don't mutate a deployment if created by another workflow (#39)
This commit adds the ability to still communicate via Slack that a deployment went through without actually having this workflow manage the deployment logic itself.
1 parent 499b502 commit 1830167

File tree

6 files changed

+42
-20
lines changed

6 files changed

+42
-20
lines changed

dist/main/index.js

Lines changed: 8 additions & 4 deletions
Large diffs are not rendered by default.

dist/post/index.js

Lines changed: 11 additions & 4 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "action-deploy",
3-
"version": "2.1.6",
3+
"version": "2.2.0",
44
"private": true,
55
"description": "Action to manage GitHub deployments",
66
"main": "lib/main.js",

src/main.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,19 @@ export async function run (): Promise<void> {
6565
switch (type) {
6666
case 'create':
6767
try {
68-
deploymentId = await create(
69-
client,
70-
logsUrl,
71-
description,
72-
status,
73-
environment,
74-
environmentUrl,
75-
mainBranch
76-
)
68+
// If a deployment was already created on a previous job,
69+
// don't create one again.
70+
if (deploymentId === '0') {
71+
deploymentId = await create(
72+
client,
73+
logsUrl,
74+
description,
75+
status,
76+
environment,
77+
environmentUrl,
78+
mainBranch
79+
)
80+
}
7781
console.log(`saveState::${DEPLOYMENT_ID_STATE_NAME}: ${deploymentId}`)
7882
core.saveState(DEPLOYMENT_ID_STATE_NAME, deploymentId) // for internal use
7983
core.setOutput(DEPLOYMENT_ID_STATE_NAME, deploymentId) // keep that output for external dependencies

src/post.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export async function post (): Promise<void> {
1212
let slackToken: string
1313
let slackChannel: string
1414
let deploymentConfidenceUrl: string
15+
let mutateDeployment: boolean
1516

1617
const { actor, ref, repo, sha } = github.context
1718

@@ -42,6 +43,11 @@ export async function post (): Promise<void> {
4243
slackChannel = getInput('slack_channel') ?? ''
4344
console.log(`slack_channel: ${slackChannel}`)
4445

46+
// We want to mutate the Deployment by default, unless the deployment
47+
// was already mutated by another action and we just want to notify
48+
mutateDeployment = getInput('mutate_deployment') !== 'false'
49+
console.log(`mutate_deployment: ${mutateDeployment.toString()}`)
50+
4551
deploymentConfidenceUrl = getInput('deployment_confidence_url') ?? ''
4652
console.log(`deployment confidence dashboard URL: ${deploymentConfidenceUrl}`)
4753
} catch (error) {
@@ -69,7 +75,8 @@ export async function post (): Promise<void> {
6975
await postSlackNotification(slackToken, slackChannel, environment, status, github.context, deploymentConfidenceUrl)
7076

7177
try {
72-
await complete(client, Number(deploymentId), status)
78+
// If the deployment was managed by another workflow we don't want to mutate it here
79+
if (mutateDeployment) await complete(client, Number(deploymentId), status)
7380
} catch (error) {
7481
if (error.name === 'HttpError' && error.status === 404) {
7582
console.log('Couldn\'t complete a deployment: not found')

0 commit comments

Comments
 (0)