1
1
import * as core from '@actions/core'
2
2
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'
5
4
6
5
export async function run ( ) : Promise < void > {
7
- let token : string
8
- let type : ActionType
9
- let deploymentId : string
10
6
let jobStatus : string
11
7
let environment : string
12
8
let slackToken : string
13
9
let slackChannel : string
14
10
let deploymentConfidenceUrl : string
15
- let mutateDeployment : boolean
16
11
let currentSha : string
17
12
18
13
const { actor, ref, repo, sha } = github . context
@@ -26,13 +21,9 @@ export async function run (): Promise<void> {
26
21
console . log ( `new_sha: ${ sha } ` )
27
22
console . log ( '\n' )
28
23
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 ###' )
35
25
26
+ try {
36
27
jobStatus = getInput ( 'job_status' ) ?? 'success'
37
28
console . log ( `job_status: ${ jobStatus } ` )
38
29
@@ -44,58 +35,24 @@ export async function run (): Promise<void> {
44
35
slackChannel = getInput ( 'slack_channel' ) ?? ''
45
36
console . log ( `slack_channel: ${ slackChannel } ` )
46
37
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
-
52
38
currentSha = getInput ( 'current_sha' ) ?? sha
53
39
console . log ( `current_sha: ${ currentSha } ` )
54
40
55
41
deploymentConfidenceUrl = getInput ( 'deployment_confidence_url' ) ?? ''
56
42
console . log ( `deployment confidence dashboard URL: ${ deploymentConfidenceUrl } ` )
57
43
} catch ( error ) {
58
- core . error ( error )
44
+ core . error ( error as Error )
59
45
core . setFailed ( `Wrong parameters given: ${ JSON . stringify ( error , null , 2 ) } ` )
60
46
throw error
61
47
}
62
48
console . log ( '\n' )
63
49
console . log ( '### post ###' )
64
50
65
- const client = new github . GitHub ( token , { previews : [ 'ant-man' , 'flash' ] } )
66
51
const status : DeploymentStatus = jobStatus === 'success' ? 'success' : 'failure'
67
52
console . log ( `status: ${ status } ` )
68
53
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 )
99
56
}
100
57
101
58
if ( process . env . NODE_ENV !== 'test' ) run ( ) // eslint-disable-line @typescript-eslint/no-floating-promises
0 commit comments