Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gradle builds #3250

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions actions/gradle/publish/README.md
Expand Up @@ -280,3 +280,7 @@ Closing the staging repository:
Releasing:

![releasing the Gradle artefacts](/actions/gradle/publish/images/gradle-publisher-release-closed-repository.png)

### Multi-Project Builds

See the same guidance in the [build docs](../../../internal/builders/gradle/README.md#multi-project-builds) for consolidating files from multi-project builds.
33 changes: 32 additions & 1 deletion internal/builders/gradle/README.md
Expand Up @@ -19,6 +19,7 @@ workflow the "Gradle builder" from now on.
- [Limitations](#limitations)
- [Generating Provenance](#generating-provenance)
- [Getting Started](#getting-started)
- [Multi-Project Builds](#multi-project-builds)
- [Private Repositories](#private-repositories)
- [Verification](#verification)

Expand Down Expand Up @@ -53,6 +54,7 @@ The Gradle builder currently has the following limitations:

1. The project must be buildable by way of `./gradlew build`. If you need the option for flags, profiles or something else to define more granular builds, please open an issue.
2. The project must include a gradle wrapper (`gradlew`). The Gradle builder does not include an installation of gradle.
3. The project's build scripts must place the artifacts into `./build`, relative to the `directory` workflow input. If you are doing [multi-project builds](https://docs.gradle.org/current/userguide/intro_multi_project_builds.html), you may need to follow the [example below](#multi-project-builds)

## Generating Provenance

Expand Down Expand Up @@ -83,13 +85,42 @@ jobs:
actions: read
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_gradle_slsa3.yml@v1.9.0
with:
artifact-list: ./artifact1.jar,./artifact2.jar
artifact-list: >-
./build/artifact1.jar,
./build/artifact2.jar
```

Now, when you invoke this workflow, the Gradle builder will build both your artifacts and the provenance files for them.

The Gradle builder requires you to specify the artifacts that you wish to attest to. To do so, you add a comma-separated list of paths to the artifacts as shown in the example. The paths are relative from the root of your project directory.

#### Multi-Project Builds

If you are using [multi-project builds](https://docs.gradle.org/current/userguide/intro_multi_project_builds.html), where each of your sub-projects' `src` are in separate subfolders, then you will need to add a task to copy over the artifact files to the root `./build` folder.

See this example to add to your sub-projects' `build.gradle.kts` file.

```kotlin
tasks.register<Copy>("copySubProjectBuild") {
from(layout.buildDirectory)
into("${rootProject.projectDir}/build/${project.name}")
}

tasks.named("build") {
finalizedBy("copySubProjectBuild")
}
```

This, for example, It will move `./app1/build/` and `./app2/build/` to `./build/app1/` and `./build/app2/`. You must then alter your input to `artifact-list`.
ramonpetgrave64 marked this conversation as resolved.
Show resolved Hide resolved

```yaml
...
artifact-list: >-
./build/app1/libs/app.jar,
./build/app2/libs/app.jar,
...
```

### Private Repositories

The builder records all provenance signatures in the [Rekor](https://github.com/sigstore/rekor) public transparency log. This record includes the repository name. To acknowledge you're aware that your repository name will be public, set the flag `rekor-log-public: true` when calling the builder:
Expand Down
3 changes: 2 additions & 1 deletion internal/builders/gradle/action.yml
Expand Up @@ -124,7 +124,8 @@ runs:
env:
PROJECT_ROOT: ${{ steps.run_gradle_builder.outputs.validated_project_root }}
run: |
mv "${PROJECT_ROOT}"/build "${GITHUB_WORKSPACE}"/
# ensure that directories are not the same before moving them, preventing an error when running action from the root of the repository
ramonpetgrave64 marked this conversation as resolved.
Show resolved Hide resolved
[[ "${PROJECT_ROOT}" -ef "${GITHUB_WORKSPACE}" ]] || mv "${PROJECT_ROOT}"/build "${GITHUB_WORKSPACE}"/
- name: Upload build dir
id: upload-build-dir
uses: slsa-framework/slsa-github-generator/.github/actions/secure-upload-folder@main
Expand Down
3 changes: 2 additions & 1 deletion internal/builders/maven/action.yml
Expand Up @@ -105,7 +105,8 @@ runs:
&& mvn package -Drun.hash.jarfile=true
# NOTE: SLSA_OUTPUTS_ARTIFACTS_FILE is a relative path and the project_root may
# not be in GITHUB_WORKSPACE, so we need to move the file.
mv $(dirname "${SLSA_OUTPUTS_ARTIFACTS_FILE}") "${GITHUB_WORKSPACE}/../"
# the following checks if the directories are different before executing the command, fixing an error when SLSA is generated from the root of a repository
[[ $(dirname "${SLSA_OUTPUTS_ARTIFACTS_FILE}") -ef "${GITHUB_WORKSPACE}/../" ]] || mv $(dirname "${SLSA_OUTPUTS_ARTIFACTS_FILE}") "${GITHUB_WORKSPACE}/../"
mv target "${GITHUB_WORKSPACE}/"

# rng generates a random number to avoid name collision in artifacts
Expand Down