From d5e52d4f06f5d75f188fd1b239c28cf0098b2e4a Mon Sep 17 00:00:00 2001 From: Patrik Korytar Date: Thu, 14 May 2026 11:19:52 +0200 Subject: [PATCH] NCL-9648 Implement gradle CI and snapshot workflows --- .github/workflows/gradle-ci.yml | 108 ++++++++++++++++++++++++++ .github/workflows/gradle-snapshot.yml | 64 +++++++++++++++ README.md | 12 +++ 3 files changed, 184 insertions(+) create mode 100644 .github/workflows/gradle-ci.yml create mode 100644 .github/workflows/gradle-snapshot.yml diff --git a/.github/workflows/gradle-ci.yml b/.github/workflows/gradle-ci.yml new file mode 100644 index 0000000..d21718b --- /dev/null +++ b/.github/workflows/gradle-ci.yml @@ -0,0 +1,108 @@ +name: Java CI with Gradle + +on: + workflow_call: + inputs: + java_version: + description: "The Java version to use to compile. Default: 17" + required: false + type: string + default: "17" + gradle_version: + description: "The Gradle version to use, or 'wrapper'. Default: wrapper" + required: false + type: string + default: "wrapper" + build_args: + description: "Args for gradle build" + required: true + type: string + fetch_all_commits: + description: "Whether to fetch all commits. Default: false" + required: false + type: boolean + default: false + pre_build_script: + description: "Optional script to run after checkout, before the build." + required: false + type: string + default: "" + upload_coverage: + description: "Whether to upload coverage to Codecov. Default: false" + required: false + type: boolean + default: false + coverage_files: + description: "Coverage report files to upload when 'upload_coverage' is true." + required: false + type: string + default: "" + upload_artifacts: + description: "Whether to upload artifacts and their metadata. Default: false" + required: false + type: boolean + default: false + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.java_version }}-${{ inputs.gradle_version }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + fetch-depth: ${{ inputs.fetch_all_commits == true && '0' || '1' }} + persist-credentials: false + + - name: Run pre-build script + if: inputs.pre_build_script != '' + shell: bash + env: + PRE_BUILD_SCRIPT: ${{ inputs.pre_build_script }} + run: bash -c "${PRE_BUILD_SCRIPT}" + + - uses: project-ncl/shared-github-actions/.github/actions/gradle-build@8508c5b6bbd47f9528410b0f7de23231b09e86e1 # main + with: + java_version: ${{ inputs.java_version }} + gradle_version: ${{ inputs.gradle_version }} + build_args: ${{ inputs.build_args }} + + - name: Codecov + if: inputs.upload_coverage + uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0 + with: + files: ${{ inputs.coverage_files }} + verbose: true + + - name: Save PR metadata + if: inputs.upload_artifacts + env: + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_SHA: ${{ github.event.pull_request.head.sha }} + run: | + mkdir -p pr-metadata + echo "$PR_NUMBER" > pr-metadata/pr-number + echo "$PR_SHA" > pr-metadata/pr-sha + + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + if: inputs.upload_artifacts + with: + name: pr-build + path: | + . + !.git + !pr-metadata + retention-days: 1 + + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + if: inputs.upload_artifacts + with: + name: pr-metadata + path: pr-metadata + retention-days: 1 diff --git a/.github/workflows/gradle-snapshot.yml b/.github/workflows/gradle-snapshot.yml new file mode 100644 index 0000000..3d1e1e7 --- /dev/null +++ b/.github/workflows/gradle-snapshot.yml @@ -0,0 +1,64 @@ +name: Build snapshot version and upload to Gradle Central + +on: + workflow_call: + inputs: + project_name: + # format: / + description: "The project name to run the job. Prevent forks to run snapshot job" + required: true + type: string + java_version: + description: "The Java version to use to compile. Default: 17" + required: false + type: string + default: "17" + fetch_all_commits: + description: "Whether to fetch all commits. Default: false" + required: false + type: boolean + default: false + + secrets: + SONATYPE_USERNAME: + required: true + SONATYPE_PASSWORD: + required: true + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + snapshot: + if: github.repository == inputs.project_name + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + fetch-depth: ${{ inputs.fetch_all_commits == true && '0' || '1' }} + persist-credentials: false + + - name: Set up JDK '${{ inputs.java_version }}' + uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0 + with: + java-version: "${{ inputs.java_version }}" + distribution: "temurin" + cache: gradle + server-id: central-publisher # we use this in our pom.xml + server-username: MAVEN_USERNAME # env var name for username + server-password: MAVEN_PASSWORD # env var name for password + + - name: Extract Project version + id: project-version + run: echo "version=$(awk -F "=" 'BEGIN{ORS=""} /version/{print $NF}' gradle.properties)" >> "$GITHUB_OUTPUT" + + - uses: project-ncl/shared-github-actions/.github/actions/gradle-build@8508c5b6bbd47f9528410b0f7de23231b09e86e1 # main + if: ${{ endsWith(steps.project-version.outputs.version, '-SNAPSHOT') }} + with: + java_version: ${{ inputs.java_version }} + build_args: "build publishToCentral -x test -x funcTest" + env: + MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} diff --git a/README.md b/README.md index 3978966..b54dca3 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,11 @@ the Java version etc. It is possible to use this within a matrix job. ``` +## Gradle CI (`gradle-ci.yml`) +Standard CI workflow for Gradle projects. + +- **Tasks**: Checkout code, set up Java, set up Maven, run build command, optionally run coverage tests, and optionally push build artifact (which is used by Mend workflow). Can also run optional pre-build script. + ## NPM CI (`npm-ci.yml`) Standard CI workflow for NPM projects. @@ -188,6 +193,9 @@ Workflow for deploying snapshot versions to Maven Central. * quarkus_jib_image ( default: `false`) * jboss_parent_override: This is used to override variables from the jboss-parent (default `-Dcentral.serverId=central-publisher -Dcentral.sonatype.url=https://central.sonatype.com/repository/maven-snapshots -Pcentral-release -Dgpg.skip`) +## Gradle Snapshot (`gradle-snapshot.yml`) + +Workflow for deploying snapshot versions to Gradle Central, similar to its Maven counterpart. ## Maven Set Version (`maven-set-version.yml`) Workflow to update the version in a Maven `pom.xml`. This can be manually run by going to the GitHub Actions tab and selecting the workflow. @@ -252,6 +260,10 @@ A GitHub repository example using those workflows can be found Sets up Java, sets up Maven, and runs build command. +## Gradle Build (`gradle-build/action.yml`) + +Sets up Java, sets up Gradle, and runs build command. + ## NPM Build (`npm-build/action.yml`) Sets up Node.js, sets up NPM, and runs build command.