Skip to content

Commit 1d5b4be

Browse files
BUILD-9566 Add support for working-directory for gradle
1 parent faa2b0e commit 1d5b4be

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ jobs:
360360
run-shadow-scans: false # Run SonarQube scans on all 3 platforms (next, sqc-eu, sqc-us)
361361
```
362362
363-
## Inputs
363+
### Inputs
364364
365365
| Input | Description | Default |
366366
|-----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
@@ -468,10 +468,28 @@ jobs:
468468
| `repox-url` | URL for Repox | `https://repox.jfrog.io` |
469469
| `repox-artifactory-url` | URL for Repox Artifactory API (overrides repox-url/artifactory if provided) | (optional) |
470470
| `sonar-platform` | SonarQube variant - 'next', 'sqc-eu', 'sqc-us', or 'none'. Use 'none' to skip sonar scans | `next` |
471+
| `working-directory` | Relative path under github.workspace to execute the build in | `.` |
471472
| `run-shadow-scans` | Enable analysis across all 3 SonarQube platforms (unified platform dogfooding) | `false` |
472473
| `cache-paths` | Custom cache paths (multiline). | `~/.gradle/caches`<br>`~/.gradle/wrapper` |
473474
| `disable-caching` | Whether to disable Gradle caching entirely | `false` |
474475

476+
> [!TIP]
477+
> When using `working-directory`, Java must be available at root due to a limitation
478+
> of [setup-gradle](https://github.com/gradle/actions/tree/main/setup-gradle).
479+
> For instance, if the `mise.toml` file is in the working directory, and not at root.
480+
>
481+
> ```yaml
482+
> - name: Workaround for setup-gradle which has no working-directory input
483+
> run: |
484+
> cp <working-directory>/mise.toml mise.toml
485+
> - uses: jdx/mise-action@5ac50f778e26fac95da98d50503682459e86d566 # v3.2.0
486+
> with:
487+
> version: 2025.7.12
488+
> - uses: SonarSource/ci-github-actions/build-gradle@v1
489+
> with:
490+
> working-directory: <working-directory>
491+
> ```
492+
475493
### Outputs
476494

477495
| Output | Description |

build-gradle/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ inputs:
4343
sonar-platform:
4444
description: SonarQube variant (next, sqc-eu, sqc-us, or none). Use 'none' to skip sonar scans.
4545
default: next
46+
working-directory:
47+
description: Relative path under github.workspace to execute the build in
48+
default: .
4649
run-shadow-scans:
4750
description: If true, run sonar scanner on all 3 platforms using the provided URL and token.
4851
If false, run on the platform provided by SONAR_PLATFORM.
@@ -136,6 +139,7 @@ runs:
136139
- name: Generate Gradle Cache Key
137140
if: ${{ inputs.disable-caching != 'true' }}
138141
shell: bash
142+
working-directory: ${{ inputs.working-directory }}
139143
run: |
140144
/usr/bin/find . \( -name '*.gradle' -o -name '*.gradle.kts' \) -type f -exec md5sum {} \; > gradle-md5-sums.txt
141145
md5sum gradle/libs.versions.toml gradle/wrapper/gradle-wrapper.properties 2>/dev/null >> gradle-md5-sums.txt || true
@@ -179,6 +183,7 @@ runs:
179183
- name: Build, analyze and deploy
180184
id: build
181185
shell: bash
186+
working-directory: ${{ inputs.working-directory }}
182187
env:
183188
# GitHub context
184189
PULL_REQUEST: ${{ github.event.pull_request.number || '' }}

0 commit comments

Comments
 (0)