-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
action.js
103 lines (94 loc) · 2.64 KB
/
action.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright H5BP
//
// Licensed under the MIT License
const path = require('path')
const core = require('@actions/core')
const exec = require('@actions/exec')
const { DefaultArtifactClient } = require('@actions/artifact')
async function action () {
const command = core.getInput('command', { required: true })
if (command !== 'test' && command !== 'benchmark') {
core.setFailed('Invalid command')
}
// ------
core.startGroup('Starting server container')
const serverArgs = [
'-v', `${path.join(__dirname, 'fixtures')}:${core.getInput('root-path', { required: true })}`
]
if (core.getInput('certs-path')) {
serverArgs.push('-v', `${path.join(__dirname, '../certs')}:${core.getInput('certs-path')}`)
} else {
core.warning('certs-path was not set')
}
const volumes = core.getInput('configs-volumes')
.split(';')
.filter(val => val !== '')
.map(vlm => ['-v', `${process.cwd()}/${vlm}`])
if (volumes.length) {
serverArgs.push(...volumes.flat())
}
serverArgs.push(core.getInput('server', { required: true }))
try {
await exec.exec('docker', [
'run',
'--detach',
'-p', '80:80',
'-p', '443:443',
'--name', 'server',
...serverArgs
])
} catch (e) {
core.setFailed(e.message)
process.exit()
}
core.endGroup()
// ------
core.startGroup('Preparing server-configs-test')
// ---
core.debug('Build k6 arguments')
const k6Args = ['run']
if (command === 'test') {
k6Args.push(
path.join(__dirname, '../lib/index.js'),
'-e', `TESTS=${core.getInput('tests')}`
)
} else if (command === 'benchmark') {
k6Args.push(path.join(__dirname, '../lib/benchmark.js'))
}
if (core.isDebug() && command !== 'benchmark') {
k6Args.push('--http-debug')
}
k6Args.push(
'--summary-export', path.join(__dirname, '../sct-summary.json'),
'--out', `json=${path.join(__dirname, '../sct-results.json')}`
)
if (process.env.K6_CLOUD_TOKEN) {
k6Args.push('--out', 'cloud')
}
core.endGroup()
// ------
try {
await exec.exec('k6', k6Args)
} catch (e) {
core.setFailed(e.message)
}
// ------
core.startGroup('Shutting down server and dumping logs')
if (command !== 'benchmark') {
await exec.exec('docker', ['logs', 'server'])
}
await exec.exec('docker', ['kill', 'server'])
await exec.exec('docker', ['rm', 'server'])
core.endGroup()
// ------
await (new DefaultArtifactClient()).uploadArtifact(
`sct-${command}-results`,
[
path.join(__dirname, '../sct-results.json'),
path.join(__dirname, '../sct-summary.json')
],
path.join(__dirname, '..'),
{ continueOnError: true }
)
}
action()