Skip to content

Commit

Permalink
Auto release game assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikk155 committed May 2, 2024
1 parent 412e218 commit 3de24b3
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 17 deletions.
51 changes: 35 additions & 16 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ on:
branches:
- main
paths:
- 'src/*'
# Only on when updating RELEASE_VERSION
- '.github/workflows/ci-cd.yml'

permissions:
contents: write
Expand All @@ -20,6 +21,24 @@ env:
VCPKG_ROOT: ${{github.workspace}}/vcpkg

jobs:
python:
name: Package Game Assets
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Installing Python
run: |
pip install --upgrade pip
pip install -r requirements.txt
- name: Release
env:
TOKEN: ${{ secrets.TOKEN }}
run: python3 scripts/install_game_assets.py ${{ env.RELEASE_VERSION }}

linux:
name: Linux-x86
runs-on: ubuntu-latest
Expand All @@ -28,34 +47,34 @@ jobs:
uses: actions/checkout@v3
with:
submodules: recursive

- name: Install G++ Multilib & 32 bit OpenGL library
run: |
sudo dpkg --add-architecture i386
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install -y g++-11-multilib libgcc-s1:i386 libstdc++6:i386 libatomic1:i386 libgl1-mesa-dev:i386
- uses: lukka/get-cmake@latest

- name: Restore artifacts, setup vcpkg
uses: lukka/run-vcpkg@v10
with:
vcpkgDirectory: '${{env.VCPKG_ROOT}}'
runVcpkgInstall: false
vcpkgJsonIgnores: "['**/vcpkg/**', '**/vcpkg_config/**', '**/utils/**']"

- name: Configure
run: >
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=${{env.GAME_NAME}}/${{env.MOD_NAME}}
-DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/cmake/LinuxToolchain.cmake
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j3

- name: Install
run: cmake --install ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Create Release
uses: xresloader/upload-to-github-release@v1.5.0
env:
Expand All @@ -74,7 +93,7 @@ jobs:
update_release_body_path: changelog.md
target_owner: Mikk155
target_repo: halflife-unified-sdk

win32:
name: Win32
runs-on: windows-latest
Expand All @@ -83,28 +102,28 @@ jobs:
uses: actions/checkout@v3
with:
submodules: recursive

- uses: lukka/get-cmake@latest

- name: Restore artifacts, setup vcpkg
uses: lukka/run-vcpkg@v10
with:
vcpkgDirectory: '${{env.VCPKG_ROOT}}'
runVcpkgInstall: false
vcpkgJsonIgnores: "['**/vcpkg/**', '**/vcpkg_config/**', '**/utils/**']"

- name: Configure
run: >
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=${{env.GAME_NAME}}/${{env.MOD_NAME}}
-DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/cmake/WindowsToolchain.cmake -A Win32
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j3

- name: Install
run: cmake --install ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}


- name: Create Release
uses: xresloader/upload-to-github-release@v1.5.0
env:
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PyGithub==2.3.0
79 changes: 79 additions & 0 deletions scripts/install_game_assets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import os, requests, shutil, sys, zipfile
from github import Github, GithubException

user = 'Mikk155'
repository = 'halflife-unified-SDK'

url = f"https://github.com/{user}/{repository}/archive/game-assets.zip"

access_token = os.getenv( "TOKEN" )

response = requests.get( url, stream = True )

abs = os.path.abspath( '' )

with open( f'{abs}/game-assets.zip', 'wb') as z:

shutil.copyfileobj( response.raw, z )

with zipfile.ZipFile( f'{abs}/game-assets.zip', 'r') as z:

z.extractall( f'{abs}/game-assets' )
z.close()

os.rename( f'{abs}/game-assets/halflife-unified-sdk-game-assets/', f'{abs}/game-assets/lp' )

os.remove( f'{abs}/game-assets.zip' )

with zipfile.ZipFile( f'{abs}/game-assets.zip', 'w', zipfile.ZIP_DEFLATED ) as z:

for root, _, files in os.walk( 'game-assets' ):

for file in files:

absp = os.path.join(root, file)

relp = os.path.relpath( absp, 'game-assets' )

z.write( absp, relp )
dbg = relp[ relp.rfind( '\\' ) + 1 : ]
print( f'Compressing {dbg}')

access_token = os.getenv( "TOKEN" )

g = Github(access_token)

repo = g.get_repo( f'{user}/{repository}')

tag_name = sys.argv[1]

try:

release = repo.create_git_release(tag_name, tag_name, f"# {tag_name}" )

new_body = ""

changelog = os.path.join( os.path.dirname(__file__), f'../changelog.md' )

with open( changelog, 'r') as cl:

for line in cl.readlines():

new_body = f'{new_body}{line}'

cl.close()

if new_body:
release.update_release(release.title, new_body)

release.upload_asset(f'{abs}/game-assets.zip', label='game-assets.zip')

print(f'Updated release for "{tag_name}"')

except GithubException as e:

if e.status == 422:

print(f'Release with tag "{tag_name}" already exists.')

exit(1)
2 changes: 1 addition & 1 deletion website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="block"><br>
<a href="en/index.html">English</a><br>
<a href="es/index.html">Español</a><br>
<a href="changelog.md">Changelog</a><br>
<a href="../changelog.md" target="_blank">Changelog</a><br>
<br></div>
</body>
</html>

0 comments on commit 3de24b3

Please sign in to comment.