This commit is contained in:
noyciy7037 2023-07-09 14:31:18 +09:00
commit 3ffd290a66
Signed by: noyciy7037
GPG Key ID: 46A54FA18BBA58FF
2 changed files with 101 additions and 0 deletions

31
action.yml Normal file
View File

@ -0,0 +1,31 @@
name: 'Online Code Pages'
description: 'Place the code in Pages.'
inputs:
ref:
description: >
The branch, tag or SHA to deployment. When checking out the repository that
triggered a workflow, this defaults to the reference or SHA for that
event. Otherwise, uses the default branch.
default: ${{ gitea.sha }}
token:
description: >
Personal access token (PAT) used to fetch the repository. The PAT is configured
with the local git config, which enables your scripts to run authenticated git
commands. The post-job step removes the PAT.
We recommend using a service account with the least permissions necessary.
Also when generating a new PAT, select the least scopes necessary.
[Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
default: ${{ gitea.token }}
pages-url:
description: The base URL for the Online Code Pages instance that you are trying to clone from, will use environment defaults to fetch from the same instance that the workflow is running from unless specified. Example URLs are https://pages.wikiwiki.li/ or https://my-pages.example.com/
default: https://pages.wikiwiki.li/
remove:
description: Remove placed codes.
default: false
runs:
using: node16
main: index.js

70
index.js Normal file
View File

@ -0,0 +1,70 @@
"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();