import experimentation
This commit is contained in:
Generated
+1396
-20
File diff suppressed because it is too large
Load Diff
@@ -17,9 +17,11 @@
|
||||
"cytoscape-elk": "^2.1.0",
|
||||
"cytoscape-klay": "^3.1.4",
|
||||
"debounce": "^1.2.1",
|
||||
"decompress": "^4.2.1",
|
||||
"express": "^4.18.2",
|
||||
"lean4-infoview": "https://gitpkg.now.sh/leanprover/vscode-lean4/lean4-infoview?de0062c",
|
||||
"lean4web": "github:hhu-adam/lean4web",
|
||||
"octokit": "^2.0.14",
|
||||
"path-browserify": "^1.0.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
@@ -30,6 +32,8 @@
|
||||
"rehype-katex": "^6.0.2",
|
||||
"remark-gfm": "^3.0.1",
|
||||
"remark-math": "^5.1.1",
|
||||
"request": "^2.88.2",
|
||||
"request-progress": "^3.0.0",
|
||||
"vscode-ws-jsonrpc": "^2.0.1",
|
||||
"web-worker": "^1.2.0",
|
||||
"ws": "^8.11.0"
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { spawn } from 'child_process'
|
||||
import fs from 'fs';
|
||||
|
||||
const progress = {}
|
||||
|
||||
async function runProcess(id, cmd, args, cwd) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const ls = spawn(cmd, args, {cwd});
|
||||
|
||||
ls.stdout.on('data', (data) => {
|
||||
progress[id].output += data.toString()
|
||||
});
|
||||
|
||||
ls.stderr.on('data', (data) => {
|
||||
progress[id].output += data.toString()
|
||||
});
|
||||
|
||||
ls.on('close', (code) => {
|
||||
resolve()
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
async function doImport (owner, repo, id) {
|
||||
fs.rmSync(`tmp/${owner}/${repo}`, { recursive: true, force: true });
|
||||
fs.mkdirSync(`tmp/${owner}/${repo}`, { recursive: true, force: true });
|
||||
await runProcess(id, "git", ["clone", `https://github.com/${owner}/${repo}.git`], `tmp/${owner}`)
|
||||
await runProcess(id, "docker", ["build", "--rm", "-f", "./Dockerfile", "-t", `github-${owner}:${repo}`, "."], `tmp/${owner}/${repo}`)
|
||||
progress[id].done = true
|
||||
}
|
||||
|
||||
export const importTrigger = (req, res) => {
|
||||
const owner = req.params.owner
|
||||
const repo = req.params.repo
|
||||
const id = req.params.owner + '/' + req.params.repo
|
||||
if(!/^[\w.-]+\/[\w.-]+$/.test(id)) { res.send(`Invalid repo name ${id}`); return }
|
||||
|
||||
if(!progress[id] || progress[id].done) {
|
||||
progress[id] = {output: "", done: false}
|
||||
doImport(owner, repo, id)
|
||||
}
|
||||
|
||||
res.redirect(`/import/status/${owner}/${repo}`)
|
||||
}
|
||||
|
||||
export const importStatus = (req, res) => {
|
||||
const owner = req.params.owner
|
||||
const repo = req.params.repo
|
||||
const id = req.params.owner + '/' + req.params.repo
|
||||
res.send(`<html><head><meta http-equiv="refresh" content="2"></head><body><pre>${progress[id]?.output ?? "Nothing here."}</pre></body></html>`)
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import { spawn } from 'child_process'
|
||||
import fs from 'fs';
|
||||
import request from 'request'
|
||||
import requestProgress from 'request-progress'
|
||||
import { Octokit } from 'octokit';
|
||||
|
||||
const TOKEN = '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'
|
||||
const octokit = new Octokit({
|
||||
auth: TOKEN
|
||||
})
|
||||
|
||||
const progress = {}
|
||||
|
||||
async function runProcess(id, cmd, args, cwd) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const ls = spawn(cmd, args, {cwd});
|
||||
|
||||
ls.stdout.on('data', (data) => {
|
||||
progress[id].output += data.toString()
|
||||
});
|
||||
|
||||
ls.stderr.on('data', (data) => {
|
||||
progress[id].output += data.toString()
|
||||
});
|
||||
|
||||
ls.on('close', (code) => {
|
||||
resolve()
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
async function download(id, url, dest) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// The options argument is optional so you can omit it
|
||||
requestProgress(request({
|
||||
url,
|
||||
headers: {
|
||||
'User-Agent': 'abentkamp',
|
||||
'X-GitHub-Api-Version': '2022-11-28',
|
||||
'Authorization': 'Bearer '+TOKEN
|
||||
}
|
||||
}))
|
||||
.on('progress', function (state) {
|
||||
progress[id].output += `Downloaded ${Math.round(state.size.transferred/1024/1024)}MB\n`
|
||||
})
|
||||
.on('error', function (err) {
|
||||
reject(err)
|
||||
})
|
||||
.on('end', function () {
|
||||
resolve()
|
||||
})
|
||||
.pipe(fs.createWriteStream(dest));
|
||||
})
|
||||
}
|
||||
|
||||
async function doImport (owner, repo, id) {
|
||||
|
||||
const artifacts = await octokit.request('GET /repos/{owner}/{repo}/actions/artifacts', {
|
||||
owner,
|
||||
repo,
|
||||
headers: {
|
||||
'X-GitHub-Api-Version': '2022-11-28'
|
||||
}
|
||||
})
|
||||
const artifact = artifacts.data.artifacts[0]
|
||||
const url = artifact.archive_download_url
|
||||
progress[id].output += `Download from ${url}\n`
|
||||
await download(id, url, "testfile")
|
||||
progress[id].output += `Download finished.\n`
|
||||
progress[id].done = true
|
||||
}
|
||||
|
||||
export const importTrigger = (req, res) => {
|
||||
const owner = req.params.owner
|
||||
const repo = req.params.repo
|
||||
const id = req.params.owner + '/' + req.params.repo
|
||||
if(!/^[\w.-]+\/[\w.-]+$/.test(id)) { res.send(`Invalid repo name ${id}`); return }
|
||||
|
||||
if(!progress[id] || progress[id].done) {
|
||||
progress[id] = {output: "", done: false}
|
||||
doImport(owner, repo, id)
|
||||
}
|
||||
|
||||
res.redirect(`/import/status/${owner}/${repo}`)
|
||||
}
|
||||
|
||||
export const importStatus = (req, res) => {
|
||||
const owner = req.params.owner
|
||||
const repo = req.params.repo
|
||||
const id = req.params.owner + '/' + req.params.repo
|
||||
res.send(`<html><head><meta http-equiv="refresh" content="5"></head><body><pre>${progress[id]?.output ?? "Nothing here."}</pre></body></html>`)
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import * as rpc from 'vscode-ws-jsonrpc';
|
||||
import * as jsonrpcserver from 'vscode-ws-jsonrpc/server';
|
||||
import os from 'os';
|
||||
import anonymize from 'ip-anonymize';
|
||||
import { importTrigger, importStatus } from './import.mjs'
|
||||
|
||||
const games = {
|
||||
adam: {
|
||||
@@ -30,8 +31,14 @@ const app = express()
|
||||
|
||||
const PORT = process.env.PORT || 8080;
|
||||
|
||||
var router = express.Router();
|
||||
|
||||
router.get('/import/status/:owner/:repo', importStatus)
|
||||
router.get('/import/trigger/:owner/:repo', importTrigger)
|
||||
|
||||
const server = app
|
||||
.use(express.static(path.join(__dirname, '../client/dist/')))
|
||||
.use('/', router)
|
||||
.listen(PORT, () => console.log(`Listening on ${PORT}`));
|
||||
|
||||
const wss = new WebSocketServer({ server })
|
||||
|
||||
@@ -68,6 +68,10 @@ module.exports = env => {
|
||||
target: 'ws://localhost:8080',
|
||||
ws: true
|
||||
},
|
||||
'/import': {
|
||||
target: 'http://localhost:3000',
|
||||
router: () => 'http://localhost:8080',
|
||||
},
|
||||
},
|
||||
static: path.join(__dirname, 'client/public/'),
|
||||
port: 3000,
|
||||
|
||||
Reference in New Issue
Block a user