From 1de4a11d1ad29be2d64e94cdd3dd147f7ad74951 Mon Sep 17 00:00:00 2001 From: Ted Senft Date: Sun, 17 Nov 2024 18:40:52 -0500 Subject: [PATCH] Add build scripts and versioning --- .github/workflows/_build.yml | 46 ++++++++++++++++++++ .github/workflows/_publish.yml | 48 +++++++++++++++++++++ .github/workflows/_run-gametests.yml | 64 ++++++++++++++++++++++++++++ .github/workflows/nightly-builds.yml | 57 +++++++++++++++++++++++++ spatial/build.gradle.kts | 24 +++++++++++ 5 files changed, 239 insertions(+) create mode 100644 .github/workflows/_build.yml create mode 100644 .github/workflows/_publish.yml create mode 100644 .github/workflows/_run-gametests.yml create mode 100644 .github/workflows/nightly-builds.yml diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml new file mode 100644 index 0000000..55bcf07 --- /dev/null +++ b/.github/workflows/_build.yml @@ -0,0 +1,46 @@ +name: Data Generation + +on: + workflow_call: + inputs: + version: + required: true + type: string + +jobs: + datagen: + name: Build + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build + run: ./gradlew :spatial-neoforge:build + env: + VERSION: ${{ inputs.version }} + GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Store Compiled + if: success() + uses: actions/upload-artifact@v4 + with: + name: build + path: spatial/build + + - name: Store Compiled + if: success() + uses: actions/upload-artifact@v4 + with: + name: build-neo + path: spatial-neoforge/build \ No newline at end of file diff --git a/.github/workflows/_publish.yml b/.github/workflows/_publish.yml new file mode 100644 index 0000000..efe9b4d --- /dev/null +++ b/.github/workflows/_publish.yml @@ -0,0 +1,48 @@ +# REQUIRES DATAGEN TO BE CALLED IN A JOB BEFORE THIS!! + +name: Publish + +on: + workflow_call: + inputs: + version: + required: true + type: string + +jobs: + publish: + name: Publish Code as Github Package - ${{ inputs.version }} + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: true + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Pull Compilation Data + uses: actions/download-artifact@v4 + with: + name: build + path: spatial/build + + - name: Pull Compilation Data (Main) + uses: actions/download-artifact@v4 + with: + name: build-neo + path: spatial-neoforge/build + + - name: Publish + run: ./gradlew :spatial:publish + env: + VERSION: ${{ inputs.version }} + GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/_run-gametests.yml b/.github/workflows/_run-gametests.yml new file mode 100644 index 0000000..fd9f229 --- /dev/null +++ b/.github/workflows/_run-gametests.yml @@ -0,0 +1,64 @@ +name: Run Game Tests + +on: + workflow_call: + inputs: + version: + required: true + type: string + +env: + VERSION: ${{ inputs.version }} + GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + run-tests: + name: Run Game Tests + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: true + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Pull Compilation Data + uses: actions/download-artifact@v4 + with: + name: build + path: spatial/build + + - name: Pull Compilation Data (Main) + uses: actions/download-artifact@v4 + with: + name: build-neo + path: spatial-neoforge/build + + - name: Run Game Tests + run: ./gradlew :spatial-neoforge:runGameTestServer + + - name: Upload test failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: test-data + path: run/gametest + + - name: Run JUnit Tests + run: ./gradlew :spatial-neoforge:test + + - name: Upload test reports on failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: test-reports + path: spatial-neoforge/build/reports \ No newline at end of file diff --git a/.github/workflows/nightly-builds.yml b/.github/workflows/nightly-builds.yml new file mode 100644 index 0000000..2aa2926 --- /dev/null +++ b/.github/workflows/nightly-builds.yml @@ -0,0 +1,57 @@ +name: Publish and Announce Nightly Build + +env: + GH_PKG_URL: "https://maven.pkg.github.com/${{ github.repository }}" + +on: + workflow_dispatch: + push: + paths-ignore: + - "README.md" + - "LICENSE" + - ".github/**/*" + - "**/*.gradle.kts" + - "**/gradle.properties" + +jobs: + vars: + name: Get Variables + runs-on: ubuntu-22.04 + outputs: + version: ${{steps.version.outputs.version}} + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 150 + fetch-tags: true + + - name: Version + id: version + uses: paulhatch/semantic-version@v5.4.0 + with: + change_path: "spatial" + version_format: "${major}.${minor}.${patch}" + search_commit_body: true + + build: + needs: [ vars ] + uses: ./.github/workflows/_build.yml + secrets: inherit + with: + version: ${{ needs.vars.outputs.version }} + + tests: + needs: [ build, vars ] + uses: ./.github/workflows/_run-gametests.yml + secrets: inherit + with: + version: ${{ needs.vars.outputs.version }} + + publish: + needs: [ vars, tests ] + uses: ./.github/workflows/_publish.yml + secrets: inherit + with: + version: ${{ needs.vars.outputs.version }} \ No newline at end of file diff --git a/spatial/build.gradle.kts b/spatial/build.gradle.kts index 87ac534..c8decf6 100644 --- a/spatial/build.gradle.kts +++ b/spatial/build.gradle.kts @@ -1,6 +1,11 @@ +var envVersion: String = System.getenv("VERSION") ?: "0.0.1" +if (envVersion.startsWith("v")) + envVersion = envVersion.trimStart('v') + plugins { id("idea") id("java") + id("maven-publish") alias(neoforged.plugins.moddev) } @@ -17,4 +22,23 @@ java { neoForge { neoFormVersion = neoforged.versions.neoform +} + + +val PACKAGES_URL = System.getenv("GH_PKG_URL") ?: "https://maven.pkg.github.com/compactmods/spatial" +publishing { + publications.register("spatial") { + from(components.getByName("java")) + } + + repositories { + // GitHub Packages + maven(PACKAGES_URL) { + name = "GitHubPackages" + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") + } + } + } } \ No newline at end of file