-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-action.js
More file actions
80 lines (70 loc) · 2.19 KB
/
github-action.js
File metadata and controls
80 lines (70 loc) · 2.19 KB
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
const core = require("@actions/core");
const exec = require('@actions/exec');
const glob = require('@actions/glob');
const fs = require("fs");
const path = require("path");
const FormData = require('form-data');
const axios = require('axios');
function isID(str) {
return !(isNaN(str) || str.includes("."));
}
async function executeTests() {
const execute = core.getBooleanInput("execute", { required: false });
if (!execute) {
core.info("Skipping execution as per input parameter.");
return;
}
if (fs.existsSync('composer.json')) {
await exec.exec('composer run prestaflow:json:file');
}
}
async function run() {
try {
await executeTests();
const token = core.getInput("token", { required: false });
const projectId = core.getInput("projectId", { required: false });
const form = new FormData();
form.append('projectId', projectId);
const patterns = ['**/prestaflow/results.json', '**/prestaflow/screens/errors/*.png'];
const globber = await glob.create(patterns.join('\n'))
for await (const file of globber.globGenerator()) {
core.debug(`Found file: ${file}`);
let stats = fs.statSync(file);
if (stats.isFile()) {
const fileName = path.basename(file);
if (file.includes('screens')) {
let fileNameT = 'screens/' + fileName;
form.append('file[]', fs.createReadStream(file), fileNameT);
} else {
form.append('file[]', fs.createReadStream(file), fileName);
}
}
}
axios.defaults.baseURL = 'https://api.prestaflow.io';
const endpoint = `/ci/github-action/`;
await axios.post(endpoint, form, {
headers: {
...form.getHeaders(),
//Authorization: 'Bearer ...', // optional
"X-Api-Token": token,
},
}).then(function (response) {
core.info("Output ID: " + response.data.id);
core.setOutput("id", response.data.id);
}).catch(function (error) {
if (error.response) {
core.setFailed(
`${error.response.statusText}`
);
} else {
core.setFailed(
`${error.message}`
);
}
});
} catch (error) {
core.setFailed(error.message);
throw error;
}
}
run();