New CDN publish workflow (#30009)
* LET'S SEE IF THIS WORKS * I forgot the chmod +x * I forgot the shebang
This commit is contained in:
committed by
GitHub
parent
bf4ef62ab3
commit
5e800e0ece
42
.github/workflows/publish.yml
vendored
42
.github/workflows/publish.yml
vendored
@@ -41,31 +41,22 @@ jobs:
|
|||||||
- name: Package client
|
- name: Package client
|
||||||
run: dotnet run --project Content.Packaging client --no-wipe-release
|
run: dotnet run --project Content.Packaging client --no-wipe-release
|
||||||
|
|
||||||
- name: Update Build Info
|
- name: Upload build artifact
|
||||||
run: Tools/gen_build_info.py
|
id: artifact-upload-step
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
- name: Shuffle files around
|
|
||||||
run: |
|
|
||||||
mkdir "release/${{ github.sha }}"
|
|
||||||
mv release/*.zip "release/${{ github.sha }}"
|
|
||||||
|
|
||||||
- name: Upload files to centcomm
|
|
||||||
uses: appleboy/scp-action@master
|
|
||||||
with:
|
with:
|
||||||
host: centcomm.spacestation14.io
|
name: build
|
||||||
username: wizards-build-push
|
path: release/*.zip
|
||||||
key: ${{ secrets.CENTCOMM_WIZARDS_BUILDS_PUSH_KEY }}
|
compression-level: 0
|
||||||
source: "release/${{ github.sha }}"
|
retention-days: 0
|
||||||
target: "/home/wizards-build-push/builds_dir/builds/"
|
|
||||||
strip_components: 1
|
|
||||||
|
|
||||||
- name: Update manifest JSON
|
- name: Publish version
|
||||||
uses: appleboy/ssh-action@master
|
run: Tools/publish_github_artifact.py
|
||||||
with:
|
env:
|
||||||
host: centcomm.spacestation14.io
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
username: wizards-build-push
|
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
|
||||||
key: ${{ secrets.CENTCOMM_WIZARDS_BUILDS_PUSH_KEY }}
|
ARTIFACT_ID: ${{ steps.artifact-upload-step.outputs.artifact-id }}
|
||||||
script: /home/wizards-build-push/push.ps1 ${{ github.sha }}
|
GITHUB_REPOSITORY: ${{ vars.GITHUB_REPOSITORY }}
|
||||||
|
|
||||||
- name: Publish changelog (Discord)
|
- name: Publish changelog (Discord)
|
||||||
run: Tools/actions_changelogs_since_last_run.py
|
run: Tools/actions_changelogs_since_last_run.py
|
||||||
@@ -77,3 +68,8 @@ jobs:
|
|||||||
run: Tools/actions_changelog_rss.py
|
run: Tools/actions_changelog_rss.py
|
||||||
env:
|
env:
|
||||||
CHANGELOG_RSS_KEY: ${{ secrets.CHANGELOG_RSS_KEY }}
|
CHANGELOG_RSS_KEY: ${{ secrets.CHANGELOG_RSS_KEY }}
|
||||||
|
|
||||||
|
- uses: geekyeggo/delete-artifact@v5
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
name: build
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ EndProject
|
|||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{806ED41A-411B-4B3B-BEB6-DEC6DCA4C205}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{806ED41A-411B-4B3B-BEB6-DEC6DCA4C205}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
Tools\generate_hashes.ps1 = Tools\generate_hashes.ps1
|
Tools\generate_hashes.ps1 = Tools\generate_hashes.ps1
|
||||||
Tools\gen_build_info.py = Tools\gen_build_info.py
|
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Robust.Shared.Scripting", "RobustToolbox\Robust.Shared.Scripting\Robust.Shared.Scripting.csproj", "{41B450C0-A361-4CD7-8121-7072B8995CFC}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Robust.Shared.Scripting", "RobustToolbox\Robust.Shared.Scripting\Robust.Shared.Scripting.csproj", "{41B450C0-A361-4CD7-8121-7072B8995CFC}"
|
||||||
|
|||||||
@@ -1,96 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
# Generates build info and injects it into the server zip files.
|
|
||||||
|
|
||||||
import codecs
|
|
||||||
import hashlib
|
|
||||||
import io
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
from zipfile import ZipFile, ZIP_DEFLATED
|
|
||||||
|
|
||||||
FILE = "SS14.Client.zip"
|
|
||||||
|
|
||||||
SERVER_FILES = [
|
|
||||||
"SS14.Server_linux-x64.zip",
|
|
||||||
"SS14.Server_linux-arm64.zip",
|
|
||||||
"SS14.Server_win-x64.zip",
|
|
||||||
"SS14.Server_osx-x64.zip"
|
|
||||||
]
|
|
||||||
|
|
||||||
VERSION = os.environ['GITHUB_SHA']
|
|
||||||
FORK_ID = "wizards"
|
|
||||||
BUILD_URL = f"https://cdn.centcomm.spacestation14.com/builds/wizards/builds/{{FORK_VERSION}}/{FILE}"
|
|
||||||
MANIFEST_URL = f"https://cdn.centcomm.spacestation14.com/cdn/version/{{FORK_VERSION}}/manifest"
|
|
||||||
MANIFEST_DOWNLOAD_URL = f"https://cdn.centcomm.spacestation14.com/cdn/version/{{FORK_VERSION}}/download"
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
client_file = os.path.join("release", FILE)
|
|
||||||
manifest = generate_build_json(client_file)
|
|
||||||
|
|
||||||
for server in SERVER_FILES:
|
|
||||||
inject_manifest(os.path.join("release", server), manifest)
|
|
||||||
|
|
||||||
|
|
||||||
def inject_manifest(zip_path: str, manifest: str) -> None:
|
|
||||||
with ZipFile(zip_path, "a", compression=ZIP_DEFLATED) as z:
|
|
||||||
z.writestr("build.json", manifest)
|
|
||||||
|
|
||||||
|
|
||||||
def generate_build_json(file: str) -> str:
|
|
||||||
# Env variables set by Jenkins.
|
|
||||||
|
|
||||||
hash = sha256_file(file)
|
|
||||||
engine_version = get_engine_version()
|
|
||||||
manifest_hash = generate_manifest_hash(file)
|
|
||||||
|
|
||||||
return json.dumps({
|
|
||||||
"download": BUILD_URL,
|
|
||||||
"hash": hash,
|
|
||||||
"version": VERSION,
|
|
||||||
"fork_id": FORK_ID,
|
|
||||||
"engine_version": engine_version,
|
|
||||||
"manifest_url": MANIFEST_URL,
|
|
||||||
"manifest_download_url": MANIFEST_DOWNLOAD_URL,
|
|
||||||
"manifest_hash": manifest_hash
|
|
||||||
})
|
|
||||||
|
|
||||||
def generate_manifest_hash(file: str) -> str:
|
|
||||||
zip = ZipFile(file)
|
|
||||||
infos = zip.infolist()
|
|
||||||
infos.sort(key=lambda i: i.filename)
|
|
||||||
|
|
||||||
bytesIO = io.BytesIO()
|
|
||||||
writer = codecs.getwriter("UTF-8")(bytesIO)
|
|
||||||
writer.write("Robust Content Manifest 1\n")
|
|
||||||
|
|
||||||
for info in infos:
|
|
||||||
if info.filename[-1] == "/":
|
|
||||||
continue
|
|
||||||
|
|
||||||
bytes = zip.read(info)
|
|
||||||
hash = hashlib.blake2b(bytes, digest_size=32).hexdigest().upper()
|
|
||||||
writer.write(f"{hash} {info.filename}\n")
|
|
||||||
|
|
||||||
manifestHash = hashlib.blake2b(bytesIO.getbuffer(), digest_size=32)
|
|
||||||
|
|
||||||
return manifestHash.hexdigest().upper()
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
|
|
||||||
def sha256_file(path: str) -> str:
|
|
||||||
with open(path, "rb") as f:
|
|
||||||
h = hashlib.sha256()
|
|
||||||
for b in iter(lambda: f.read(4096), b""):
|
|
||||||
h.update(b)
|
|
||||||
|
|
||||||
return h.hexdigest()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
56
Tools/publish_github_artifact.py
Executable file
56
Tools/publish_github_artifact.py
Executable file
@@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
GITHUB_TOKEN = os.environ["GITHUB_TOKEN"]
|
||||||
|
PUBLISH_TOKEN = os.environ["PUBLISH_TOKEN"]
|
||||||
|
ARTIFACT_ID = os.environ["ARTIFACT_ID"]
|
||||||
|
GITHUB_REPOSITORY = os.environ["GITHUB_REPOSITORY"]
|
||||||
|
VERSION = os.environ['GITHUB_SHA']
|
||||||
|
|
||||||
|
#
|
||||||
|
# CONFIGURATION PARAMETERS
|
||||||
|
# Forks should change these to publish to their own infrastructure.
|
||||||
|
#
|
||||||
|
ROBUST_CDN_URL = "https://wizards.cdn.spacestation14.com/"
|
||||||
|
FORK_ID = "wizards"
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("Fetching artifact URL from API...")
|
||||||
|
artifact_url = get_artifact_url()
|
||||||
|
print(f"Artifact URL is {artifact_url}, publishing to Robust.Cdn")
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"version": VERSION,
|
||||||
|
"engineVersion": get_engine_version(),
|
||||||
|
"archive": artifact_url
|
||||||
|
}
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {PUBLISH_TOKEN}",
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
resp = requests.post(f"{ROBUST_CDN_URL}fork/{FORK_ID}/publish", json=data, headers=headers)
|
||||||
|
resp.raise_for_status()
|
||||||
|
print("Publish succeeded!")
|
||||||
|
|
||||||
|
def get_artifact_url() -> str:
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {GITHUB_TOKEN}",
|
||||||
|
"X-GitHub-Api-Version": "2022-11-28"
|
||||||
|
}
|
||||||
|
resp = requests.get(f"https://api.github.com/repos/{GITHUB_REPOSITORY}/actions/artifacts/{ARTIFACT_ID}/zip", allow_redirects=False, headers=headers)
|
||||||
|
resp.raise_for_status()
|
||||||
|
|
||||||
|
return resp.headers["Location"]
|
||||||
|
|
||||||
|
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()
|
||||||
Reference in New Issue
Block a user