pages/index.js

71 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-07-09 14:31:18 +09:00
"use strict";
const https = require('https');
const token = process.env.INPUT_TOKEN;
const repository = process.env.GITHUB_REPOSITORY;
const owner = process.env.GITHUB_REPOSITORY_OWNER;
const pagesControl = process.env["INPUT_PAGES-URL"] + "control.php";
const pagesLogs = process.env["INPUT_PAGES-URL"] + "getlogs.php";
const ref = process.env.INPUT_REF;
const remove = JSON.parse(process.env.INPUT_REMOVE.toLowerCase());
const data = JSON.stringify({
repository: repository,
owner: owner,
token: token,
ref: ref,
remove: remove,
});
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
};
const url = pagesControl;
const request = https.request(url, options, response => {
console.log('statusCode:', response.statusCode);
let body = "";
response.on('data', (d) => {
body += d;
});
response.on('end', () => {
if (response.statusCode < 200 || 299 < response.statusCode) {
process.exitCode = 1;
console.log(body);
return;
}
console.log(`processID: ${body}`);
let log = "";
const getLogs = () => {
const req = https.request(pagesLogs + "?processId=" + body, (res) => {
let logBody = "";
res.on('data', (chunk) => {
logBody += chunk;
});
res.on('end', () => {
const logData = JSON.parse(logBody);
process.stdout.write(logData["log"].slice(log.length));
log = logData["log"];
if (!logData["finished"]) {
setTimeout(getLogs, 1000);
} else if (!logData["succeed"]) {
process.exitCode = 1;
}
});
});
req.end();
};
setTimeout(getLogs, 1000);
});
});
request.write(data);
request.end();