From c88fdadeb68a82903f47ba62f93e26f820685531 Mon Sep 17 00:00:00 2001 From: MaxSMokeSkaarj Date: Sat, 8 Mar 2025 14:35:42 +1000 Subject: [PATCH] =?utf8?q?=D0=90=D0=B2=D1=82=D0=BE=D0=BE=D0=B1=D0=BD=D0=BE?= =?utf8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20SS14?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ...{publish-testing.yml => publish-local.yml} | 2 +- Tools/publish_multi_request.mjs | 89 ------------------- Tools/publish_multi_request_local.py | 85 ++++++++++++++++++ 3 files changed, 86 insertions(+), 90 deletions(-) rename .github/workflows/{publish-testing.yml => publish-local.yml} (93%) delete mode 100644 Tools/publish_multi_request.mjs create mode 100755 Tools/publish_multi_request_local.py diff --git a/.github/workflows/publish-testing.yml b/.github/workflows/publish-local.yml similarity index 93% rename from .github/workflows/publish-testing.yml rename to .github/workflows/publish-local.yml index aa3b35dea1..304bce3d4f 100644 --- a/.github/workflows/publish-testing.yml +++ b/.github/workflows/publish-local.yml @@ -39,7 +39,7 @@ jobs: run: dotnet run --project Content.Packaging client --no-wipe-release - name: Publish version - run: Tools/publish_multi_request.py --fork-id wizards-testing + run: Tools/publish_multi_request_local.py env: PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }} GITHUB_REPOSITORY: ${{ vars.GITHUB_REPOSITORY }} diff --git a/Tools/publish_multi_request.mjs b/Tools/publish_multi_request.mjs deleted file mode 100644 index cd2ffab4f1..0000000000 --- a/Tools/publish_multi_request.mjs +++ /dev/null @@ -1,89 +0,0 @@ -#!/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/Tools/publish_multi_request_local.py b/Tools/publish_multi_request_local.py new file mode 100755 index 0000000000..fac0400857 --- /dev/null +++ b/Tools/publish_multi_request_local.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 + +import argparse +import requests +import os +import subprocess +from typing import Iterable + +PUBLISH_TOKEN = os.environ["PUBLISH_TOKEN"] +VERSION = os.environ["GITHUB_SHA"] + +RELEASE_DIR = "release" + +# +# CONFIGURATION PARAMETERS +# Forks should change these to publish to their own infrastructure. +# +ROBUST_CDN_URL = "http://192.168.255.254:27690/" +FORK_ID = "main" + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--fork-id", default=FORK_ID) + + args = parser.parse_args() + fork_id = args.fork_id + + session = requests.Session() + session.headers = { + "Authorization": f"Bearer {PUBLISH_TOKEN}", + } + + print(f"Starting publish on Robust.Cdn for version {VERSION}") + + data = { + "version": VERSION, + "engineVersion": get_engine_version(), + } + headers = { + "Content-Type": "application/json" + } + resp = session.post(f"{ROBUST_CDN_URL}fork/{fork_id}/publish/start", json=data, headers=headers) + resp.raise_for_status() + print("Publish successfully started, adding files...") + + for file in get_files_to_publish(): + print(f"Publishing {file}") + with open(file, "rb") as f: + headers = { + "Content-Type": "application/octet-stream", + "Robust-Cdn-Publish-File": os.path.basename(file), + "Robust-Cdn-Publish-Version": VERSION + } + resp = session.post(f"{ROBUST_CDN_URL}fork/{fork_id}/publish/file", data=f, headers=headers) + + resp.raise_for_status() + + print("Successfully pushed files, finishing publish...") + + data = { + "version": VERSION + } + headers = { + "Content-Type": "application/json" + } + resp = session.post(f"{ROBUST_CDN_URL}fork/{fork_id}/publish/finish", json=data, headers=headers) + resp.raise_for_status() + + print("SUCCESS!") + + +def get_files_to_publish() -> Iterable[str]: + for file in os.listdir(RELEASE_DIR): + yield os.path.join(RELEASE_DIR, file) + + +def get_engine_version() -> str: + proc = subprocess.run(["git", "describe","--tags", "--abbrev=0"], stdout=subprocess.PIPE, cwd="RobustToolbox", check=True, encoding="UTF-8") + tag = proc.stdout.strip() + assert tag.startswith("v") + return tag[1:] # Cut off v prefix. + + +if __name__ == '__main__': + main() -- 2.52.0