Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions .github/workflows/gradle-ci.yml
Original file line number Diff line number Diff line change
@@ -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
64 changes: 64 additions & 0 deletions .github/workflows/gradle-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build snapshot version and upload to Gradle Central

on:
workflow_call:
inputs:
project_name:
# format: <organisation>/<project_name>
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing matching configuration from the maven-snapshot i.e. configuring server-id, server-username etc. I am wondering if that is why I needed that workaround or deleting the settings file and generating a new one below below

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think after some experimentation its due to the fact that the settings.xml always ends up being generated and the settings loader plugin I was using attempts to decrypt it annoyingly. I'm seeing if I can remove that plugin and use a custom implementation which would simplify the work here (See project-ncl/gradle-manipulator#538 )

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 }}
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ the Java version etc. It is possible to use this within a matrix job.
```
</details>

## 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.

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down