From 34a45bcc4a4e31840547b702eafbe80488ef4516 Mon Sep 17 00:00:00 2001 From: MaxSMokeSkaarj Date: Sun, 12 Jan 2025 15:03:32 +1000 Subject: [PATCH] =?utf8?q?=D0=BE=D1=82=D0=BA=D0=B0=D1=82=20=D0=BF=D0=B8?= =?utf8?q?=D0=B7=D0=B4=D0=B5=D1=86=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Corvax-SS14 | 2 +- RobustToolbox | 2 +- Tools/publish_multi_request.mjs | 89 +++++++++++++++++++++++++++++++++ publish.sh | 8 --- 4 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 Tools/publish_multi_request.mjs delete mode 100755 publish.sh diff --git a/Corvax-SS14 b/Corvax-SS14 index e301f52e65..51eb319109 160000 --- a/Corvax-SS14 +++ b/Corvax-SS14 @@ -1 +1 @@ -Subproject commit e301f52e655c57d6df4a0475e75eb4b24f64e0e4 +Subproject commit 51eb31910902353a4df65ff4a3e3eb4a50edaafd diff --git a/RobustToolbox b/RobustToolbox index e4190f4f29..e47ba0faea 160000 --- a/RobustToolbox +++ b/RobustToolbox @@ -1 +1 @@ -Subproject commit e4190f4f2900634e332208a77cd6df9cef75c29a +Subproject commit e47ba0faea6b1143f4810547b3d617a110bdb6a5 diff --git a/Tools/publish_multi_request.mjs b/Tools/publish_multi_request.mjs new file mode 100644 index 0000000000..cd2ffab4f1 --- /dev/null +++ b/Tools/publish_multi_request.mjs @@ -0,0 +1,89 @@ +#!/usr/bin/env node + +import fs from 'fs'; +import path from 'path'; +import https from 'https'; +import { execSync } from 'child_process'; + +const PUBLISH_TOKEN = process.env.PUBLISH_TOKEN; +const VERSION = process.env.GITHUB_SHA; + +const RELEASE_DIR = 'release'; +const ROBUST_CDN_URL = 'https://ss14.smokeofanarchy.ru/cdn/'; +const FORK_ID = 'main'; + + +function getFilesToPublish() { + return fs.readdirSync(RELEASE_DIR).map(file => path.join(RELEASE_DIR, file)); +} + +function getEngineVersion() { + const tag = execSync('git describe --tags --abbrev=0', { cwd: 'RobustToolbox', encoding: 'utf-8' }).trim(); + if (!tag.startsWith('v')) throw new Error('Tag does not start with v'); + return tag.slice(1); // Cut off v prefix. +} + +function postRequest(url, data, customHeaders = {}) { + return new Promise((resolve, reject) => { + const req = https.request(url, { + method: 'POST', + headers: { + 'Authorization': `Bearer ${PUBLISH_TOKEN}`, + 'Content-Type': 'application/json', + ...customHeaders, + }, + }, (res) => { + let body = ''; + res.on('data', chunk => { + body += chunk; + }); + res.on('end', () => { + if (res.statusCode >= 200 && res.statusCode < 300) { + resolve(body); + } else { + reject(new Error(`Request failed with status code ${res.statusCode}: ${body}`)); + } + }); + }); + + req.on('error', (e) => { + reject(e); + }); + + if (data instanceof fs.ReadStream) { + data.pipe(req); + } else { + req.write(JSON.stringify(data)); + } + req.end(); + }); +} + +console.log(`Starting publish on Robust.Cdn for version ${VERSION}`); + +const data = { + version: VERSION, + engineVersion: getEngineVersion(), +}; + +await postRequest(`${ROBUST_CDN_URL}fork/${FORK_ID}/publish/start`, data); + +console.log("Publish successfully started, adding files..."); + +for (const file of getFilesToPublish()) { + console.log(`Publishing ${file}`); + const fileStream = fs.createReadStream(file); + const headers = { + 'Content-Type': 'application/octet-stream', + 'Robust-Cdn-Publish-File': path.basename(file), + 'Robust-Cdn-Publish-Version': VERSION, + }; + + await postRequest(`${ROBUST_CDN_URL}fork/${FORK_ID}/publish/file`, fileStream, headers); +} + +console.log("Successfully pushed files, finishing publish..."); + +await postRequest(`${ROBUST_CDN_URL}fork/${FORK_ID}/publish/finish`, { version: VERSION }); + +console.log("SUCCESS!"); diff --git a/publish.sh b/publish.sh deleted file mode 100755 index 44bd83c66a..0000000000 --- a/publish.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -cd RobustToolbox -git fetch --depth=1 -cd .. -dotnet restore -dotnet build Content.Packaging --configuration Release --no-restore /m -dotnet run --project Content.Packaging server --platform win-x64 --platform linux-x64 --platform osx-x64 --platform linux-arm64 -dotnet run --project Content.Packaging client --no-wipe-release -- 2.52.0