From 31fcff13e97003f4c865bfc0f57705898625fdae Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sun, 4 Feb 2024 00:36:58 -0500 Subject: [PATCH] CI Improvements --- .gitea/workflows/build.yml | 41 +++++++++++++++++++++++++++++------ scripts/build-example-mods.sh | 22 +++++++++++++++++++ scripts/build.mjs | 21 +++++++++++++----- scripts/test.sh | 11 ---------- 4 files changed, 72 insertions(+), 23 deletions(-) create mode 100755 scripts/build-example-mods.sh diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 731a93da..f863d5cf 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -1,4 +1,4 @@ -name: 'Build' +name: 'CI' on: push: @@ -38,8 +38,9 @@ jobs: - name: Upload Artifacts uses: actions/upload-artifact@v3 with: - name: ${{ matrix.mode }}-${{ matrix.arch }} - path: ./out/**/*.AppImage* + name: ${{ matrix.mode }} (${{ matrix.arch }}) + path: ./out/*.AppImage* + if-no-files-found: error # Test Project test: strategy: @@ -59,12 +60,38 @@ jobs: # Dependencies - name: Install Dependencies run: ./scripts/install-dependencies.sh - - name: Install ARM Toolchain - if: ${{ matrix.mode == 'Client' }} - run: apt-get install --no-install-recommends -y g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf # Test - name: Test run: ./scripts/test.sh ${{ matrix.mode }} + # Example Mods + example-mods: + name: Build Example Mods + runs-on: ubuntu-latest + container: node:lts-bullseye + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + submodules: true + # Dependencies + - name: Install Dependencies + run: ./scripts/install-dependencies.sh + - name: Install ARM Toolchain + run: apt-get install --no-install-recommends -y g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf + # Build SDK + - name: Build SDK + run: | + ./scripts/build.mjs none client host + ./out/client/host/usr/bin/minecraft-pi-reborn-client --copy-sdk + # Build Example Mods + - name: Build Example Mods + run: ./scripts/build-example-mods.sh + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: Example Mods + path: ./out/example-mods/* + if-no-files-found: error # Create Release release: if: startsWith(github.ref, 'refs/tags/') @@ -87,7 +114,7 @@ jobs: - name: Create Release uses: https://gitea.com/actions/release-action@main with: - files: ./out + files: ./out/*/*.AppImage* api_key: ${{ secrets.RELEASE_TOKEN }} title: v${{ github.ref_name }} body: "[View Changelog](https://gitea.thebrokenrail.com/minecraft-pi-reborn/minecraft-pi-reborn/src/branch/master/docs/CHANGELOG.md)" diff --git a/scripts/build-example-mods.sh b/scripts/build-example-mods.sh new file mode 100755 index 00000000..8bd6e96d --- /dev/null +++ b/scripts/build-example-mods.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +set -e + +# Create Output Directory +ROOT="$(pwd)" +OUT="${ROOT}/out/example-mods" +rm -rf "${OUT}" +mkdir -p "${OUT}" + +# Build +for MOD in example-mods/*/; do + cd "${ROOT}/${MOD}" + # Build + rm -rf build + mkdir build + cd build + cmake -GNinja .. + cmake --build . + # Copy Result + cp lib*.so "${OUT}" +done diff --git a/scripts/build.mjs b/scripts/build.mjs index d1bc92c6..17f19ba1 100755 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -136,7 +136,11 @@ function updateDir(dir) { return path.join(dir, variant.name, architecture.name); } build = updateDir(build); -out = updateDir(out); +let cleanOut = false; +if (packageType === PackageTypes.None) { + cleanOut = true; + out = updateDir(out); +} // Configure Build Options function toCmakeBool(val) { @@ -150,9 +154,6 @@ if (architecture !== Architectures.Host) { } else { delete options['CMAKE_TOOLCHAIN_FILE']; } -if (packageType === PackageTypes.AppImage) { - options['CPACK_PACKAGE_DIRECTORY'] = out; -} // Make Build Directory function createDir(dir, clean) { @@ -163,7 +164,7 @@ function createDir(dir, clean) { } createDir(build, clean); if (!install) { - createDir(out, true); + createDir(out, cleanOut); } // Run CMake @@ -193,4 +194,14 @@ if (packageType !== PackageTypes.AppImage) { run(['cmake', '--install', '.']); } else { run(['cmake', '--build', '.', '--target', 'package']); + // Copy Generated Files + const files = fs.readdirSync(build); + for (const file of files) { + if (file.includes('.AppImage')) { + info('Copying: ' + file); + const src = path.join(build, file); + const dst = path.join(out, file); + fs.copyFileSync(src, dst); + } + } } diff --git a/scripts/test.sh b/scripts/test.sh index fc113843..bb01250c 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -27,15 +27,4 @@ else export _MCPI_SKIP_ROOT_CHECK=1 export HOME="$(pwd)/build/test" minecraft-pi-reborn-client --default --no-cache --benchmark - - # Build Example Mods - for project in example-mods/*/; do - cd "${project}" - rm -rf build - mkdir build - cd build - cmake -GNinja .. - cmake --build . - cd ../../../ - done fi