-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
37 lines (33 loc) · 1.05 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
const core = require('@actions/core');
const github = require('@actions/github');
const https = require('https');
const url = require('url');
try {
const urlToHit = core.getInput('url-to-hit');
const parsedUrl = url.parse(urlToHit);
const expectedStatuses = core.getInput('expected-statuses').split(",").map((status) => Number(status)) ;
const userAgentToUse = core.getInput('user-agent-to-use');
console.log(`Pinging ${urlToHit} and expecting ${expectedStatuses}`);
const options = {
hostname: parsedUrl.host,
path: parsedUrl.path,
port: parsedUrl.port,
method: 'GET',
headers: {
'User-Agent': userAgentToUse
}
};
https.get(options, (resp) => {
if (!expectedStatuses.includes(resp.statusCode)) {
core.setFailed(`Request status was ${resp.statusCode}`);
} else {
console.log(`Successful check`);
core.setOutput("status", resp.statusCode);
}
}).on("error", (err) => {
console.log(`Request failed`);
core.setFailed(err.message);
})
} catch (error) {
core.setFailed(error.message);
}