From 1860bd42c015124d7e01e1d3473ba4595e257db9 Mon Sep 17 00:00:00 2001 From: Yurihaia <17830663+Yurihaia@users.noreply.github.com> Date: Sun, 14 Apr 2024 12:16:29 -0400 Subject: [PATCH] Add updated build script --- .editorconfig | 5 + .github/workflows/build.yaml | 194 +++++++++++++-------------- .github/workflows/create_relnotes.js | 36 +++++ .github/workflows/docs.yaml | 24 ++-- .github/workflows/release_notes.md | 10 ++ Assembly-CSharp/ModHooks.cs | 1 + hollowknight.version | 1 + moddingapi.version | 1 + 8 files changed, 158 insertions(+), 114 deletions(-) create mode 100644 .github/workflows/create_relnotes.js create mode 100644 .github/workflows/release_notes.md create mode 100644 hollowknight.version create mode 100644 moddingapi.version diff --git a/.editorconfig b/.editorconfig index d8bdee65..84ec7ded 100644 --- a/.editorconfig +++ b/.editorconfig @@ -179,3 +179,8 @@ resharper_web_config_wrong_module_highlighting = warning indent_style = space indent_size = 4 tab_width = 4 + +[*.{yaml,yml}] +indent_size = 2 +tab_width = 2 +indent_style = space \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index e1cfd102..0c4db4d2 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,119 +1,107 @@ name: build -on: [push, pull_request] +on: + push: + pull_request: jobs: - build-win: + build: runs-on: ubuntu-latest + strategy: + matrix: + platform: [windows, macos, linux] + archive-ref: [main] steps: - - uses: actions/checkout@v3 - - name: Setup Vanilla - run: | - wget https://files.catbox.moe/i4sdl6.zip -O Vanilla.zip - unzip Vanilla.zip -d Vanilla - - name: Setup .NET - uses: actions/setup-dotnet@v3 - - name: Setup ms-build - run: sudo apt-get install -y nuget mono-devel mono-xbuild - - name: Restore dependencies - run: dotnet restore - - name: Build PrePatcher - run: | - dotnet build PrePatcher -o PrePatcher/Output -p:Configuration=Release - - name: Build Assembly-CSharp (Windows) - run: | - dotnet build Assembly-CSharp -p:SolutionDir=$PWD -p:Configuration=Release - - name: Upload Windows Binary - uses: actions/upload-artifact@v3 - with: - name: ModdingApiWin - path: ./OutputFinal/ - - build-linux: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup Vanilla - run: | - wget https://files.catbox.moe/j85bvb.zip -O Vanilla.zip - unzip Vanilla.zip -d Vanilla - - name: Setup .NET - uses: actions/setup-dotnet@v3 - - name: Setup ms-build - run: sudo apt-get install -y nuget mono-devel mono-xbuild - - name: Restore dependencies - run: dotnet restore - - name: Build PrePatcher - run: | - dotnet build PrePatcher -o PrePatcher/Output -p:Configuration=Release - - name: Build Assembly-CSharp - run: | - dotnet build Assembly-CSharp -p:SolutionDir=$PWD -p:Configuration=Release - - name: Upload Linux Binary - uses: actions/upload-artifact@v3 - with: - name: ModdingApiLinux - path: ./OutputFinal/ - - build-mac: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup Vanilla - run: | - wget https://files.catbox.moe/j8fyro.zip -O Vanilla.zip - unzip Vanilla.zip -d Vanilla - - name: Setup .NET - uses: actions/setup-dotnet@v3 - - name: Setup ms-build - run: sudo apt-get install -y nuget mono-devel mono-xbuild - - name: Restore dependencies - run: dotnet restore - - name: Build PrePatcher - run: | - dotnet build PrePatcher -o PrePatcher/Output -p:Configuration=Release - - name: Build Assembly-CSharp - run: | - dotnet build Assembly-CSharp -p:SolutionDir=$PWD -p:Configuration=Release - - name: Upload Mac Binary - uses: actions/upload-artifact@v3 - with: - name: ModdingApiMac - path: ./OutputFinal/ - + - uses: actions/checkout@v4 + + - name: Read Versions + run: | + HKV=$(cat ./hollowknight.version) + echo "HK_VERSION=$HKV" >> $GITHUB_ENV + + - name: Checkout Binaries + uses: actions/checkout@v4 + with: + repository: hk-modding/hk-binary-archives + ref: ${{ matrix.archive-ref }} + ssh-key: ${{ secrets.BINARY_ARCHIVE_DEPLOY_KEY }} + sparse-checkout: | + ${{ env.HK_VERSION }}/managed.${{ matrix.platform }}.tar.gz + sparse-checkout-cone-mode: false + path: ./hk-binary-archives + + - name: Unpack Archive + run: | + mkdir Vanilla + cd ./Vanilla + tar -xzf ../hk-binary-archives/${{ env.HK_VERSION }}/managed.${{ matrix.platform }}.tar.gz + + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: 6.0.x + - name: Setup MSBuild + run: | + sudo apt-get update -y + sudo apt-get install -y nuget mono-devel mono-xbuild + - name: Restore Dependencies + run: | + dotnet restore + - name: Build PrePatcher + run: | + dotnet build PrePatcher -o PrePatcher/Output -p:Configuration=Release + - name: Build Assembly-CSharp + run: | + dotnet build Assembly-CSharp -p:SolutionDir=$PWD -p:Configuration=Release + - name: Upload Binary + uses: actions/upload-artifact@v4 + with: + name: build.${{ matrix.platform }} + path: ./OutputFinal/ + release: - needs: [build-win, build-linux, build-mac] + needs: [build] runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags') steps: - - name: Download artifacts - uses: actions/download-artifact@v3 + - name: Read Versions + run: | + HKV=$(cat ./hollowknight.version) + echo "HK_VERSION=$HKV" >> $GITHUB_ENV + + APIV=$(cat ./moddingapi.version) + echo "API_VERSION=$APIV" >> $GITHUB_ENV + + - uses: actions/download-artifact@v4 with: path: ./artifacts - - name: Zip + - name: Zip Artifacts run: | - zip -jr ModdingApiWin.zip ./artifacts/ModdingApiWin/* - zip -jr ModdingApiLinux.zip ./artifacts/ModdingApiLinux/* - zip -jr ModdingApiMac.zip ./artifacts/ModdingApiMac/* - - name: Generate release info + zip -jr moddingapi.${{ env.API_VERSION }}.windows.zip ./artifacts/build.windows/* + zip -jr moddingapi.${{ env.API_VERSION }}.macos.zip ./artifacts/build.macos/* + zip -jr moddingapi.${{ env.API_VERSION }}.linux.zip ./artifacts/build.linux/* + + - uses: actions/setup-node@v4 + with: + node-version: '20.x' + - name: Install Node Dependencies run: | - echo "# Checksums" > ChangeLog.txt ; - echo "* Linux:" >> ChangeLog.txt ; - echo -n " * " >> ChangeLog.txt ; - sha256sum -b ModdingApiLinux.zip | cut -d " " -f 1 >> ChangeLog.txt ; - echo "* Mac:" >> ChangeLog.txt ; - echo -n " * " >> ChangeLog.txt ; - sha256sum -b ModdingApiMac.zip | cut -d " " -f 1 >> ChangeLog.txt ; - echo "* Windows:" >> ChangeLog.txt ; - echo -n " * " >> ChangeLog.txt ; - sha256sum -b ModdingApiWin.zip | cut -d " " -f 1 >> ChangeLog.txt ; - echo "# Changelog" >> ChangeLog.txt ; - echo "${{ github.event.head_commit.message }}" >> ChangeLog.txt ; - - name: Create release if a new tag is pushed - uses: softprops/action-gh-release@v1 + npm install handlebars + - name: Create Release Notes + id: create-relnotes + uses: actions/github-script@v7 + env: + CHANGELOG: ${{ github.event.head_commit.message }} + with: + result-encoding: string + script: | + const script = require("./.github/workflows/create_relnotes.js"); + return await script(); + + - name: Create Release + uses: softprops/action-gh-release@v2 with: - body_path: ChangeLog.txt + body: ${{ steps.create-relnotes.outputs.result }} files: | - ./ModdingApiWin.zip - ./ModdingApiLinux.zip - ./ModdingApiMac.zip + ./moddingapi.${{ env.API_VERSION }}.windows.zip + ./moddingapi.${{ env.API_VERSION }}.macos.zip + ./moddingapi.${{ env.API_VERSION }}.linux.zip diff --git a/.github/workflows/create_relnotes.js b/.github/workflows/create_relnotes.js new file mode 100644 index 00000000..e7ab76fd --- /dev/null +++ b/.github/workflows/create_relnotes.js @@ -0,0 +1,36 @@ +// @ts-check +/** @param {import('github-script').AsyncFunctionArguments} args */ +module.exports = async ({ github, core }) => { + const handlebars = require("handlebars"); + const fs = require("node:fs/promises"); + const crypto = require("node:crypto"); + + const { HK_VERSION, API_VERSION, CHANGELOG } = process.env; + + const relnotes = await fs.readFile("./.github/workflows/release_notes.md", { encoding: "utf-8" }); + const template = handlebars.compile(relnotes); + + const artifact_windows = await fs.readFile(`./moddingapi.${API_VERSION}.windows.zip`); + const artifact_macos = await fs.readFile(`./moddingapi.${API_VERSION}.macos.zip`); + const artifact_linux = await fs.readFile(`./moddingapi.${API_VERSION}.linux.zip`); + + const hash_windows = crypto.createHash("sha256"); + hash_windows.update(artifact_windows); + + const hash_macos = crypto.createHash("sha256"); + hash_macos.update(artifact_macos); + + const hash_linux = crypto.createHash("sha256"); + hash_linux.update(artifact_linux); + + const output = template({ + api_version: API_VERSION, + hk_version: HK_VERSION, + changelog: CHANGELOG, + windows_cs: hash_windows.digest("hex"), + macos_cs: hash_macos.digest("hex"), + linux_cs: hash_linux.digest("hex"), + }); + + return output; +}; \ No newline at end of file diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index b7923068..0ab7fc3c 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -6,32 +6,34 @@ on: jobs: docfx: - if: github.event_name == 'push' runs-on: ubuntu-latest - steps: - - name: Checkout repo - uses: actions/checkout@v2 - - name: Checkout docs - uses: actions/checkout@v2 + - name: Checkout Repository + uses: actions/checkout@v4 + - name: Checkout `docs` branch + uses: actions/checkout@v4 with: ref: docs path: docs - name: Setup .NET - uses: actions/setup-dotnet@v1 - - name: Setup ms-build, mono - run: sudo apt-get install -y nuget mono-devel mono-xbuild + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 6.0.x + - name: Setup MSBuild + run: | + sudo apt-get update -y + sudo apt-get install -y nuget mono-devel mono-xbuild - name: Download DocFX working-directory: docs run: | wget https://github.com/dotnet/docfx/releases/download/v2.59.4/docfx.zip -O docfx.zip unzip docfx.zip -d docfx - - name: Build docs + - name: Build Documentation working-directory: docs run: | mono docfx/docfx.exe - name: Publish - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: DocFX diff --git a/.github/workflows/release_notes.md b/.github/workflows/release_notes.md new file mode 100644 index 00000000..edfa03fa --- /dev/null +++ b/.github/workflows/release_notes.md @@ -0,0 +1,10 @@ +# ModdingAPI {{api_version}} for Hollow Knight {{hk_version}} + +### Changelog + +{{changelog}} + +### Checksums +* Windows: `{{windows_cs}}` +* MacOS: `{{macos_cs}}` +* Linux: `{{linux_cs}}` diff --git a/Assembly-CSharp/ModHooks.cs b/Assembly-CSharp/ModHooks.cs index 200a79ea..5d0c8602 100644 --- a/Assembly-CSharp/ModHooks.cs +++ b/Assembly-CSharp/ModHooks.cs @@ -24,6 +24,7 @@ namespace Modding [PublicAPI] public class ModHooks { + // Make sure this is in sync with `/moddingapi.version`. private const int _modVersion = 74; private static readonly string SettingsPath = Path.Combine(Application.persistentDataPath, "ModdingApi.GlobalSettings.json"); diff --git a/hollowknight.version b/hollowknight.version new file mode 100644 index 00000000..8a7a4d76 --- /dev/null +++ b/hollowknight.version @@ -0,0 +1 @@ +1.5.78.11833 \ No newline at end of file diff --git a/moddingapi.version b/moddingapi.version new file mode 100644 index 00000000..4cfcc40e --- /dev/null +++ b/moddingapi.version @@ -0,0 +1 @@ +v74 \ No newline at end of file