Skip to content

Commit 6d034d8

Browse files
committed
Remove code unrelated to Slack
1 parent caafa9c commit 6d034d8

File tree

7 files changed

+11
-257
lines changed

7 files changed

+11
-257
lines changed

action.yml

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,10 @@
1-
name: action-deploy
2-
description: Action to manage GitHub deployments
3-
author: radiantspace
1+
name: action-deployment-notifications
2+
description: Action to send npm service deployment notifications to Slack
3+
author: radiantspace, hashtagchris
44
inputs:
5-
token:
6-
required: true
7-
description: GitHub token
8-
type:
9-
required: true
10-
description: a type of deployment action to perform, can be 'create', 'delete' and 'delete-all'
11-
logs:
12-
required: false
13-
description: url to deployment logs
14-
description:
15-
required: false
16-
description: description of a deployment
17-
deployment_id:
18-
required: false
19-
description: an id for deployment if 'delete' type is used
20-
status:
21-
required: false
22-
description: status for created deployment
235
environment:
246
required: false
257
description: environment to create or delete all deployments in, default to context.ref without prefixes ('refs/heads/', 'deploy-'), i.e. branch name
26-
environment_url:
27-
required: false
28-
description: link for the deployment (e.g. http://staging.your.app/status)
29-
main_branch:
30-
required: false
31-
description: name of main branch of the repo, to get and store sha of the head commit and track diff being deployed
328
job_status:
339
required: false
3410
description: pass `{{job.status}}` to set the deployment completion status post script accordingly
@@ -41,12 +17,9 @@ inputs:
4117
deployment_confidence_url:
4218
required: false
4319
description: link for the deployment confidence dashboard
44-
mutate_deployment:
45-
required: false
46-
description: Whether the deployment status needs to be mutated by this action
4720
current_sha:
4821
required: false
4922
description: Sha of the deployment
5023
runs:
51-
using: 'node12'
24+
using: 'node16'
5225
main: 'dist/main/index.js'

src/complete.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/create.ts

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/delete-all.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/delete.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/main.ts

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import * as core from '@actions/core'
22
import * as github from '@actions/github'
3-
import { complete } from './complete'
4-
import { ActionType, DeploymentStatus, getInput, DEPLOYMENT_ID_STATE_NAME, getEnvironment, postSlackNotification } from './utils'
3+
import { DeploymentStatus, getInput, getEnvironment, postSlackNotification } from './utils'
54

65
export async function run (): Promise<void> {
7-
let token: string
8-
let type: ActionType
9-
let deploymentId: string
106
let jobStatus: string
117
let environment: string
128
let slackToken: string
139
let slackChannel: string
1410
let deploymentConfidenceUrl: string
15-
let mutateDeployment: boolean
1611
let currentSha: string
1712

1813
const { actor, ref, repo, sha } = github.context
@@ -26,13 +21,9 @@ export async function run (): Promise<void> {
2621
console.log(`new_sha: ${sha}`)
2722
console.log('\n')
2823

29-
try {
30-
console.log('### post.inputs ###')
31-
token = getInput('token', { required: true }) ?? ''
32-
33-
type = getInput('type', { required: true }) as ActionType
34-
console.log(`type: ${type}`)
24+
console.log('### post.inputs ###')
3525

26+
try {
3627
jobStatus = getInput('job_status') ?? 'success'
3728
console.log(`job_status: ${jobStatus}`)
3829

@@ -44,58 +35,24 @@ export async function run (): Promise<void> {
4435
slackChannel = getInput('slack_channel') ?? ''
4536
console.log(`slack_channel: ${slackChannel}`)
4637

47-
// We want to mutate the Deployment by default, unless the deployment
48-
// was already mutated by another action and we just want to notify
49-
mutateDeployment = getInput('mutate_deployment') !== 'false'
50-
console.log(`mutate_deployment: ${mutateDeployment.toString()}`)
51-
5238
currentSha = getInput('current_sha') ?? sha
5339
console.log(`current_sha: ${currentSha}`)
5440

5541
deploymentConfidenceUrl = getInput('deployment_confidence_url') ?? ''
5642
console.log(`deployment confidence dashboard URL: ${deploymentConfidenceUrl}`)
5743
} catch (error) {
58-
core.error(error)
44+
core.error(error as Error)
5945
core.setFailed(`Wrong parameters given: ${JSON.stringify(error, null, 2)}`)
6046
throw error
6147
}
6248
console.log('\n')
6349
console.log('### post ###')
6450

65-
const client = new github.GitHub(token, { previews: ['ant-man', 'flash'] })
6651
const status: DeploymentStatus = jobStatus === 'success' ? 'success' : 'failure'
6752
console.log(`status: ${status}`)
6853

69-
switch (type) {
70-
case 'create':
71-
deploymentId = core.getState(DEPLOYMENT_ID_STATE_NAME)
72-
console.log(`deploymentId: ${deploymentId}`)
73-
if (deploymentId === undefined || deploymentId === '') {
74-
console.log('No deploymentId provided, skip status update')
75-
return
76-
}
77-
78-
// Post Slack notification
79-
await postSlackNotification(slackToken, slackChannel, environment, status, github.context, deploymentConfidenceUrl, currentSha)
80-
81-
try {
82-
// If the deployment was managed by another workflow we don't want to mutate it here
83-
if (mutateDeployment) await complete(client, Number(deploymentId), status)
84-
} catch (error) {
85-
if (error.name === 'HttpError' && error.status === 404) {
86-
console.log('Couldn\'t complete a deployment: not found')
87-
return
88-
}
89-
core.error(error)
90-
core.setFailed(`Complete deployment failed: ${JSON.stringify(error, null, 2)}`)
91-
throw error
92-
}
93-
94-
break
95-
default:
96-
console.log(`No post script for type: ${type}`)
97-
break
98-
}
54+
// Post Slack notification
55+
await postSlackNotification(slackToken, slackChannel, environment, status, github.context, deploymentConfidenceUrl, currentSha)
9956
}
10057

10158
if (process.env.NODE_ENV !== 'test') run() // eslint-disable-line @typescript-eslint/no-floating-promises

src/utils.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ export type DeploymentStatus =
2121
| 'pending'
2222
| 'success'
2323

24-
export type ActionType = 'create' | 'delete' | 'delete-all'
25-
26-
export const DEPLOYMENT_ID_STATE_NAME = 'deployment_id'
27-
2824
// nullify getInput empty results
2925
// to allow coalescence ?? operator
3026
export function getInput (name: string, options?: core.InputOptions): string | null {
@@ -91,7 +87,7 @@ export async function postSlackNotification (
9187
await slackClient.chat.postMessage(slackParams)
9288
console.log(`Slack message posted to channel: ${slackChannel}`)
9389
} catch (error) {
94-
core.error(error)
90+
core.error(error as Error)
9591
}
9692
}
9793

0 commit comments

Comments
 (0)