From d5aca769f53e9e179238612c0e52215834533df6 Mon Sep 17 00:00:00 2001 From: Tristan Date: Sat, 11 Jan 2025 15:24:21 +0000 Subject: [PATCH] Use a single workflow with a reusable maven build action --- .github/actions/maven-build.yml | 36 ++++++++++++++++++++ .github/workflows/ci.yml | 59 ++++++++++++++++++++++----------- .github/workflows/graal.yml | 41 ----------------------- .github/workflows/hotspot.yml | 44 ------------------------ Dockerfile | 14 ++++---- 5 files changed, 82 insertions(+), 112 deletions(-) create mode 100644 .github/actions/maven-build.yml delete mode 100644 .github/workflows/graal.yml delete mode 100644 .github/workflows/hotspot.yml diff --git a/.github/actions/maven-build.yml b/.github/actions/maven-build.yml new file mode 100644 index 0000000..e4bc03a --- /dev/null +++ b/.github/actions/maven-build.yml @@ -0,0 +1,36 @@ +name: "HotSpot Build" + +inputs: + BUILD_REVISION: + description: "Canonical build revision for this execution" + required: true + MAVEN_JOB_ARGS: + description: "Maven arguments to add" + required: true + +runs: + using: composite + steps: + - name: "Checkout repository" + uses: "actions/checkout@v4" + - name: "Cache local Maven repository" + uses: "actions/cache@v4" + with: + path: "~/.m2/repository" + key: "${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pom.xml') }}" + restore-keys: | + ${{ runner.os }}-${{ runner.arch }}- + - name: "Build and test" + shell: "/bin/bash" + run: | + set -euo pipefail + + mvn -B -e -fae --show-version \ + -Dmaven.repo.local="$HOME/.m2/repository" \ + -DsurefireTmpDir="$(pwd)/.github/tmpdir" \ + -Drevision="${{ inputs.BUILD_REVISION }}" \ + ${{ inputs.MAVEN_JOB_ARGS }} + + if [ -f "target/jacoco/jacoco.csv" ]; then + awk -F"," '{ instructions += $4 + $5; covered += $5 } END { print covered, "/", instructions, " instructions covered"; print 100*covered/instructions, "% covered" }' target/site/jacoco/jacoco.csv + fi diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 390101b..bbbffcf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,8 +5,11 @@ on: paths-ignore: [ "README.md" ] workflow_dispatch: { } +env: + JAVA_VERSION: "23" + jobs: - build_variables: + set_variables: name: "Set build variables" runs-on: "ubuntu-latest" outputs: @@ -21,22 +24,40 @@ jobs: echo "build_image=$BUILD_IMAGE" | tee -a "$GITHUB_OUTPUT" echo "build_version=$BUILD_VERSION" | tee -a "$GITHUB_OUTPUT" - hotspot: - name: "HotSpot JIT" - needs: "build_variables" - uses: "./.github/workflows/hotspot.yml" - secrets: "inherit" - with: - JDK_VERSION: "23" - BUILD_IMAGE: "${{ needs.build_variables.outputs.build_image }}" - BUILD_REVISION: "${{ needs.build_variables.outputs.build_version }}" + build_hotspot: + name: "HotSpot" + runs-on: "ubuntu-latest" + needs: [ "set_variables" ] + container: + image: "ghcr.io/mangadex-pub/jdk-maven:${{ env.JAVA_VERSION }}-corretto" + options: "--user root" # this is sad, but Github CI is (once again) very silly + steps: + - name: "Maven Build (JIT)" + uses: "./.github/actions/maven-build.yml" + with: + BUILD_REVISION: "${{ needs.build_variables.outputs.build_version }}" + MAVEN_JOB_ARGS: "verify package" + - name: "Archive jarfile" + uses: "actions/upload-artifact@v4" + with: + name: "mcw.jar" + path: "target/mcw.jar" - graal: - name: "GraalVM AOT" - needs: [ "build_variables", "hotspot" ] - uses: "./.github/workflows/graal.yml" - secrets: "inherit" - with: - JDK_VERSION: "23" - BUILD_IMAGE: "${{ needs.build_variables.outputs.build_image }}" - BUILD_REVISION: "${{ needs.build_variables.outputs.build_version }}" + build_graal: + name: "GraalVM" + runs-on: "ubuntu-latest" + needs: [ "set_variables", "build_hotspot" ] + container: + image: "ghcr.io/mangadex-pub/jdk-maven:${{ env.JAVA_VERSION }}-graal" + options: "--user root" # this is sad, but Github CI is (once again) very silly + steps: + - name: "Maven Build (AOT)" + uses: "./.github/actions/maven-build.yml" + with: + BUILD_REVISION: "${{ needs.build_variables.outputs.build_version }}" + MAVEN_JOB_ARGS: "package -Pnative -DskipTests" + - name: "Archive binary" + uses: "actions/upload-artifact@v4" + with: + name: "mcw-${{ runner.os }}-${{ runner.arch }}" + path: "target/mcw" diff --git a/.github/workflows/graal.yml b/.github/workflows/graal.yml deleted file mode 100644 index dd9926a..0000000 --- a/.github/workflows/graal.yml +++ /dev/null @@ -1,41 +0,0 @@ -on: - workflow_call: - inputs: - JDK_VERSION: - type: string - description: "JDK version to use for build" - required: true - BUILD_IMAGE: - type: string - description: "Build image" - required: true - BUILD_REVISION: - type: string - description: "Build revision" - required: true - -jobs: - build: - runs-on: "ubuntu-latest" - container: - image: "ghcr.io/mangadex-pub/jdk-maven:${{ inputs.JDK_VERSION }}-graal" - options: "--user root" # this is sad, but Github CI is (once again) very silly - steps: - - name: "Checkout repository" - uses: "actions/checkout@v4" - - name: "Cache local Maven repository" - uses: "actions/cache@v4" - with: - path: "~/.m2/repository" - key: "${{ runner.os }}-graal-${{ inputs.JDK_VERSION }}-${{ hashFiles('pom.xml') }}" - restore-keys: | - ${{ runner.os }}-graal-${{ inputs.JDK_VERSION }}- - - name: "Build and test" - run: | - set -euo pipefail - mvn -Pnative -B -Dmaven.repo.local="$HOME/.m2/repository" -e -fae --show-version -Drevision="${{ inputs.BUILD_REVISION }}" -DskipTests package - - name: "Archive executable" - uses: "actions/upload-artifact@v4" - with: - name: "mcw-glibc" - path: "target/mcw" diff --git a/.github/workflows/hotspot.yml b/.github/workflows/hotspot.yml deleted file mode 100644 index 0cee39f..0000000 --- a/.github/workflows/hotspot.yml +++ /dev/null @@ -1,44 +0,0 @@ -on: - workflow_call: - inputs: - JDK_VERSION: - type: string - description: "JDK version to use for build" - required: true - BUILD_IMAGE: - type: string - description: "Build image" - required: true - BUILD_REVISION: - type: string - description: "Build revision" - required: true - -jobs: - build: - runs-on: "ubuntu-latest" - steps: - - name: "Checkout repository" - uses: "actions/checkout@v4" - - name: "Set up JDK" - uses: "actions/setup-java@v4" - with: - distribution: "corretto" - java-version: "${{ inputs.JDK_VERSION }}" - - name: "Cache local Maven repository" - uses: "actions/cache@v4" - with: - path: "~/.m2/repository" - key: "${{ runner.os }}-hotspot-${{ inputs.JDK_VERSION }}-${{ hashFiles('pom.xml') }}" - restore-keys: | - ${{ runner.os }}-hotspot-${{ inputs.JDK_VERSION }}- - - name: "Build and test" - run: | - set -euo pipefail - mvn -B -e -fae --show-version -Drevision="${{ inputs.BUILD_REVISION }}" -DsurefireTmpDir="$(pwd)/.github/tmpdir" verify package - awk -F"," '{ instructions += $4 + $5; covered += $5 } END { print covered, "/", instructions, " instructions covered"; print 100*covered/instructions, "% covered" }' target/site/jacoco/jacoco.csv - - name: "Archive jarfile" - uses: "actions/upload-artifact@v4" - with: - name: "mcw.jar" - path: "target/mcw.jar" diff --git a/Dockerfile b/Dockerfile index 5066be7..79b80f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,15 @@ -FROM ghcr.io/mangadex-pub/jdk-maven:23-corretto AS hotspot-corretto +FROM amazoncorretto:23-headless AS hotspot USER root -RUN mkdir -pv /opt/mcw -COPY target/mcw.jar /opt/mcw/mcw.jar +RUN mkdir -pv /opt/mcw/bin +COPY target/mcw.jar /opt/mcw/bin/mcw.jar -USER mangadex -RUN java -jar /opt/mcw/mcw.jar --version +RUN java -jar /opt/mcw/bin/mcw.jar --version -FROM ghcr.io/mangadex-pub/containers-base/rockylinux:9 AS aot-glibc +FROM ghcr.io/mangadex-pub/containers-base/rockylinux:9 AS graal USER root -RUN mkdir -pv /opt/mcw +RUN mkdir -pv /opt/mcw/bin COPY target/mcw /opt/mcw/mcw -USER mangadex RUN /opt/mcw/mcw --version