-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (31 loc) · 1.03 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
const FormData = require('form-data');
const core = require('@actions/core');
const fs = require('fs');
const host = 'dev.larawatch.com';
const protocol = 'https:';
const path = '/api/uploadphpstan';
const filePath = core.getInput('filePath');
const data = core.getInput('data');
console.info('endpoint', host + path);
try {
fs.existsSync(filePath);
console.info('File found', filePath);
} catch (e) {
return core.setFailed('ERROR: file not found: ' + filePath);
}
const form = new FormData();
form.append('file', fs.createReadStream(filePath));
form.append('data', data);
form.getLength(function (err, l) {
console.info('Sending file, size:', l + 'b');
});
form.submit({ host, protocol, path }, function (err, res) {
if (err) {
console.error(err);
return core.setFailed('Request failed');
}
console.info('Response', res.statusCode, res.statusMessage);
if (res.statusCode >= 400 && res.statusCode < 600) {
core.setFailed('Request failed');
}
});