From 3ffd290a66247f5c74b3439f2c12b1ac0455dced Mon Sep 17 00:00:00 2001 From: noyciy7037 Date: Sun, 9 Jul 2023 14:31:18 +0900 Subject: [PATCH] init --- action.yml | 31 ++++++++++++++++++++++++ index.js | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 action.yml create mode 100644 index.js diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..5de3096 --- /dev/null +++ b/action.yml @@ -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 \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..1763d2d --- /dev/null +++ b/index.js @@ -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(); + +