From d9205ae86299f8808a8c54fe2308589b8bf722a8 Mon Sep 17 00:00:00 2001 From: PythiaUF <125420118+PythiaUF@users.noreply.github.com> Date: Wed, 2 Oct 2024 23:40:45 -0400 Subject: [PATCH] ci: create build ci for push/prs --- .github/workflows/build.yml | 50 ++++++++++++++++++++++++++++++++++++ .github/workflows/process.py | 31 ++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/process.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..cd2a25c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,50 @@ +name: Build Bytes of Love +on: + - push + - pull_request + +jobs: + renpy-build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Extract short commit hash + shell: bash + run: echo "git_hash=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_OUTPUT + id: ref + + - name: Setup Ren'Py and Build + run: | + wget https://www.renpy.org/dl/8.3.2/renpy-8.3.2-sdk.tar.bz2 + tar -xf renpy-8.3.2-sdk.tar.bz2 + ( cd renpy-8.3.2-sdk && ./renpy.sh launcher distribute ../BytesOfLove --destination ../dist --package win --package mac --package linux ) + + - name: Process Files + run: python .github/workflows/process.py ${{ steps.ref.outputs.git_hash }} + + - name: Upload Linux Build + uses: actions/upload-artifact@v4 + with: + name: BytesOfLove-linux-${{ steps.ref.outputs.git_hash }} + path: dist/BytesOfLove-linux-${{ steps.ref.outputs.git_hash }}.tar.bz2 + compression-level: 0 + + - name: Upload Mac Build + uses: actions/upload-artifact@v4 + with: + name: BytesOfLove-mac-${{ steps.ref.outputs.git_hash }} + path: dist/BytesOfLove-mac-${{ steps.ref.outputs.git_hash }}.zip + compression-level: 0 + + - name: Upload Windows Build + uses: actions/upload-artifact@v4 + with: + name: BytesOfLove-win-${{ steps.ref.outputs.git_hash }} + path: dist/BytesOfLove-win-${{ steps.ref.outputs.git_hash }} \ No newline at end of file diff --git a/.github/workflows/process.py b/.github/workflows/process.py new file mode 100644 index 0000000..bac089b --- /dev/null +++ b/.github/workflows/process.py @@ -0,0 +1,31 @@ +import sys +from pathlib import Path +from zipfile import ZipFile + +commit_hash = sys.argv[1] + +files = Path("dist").glob('*') + +for a_file in files: + if not a_file.is_file(): + continue + + if a_file.suffix == ".zip": + platform = a_file.stem.split("-")[-1].removesuffix(".zip") + + if platform == "win": + print("Extracting", a_file) + with ZipFile(a_file, 'r') as zip_ref: + zip_ref.extractall(f"dist/BytesOfLove-{platform}-{commit_hash}") + print("Extracted", a_file) + else: + # due to https://github.com/actions/upload-artifact?tab=readme-ov-file#permission-loss, + # we don't want to extract the file in the fears of losing certain permissions + # windows doesn't care though + print("Renaming", a_file) + a_file.rename(f"dist/BytesOfLove-{platform}-{commit_hash}.zip") + + elif a_file.suffix == ".bz2": + # see above + print("Renaming", a_file) + a_file.rename("dist/BytesOfLove-linux-" + commit_hash + ".tar.bz2") \ No newline at end of file