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 }}
+++ /dev/null
-#!/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!");
--- /dev/null
+#!/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()