generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
88 lines (76 loc) · 2.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// bundlers can't detect that this is used in primus
// as it is a non-static require
const ws = require('ws')
const jsonParser = require('primus/parsers/json')
const wsTransformer = require('primus/transformers/websockets')
const core = require('@actions/core');
const Primus = require('primus')
const Emitter = require('primus-emitter')
const Socket = Primus.createSocket({
transformer: wsTransformer,
parser: jsonParser,
plugin: { emitter: Emitter },
noop: [ws]
})
const admiralHost = core.getInput('admiralHost')
const appId = core.getInput('appId')
const order = core.getInput('order')
const version = core.getInput('version')
const explicitEnvironment = core.getInput('environment')
core.info('INPUT: ' + JSON.stringify({appId, order, version, explicitEnvironment}))
if (!admiralHost || !appId || !order || !version) {
core.setFailed('admiralHost, appId, order and version must all be set')
core.setOutput('success', 'false')
process.exit(1)
}
const environment =
explicitEnvironment || (version.includes('-') ? 'staging' : 'production')
core.info('Chosen Environment: ' + environment)
const client = new Socket(admiralHost, { strategy: false })
// We need to let Node know that we're doing something long lived
// You will need to set a timeout on the action or this risks using
// all your minutes!
setInterval(() => {
client.send('ping')
}, 5000)
client.on('error', (error) => {
core.setFailed('Client error: '+ error)
core.setOutput('success', 'false')
client.end()
process.exit(1)
})
client.on('end', () => {
core.info('Client disconnected')
process.exit(0)
})
client.on('open', () => {
client.on('serverMessage', (data) => {
const msg = 'Admiral: ' + data.message
core.info(msg)
})
client.on('captainMessage', (data) => {
const msg = data.captainName + ': ' + data.message
core.info(msg)
})
client.send('register', null, (response) => {
const data = {
appId: appId,
environment: environment,
order: order,
orderArgs: [version],
clientId: response.clientId,
username: 'GitHub Actions'
}
client.send('executeOrder', data, (response) => {
if (response.success) {
core.info('ORDER EXECUTED')
core.setOutput('success', true)
} else {
if (response.message) core.info(response.message)
core.setOutput('success', false)
core.setFailed(response.message)
}
client.end()
})
})
})