Skip to content

Commit

Permalink
Update CDN Scripts & Automatically Build Releases (#1097)
Browse files Browse the repository at this point in the history
  • Loading branch information
DEATHB4DEFEAT authored Oct 19, 2024
1 parent 0f73ebf commit f92a126
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 32 deletions.
42 changes: 10 additions & 32 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,17 @@ jobs:
- name: Package client
run: dotnet run --project Content.Packaging client --no-wipe-release

- name: Update Build Info
run: Tools/gen_build_info.py

- 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:
host: ${{ secrets.PUBLISH_HOST }}
username: ${{ secrets.PUBLISH_USER }}
key: ${{ secrets.PUBLISH_KEY }}
port: ${{ secrets.PUBLISH_PORT }}
source: "release/${{ github.sha }}"
target: "/var/www/builds.delta-v.org/delta-v/builds/"
strip_components: 1

- name: Update manifest JSON
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PUBLISH_HOST }}
username: ${{ secrets.PUBLISH_USER }}
key: ${{ secrets.PUBLISH_KEY }}
port: ${{ secrets.PUBLISH_PORT }}
script: /home/deltav/publish/push.ps1 ${{ github.sha }}

- name: Publish changelog (Discord)
run: Tools/actions_changelogs_since_last_run.py
- name: Publish version
run: Tools/publish_multi_request.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DISCORD_WEBHOOK_URL: ${{ secrets.CHANGELOG_DISCORD_WEBHOOK }}
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
GITHUB_REPOSITORY: ${{ vars.GITHUB_REPOSITORY }}

# - name: Publish changelog (Discord)
# run: Tools/actions_changelogs_since_last_run.py
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# DISCORD_WEBHOOK_URL: ${{ secrets.CHANGELOG_DISCORD_WEBHOOK }}

- name: Publish changelog (RSS)
run: Tools/actions_changelog_rss.py
Expand Down
78 changes: 78 additions & 0 deletions Tools/publish_multi_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env python3

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 = "https://cdn.simplestation.org/"
FORK_ID = "einstein-engines"

def main():
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()

0 comments on commit f92a126

Please sign in to comment.