Skip to content

Commit

Permalink
Publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidenkrz committed Oct 16, 2024
1 parent 5157497 commit 0d38ad8
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 60 deletions.
66 changes: 34 additions & 32 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# From https://github.com/DeltaV-Station/Delta-v/
name: PR Changelogs
concurrency: commit_action
on:
Expand All @@ -16,40 +17,41 @@ jobs:
permissions:
contents: write
steps:
- name: Checkout Master
uses: actions/checkout@v3
with:
token: ${{ secrets.BOT_TOKEN }}
ref: ${{ vars.CHANGELOG_BRANCH }}
- name: Checkout Master
uses: actions/checkout@v3
with:
token: ${{ secrets.BOT_TOKEN }}
ref: "${{ vars.CHANGELOG_BRANCH }}"

- name: Setup Git
run: |
git config --global user.name "${{ vars.CHANGELOG_USER }}"
git config --global user.email "${{ vars.CHANGELOG_EMAIL }}"
shell: bash
- name: Setup Git
run: |
git config --global user.name "${{ vars.CHANGELOG_USER }}"
git config --global user.email "${{ vars.CHANGELOG_EMAIL }}"
shell: bash

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Install Dependencies
run: |
cd "Tools/changelogs"
npm install
shell: bash
- name: Install Dependencies
run: |
cd "Tools/changelog"
npm install
shell: bash
continue-on-error: true

- name: Generate Changelog
run: |
cd "Tools/changelogs"
node changelog.js
shell: bash
- name: Generate Changelog
run: |
cd "Tools/changelog"
node changelog.js
shell: bash
continue-on-error: true

- name: Commit Changelog
run: |
git pull origin master
git add *.yml
git commit -m "${{ vars.CHANGELOG_MESSAGE }} (#${{ env.PR_NUMBER }})"
git push
shell: bash
continue-on-error: true
- name: Commit Changelog
run: |
git add *.yml
git commit -m "${{ vars.CHANGELOG_MESSAGE }} (#${{ env.PR_NUMBER }})"
git push
shell: bash
continue-on-error: true
34 changes: 6 additions & 28 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v3.2.0
with:
dotnet-version: 8.0.100
dotnet-version: 8.0.x

- name: Get Engine Tag
run: |
Expand All @@ -41,33 +41,11 @@ 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 version
run: Tools/publish_multi_request.py
env:
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
GITHUB_REPOSITORY: ${{ vars.GITHUB_REPOSITORY }}

- name: Publish changelog (Discord)
run: Tools/actions_changelogs_since_last_run.py
Expand Down
56 changes: 56 additions & 0 deletions Tools/publish_github_artifact.py
Original file line number Diff line number Diff line change
@@ -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://cdn.simplestation.org/"
FORK_ID = "goobstation-mrp"

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()
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 = "goobstation-mrp"

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 0d38ad8

Please sign in to comment.