-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (63 loc) · 2.44 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
const core = require('@actions/core');
const { context, GitHub } = require('@actions/github');
const fs = require('fs').promises;
const path = require('path');
const axios = require('axios');
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0
console.log('Starting.');
async function checkDownloadArray(downloadArray, game, issuesFound) {
for(let download of downloadArray) {
if(!download.check_download_status) {
continue;
}
console.info(`checkDownloadArray for ${JSON.stringify(download)}`);
try {
const result = await axios.head(download.url + download.file);
if(result.status != 200) {
issuesFound.push({
download_name: download.name,
download_status: result.status,
download_status_text: result.statusText,
game_name: game.game_name,
game_app_id: game.app_id
});
} else {
console.info(`checkDownloadArray success for ${JSON.stringify(download)}`);
}
} catch(error) {
console.log(error);
issuesFound.push({
download_name: download.name,
download_status: error.response ? error.response.status : -1,
download_status_text: error.response ? error.response.statusText : error.message,
game_name: game.game_name,
game_app_id: game.app_id
});
}
}
}
async function run() {
try {
const packagesJsonPath = path.join('metadata', 'packagessniper_v2.json');
const packagesJsonStr = await fs.readFile(packagesJsonPath, 'utf-8');
const packagesJson = JSON.parse(packagesJsonStr);
const issuesFound = [];
for(let game of packagesJson.games) {
await checkDownloadArray(game.download, game, issuesFound);
}
await checkDownloadArray(packagesJson.default_engine.download, packagesJson.default_engine, issuesFound);
console.info(`issuesFound: ${JSON.stringify(issuesFound)}`);
const matrix = {};
if(issuesFound.length) {
matrix.include = [];
}
for(let downloadIssue of issuesFound) {
matrix.include.push(downloadIssue);
}
core.setOutput('matrix', JSON.stringify(matrix));
}
catch (error) {
core.setFailed(error.message);
}
}
run();