diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 98f051969..ae5726b95 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -5,7 +5,8 @@ on: branches: - main paths: - - 'src/*' + # Only on when updating RELEASE_VERSION + - '.github/workflows/ci-cd.yml' permissions: contents: write @@ -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 @@ -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: @@ -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 @@ -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: diff --git a/website/changelog.md b/changelog.md similarity index 100% rename from website/changelog.md rename to changelog.md diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..0ee8b5539 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +PyGithub==2.3.0 diff --git a/scripts/install_game_assets.py b/scripts/install_game_assets.py new file mode 100644 index 000000000..419079bb9 --- /dev/null +++ b/scripts/install_game_assets.py @@ -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) diff --git a/website/index.html b/website/index.html index 5d5d15a67..81a67d9fb 100644 --- a/website/index.html +++ b/website/index.html @@ -13,7 +13,7 @@