-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (48 loc) · 1.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
const core = require('@actions/core');
const github = require('@actions/github');
const https = require('node:https');
const spawn = require('child_process').spawn;
try {
const path = core.getInput('path');
const ticket = core.getInput('ticket');
request = https.request(
`https://staging.cm4all.works/ticket/${ticket}`,
{
'method': 'PUT',
'headers': {
'content-type': 'application/x-tar',
'expect': '100-continue',
}
},
(res) => {
if (res.statusCode !== 201) {
core.setFailed(`PUT failed: ${res.statusCode}`);
res.resume();
return;
}
},
);
request.on('continue', () => {
const child = spawn('/bin/tar', ['cC', path, '.']);
child.stdout.on('data', (data) => {
request.write(data);
});
child.on('close', (code) => {
if (code !== 0) {
core.setFailed(`tar failed: ${code}`);
request.destroy();
return;
}
request.end();
});
child.on('error', (err) => {
core.setFailed(`tar failed: ${err}`);
request.destroy();
});
});
request.on('error', (err) => {
core.setFailed(`PUT failed: ${err}`);
});
} catch (error) {
core.setFailed(error.message);
}