Skip to content

Commit

Permalink
Add JDK 8 compatibility (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
jprinet authored Jul 31, 2024
1 parent b57ee9d commit 1d769fc
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 77 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
with:
node-version: 20
cache: npm
- name: Set up JDK 11
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: 11
java-version: 8
distribution: "temurin"
- name: Install Dependencies
run: npm ci
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
repository: 'gradle/develocity-build-config-samples'
path: 'sample'
ref: 'main'
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ jobs:
- name: Create Release
uses: softprops/action-gh-release@v2
with:
body_path: release/changelog.txt
body_path: release/changelog.md
name: ${{ github.event.inputs.release_version }}
tag_name: v${{ github.event.inputs.release_version }}
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
nodejs 20.14.0
java liberica-11.0.16+8
java liberica-8u362+9
135 changes: 89 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

A collection of composite GitHub Actions related to [Develocity](https://gradle.com/)

## Add a workflow summary to Maven builds
---

### Description
The `maven-setup` action adds a workflow summary for each Maven invocation.
The summary is also added as a pull-request comment in a pull-request context. This can be disabled via [configuration](#summary).
## maven-setup action

### Features

This action can be combined with the `maven-publish-build-scan` action to publish Build Scan® in a fork context. See [the relevant section](#publish-build-scans-for-pull-requests-issued-from-forked-repositories) for details.
The action enables three features:
- [Build Summary](#build-summary): Display a summary of the Maven builds as a GitHub workflow summary or as a pull-request comment
- [Develocity extensions injection](#develocity-extensions-injection): Inject Develocity/CCUD Maven extensions
- [Capture Build Scan® data](#capture-build-scan-data): Capture published Build Scan® links and unpublished Build Scan® data as a workflow artifact per job with prefix `build-scan-data-maven`, which can then be published in a dependent workflow.

> [!NOTE]
> This action can be combined with the `maven-publish-build-scan` action to publish Build Scan® in a fork context. See [the relevant section](#publish-build-scans-for-pull-requests-issued-from-forked-repositories) for details.
### Usage

Expand All @@ -28,47 +34,45 @@ jobs:
> [!NOTE]
> When authenticated access is required to publish a Build Scan®, it is recommended to provide as input `develocity-access-key` to the `maven-setup` step. This triggers a request for a [short-lived access token](https://docs.gradle.com/develocity/api-manual/#short_lived_access_tokens) instead of relying on the `DEVELOCITY_ACCESS_KEY` environment variable.
### Enabling Develocity/CCUD Maven Extension injection
If one wants to inject Develocity Maven Extension (and optionally CCUD Maven Extension), the `develocity-injection-enabled` input should be set to `true`. The `develocity-url`, `develocity-maven-extension-version`, and optionally `develocity-ccud-maven-extension-version` inputs should be set accordingly:
```yaml
name: PR Build
jobs:
build:
- name: Setup Maven
uses: gradle/develocity-actions/maven-setup@v1
with:
develocity-url: 'https://scans.gradle.com'
develocity-injection-enabled: 'true'
develocity-maven-extension-version: '1.21.6'
- name: Build with Maven
run: ./mvnw clean package
[...]
```
---

### Implementation details
#### Build Summary

The action enables three features:
- Display a summary of the Maven builds as a GitHub workflow summary or as a pull-request comment
- Inject Develocity/CCUD Maven extensions
- Capture unpublished Build Scan® data as a workflow artifact per job with prefix `build-scan-data-maven`, which can then be published in a dependent workflow.
###### Requirements
- The Maven project must be compiled with JDK 8 or above
- The Maven project must have the Develocity extension applied (or injected)

#### Workflow Summary
The process is handled by a [Maven extension](https://maven.apache.org/guides/mini/guide-using-extensions.html) `maven-build-scan-capture-extension.jar` which is running during each Maven invocation.
The extension is automatically registered by configuring the environment `MAVEN_OPTS=-Dmaven.ext.classpath=<PATH_TO_EXTENSION>`.

> [!WARNING]
> If `MAVEN_OPTS` environment variable is set in the step invoking the `mvn` command, the extension won't be registered.
Make sure to use `MAVEN_OPTS: ${{ env.MAVEN_OPTS }} <EXTRA_PARAMETERS>` construction to append the extra parameters and have the extension registered.
> [!WARNING]
> The job name is computed by appending `github.job` to the current matrix value (if present). This works only when the matrix contains entries defined as single-dimension array. If a matrix entry is an array of objects, the computed `job-name` can be overridden with the `job-name` action input to avoid having `-object` in the job name.
###### Workflow Summary
By default, a summary will be added to the GitHub workflow calling the action (can be skipped if `add-job-summary` is set to `false`):

![workflow](./doc/summary-workflow.png)

#### Pull-request Comment
###### Pull-request Comment

By default, a comment will be added to the pull-request with the summary (can be skipped if `add-pr-comment` is set to `false`):

![comment](./doc/summary-comment.png)

**Permissions**:

The following permissions are required for this feature to work:
- `pull-requests: write`: to comment the pull-request

> [!NOTE]
> - The job name is computed by appending `github.job` to the current matrix value (if present) but can be overridden with `job-name` input.
> - The pull-request comment is overwriting the previous summary comment if present, this means that if several jobs have a setup-maven step,
> The pull-request comment is overwriting the previous summary comment if present, this means that if several jobs have a setup-maven step,
only the last will have its summary commented in the PR. It is recommended to disable the pull-request summary in this case (`add-pr-comment: false`).

#### Raw Summary data
###### Raw Summary data

Additionally, the summary details will be accessible in `$RUNNER_TEMP/build-scan-data-maven/build-metadata.json` with the format below:

Expand Down Expand Up @@ -102,8 +106,46 @@ Additionally, the summary details will be accessible in `$RUNNER_TEMP/build-scan
]
}
```
#### Capture unpublished Build Scan®

---

#### Develocity extensions injection

If one wants to inject Develocity Maven Extension (and optionally CCUD Maven Extension), the `develocity-injection-enabled` input should be set to `true`. The `develocity-url`, `develocity-maven-extension-version`, and optionally `develocity-ccud-maven-extension-version` inputs should be set accordingly:
```yaml
name: PR Build
jobs:
build:
- name: Setup Maven
uses: gradle/develocity-actions/maven-setup@v1
with:
develocity-url: 'https://scans.gradle.com'
develocity-injection-enabled: 'true'
develocity-maven-extension-version: '<DV_EXTENSION_VERSION>'
- name: Build with Maven
run: ./mvnw clean package
[...]
```

> [!NOTE]
> DV_EXTENSION_VERSION needs to be adjusted to the expected version of the Develocity Maven Extension.
---

#### Capture Build Scan® data

###### Requirements
- The Maven project must be compiled with JDK 8 or above
- The Maven project must have the Develocity extension applied (or injected)

The process is handled by a [Maven extension](https://maven.apache.org/guides/mini/guide-using-extensions.html) `maven-build-scan-capture-extension.jar` which is running during each Maven invocation.
The extension is automatically registered by configuring the environment `MAVEN_OPTS=-Dmaven.ext.classpath=<PATH_TO_EXTENSION>`.

> [!WARNING]
> If `MAVEN_OPTS` environment variable is set in the step invoking the `mvn` command, the extension won't be registered.
Make sure to use `MAVEN_OPTS: ${{ env.MAVEN_OPTS }} <EXTRA_PARAMETERS>` construction to append the extra parameters and have the extension registered.
###### Configuration
The _capture strategy_ can be customized:
- `ALWAYS`: default behavior, capture will be attempted on each Maven invocation
- `ON_FAILURE`: capture will be attempted only on failed builds
Expand All @@ -113,13 +155,6 @@ The _capture_ can be _enabled_/_disabled_ separately:
- `capture-unpublished-build-scans`: to disable unpublished Build Scan® capture
- `capture-build-scan-links`: to disable Build Scan® link capture

The process is handled by a [Maven extension](https://maven.apache.org/guides/mini/guide-using-extensions.html) `maven-build-scan-capture-extension.jar` which is running during each Maven invocation.
The extension is automatically registered by configuring the environment `MAVEN_OPTS=-Dmaven.ext.classpath=<PATH_TO_EXTENSION>`.

> [!NOTE]
> If `MAVEN_OPTS` environment variable is set in the step invoking the `mvn` command, the extension won't be registered.
Make sure to use `MAVEN_OPTS: ${{ env.MAVEN_OPTS }} <EXTRA_PARAMETERS>` construction to append the extra parameters and have the extension registered.
The captured files are added as workflow artifact (one artifact per job).

When a Build Scan link is captured, it is added as output to the step invoking Maven.
Expand All @@ -130,12 +165,9 @@ The output name is `build-scan-url` and can be used in subsequent steps of the w
- `pull_request`: To capture unpublished Build Scan®
- `workflow_run`: To capture Build Scan® links

**Permissions**:

The following permissions are required for this action to operate:
- `pull-requests: write`: to comment the pull-request
---

**Action inputs**:
### Action inputs

| Name | Description | Default |
|-------------------------------------------|---------------------------------------------------------------------------------------------------|----------|
Expand All @@ -154,7 +186,10 @@ The following permissions are required for this action to operate:
| `develocity-ccud-maven-extension-version` | *Optional*: Common Custom User Data Maven Extension version to be injected | |
| `develocity-allow-untrusted-server` | *Optional*: Whether to allow communicating with untrusted server | |

## Publish Build Scans® for pull-requests issued from forked repositories
---

## maven-publish-build-scan action
Publish Build Scans® for pull-requests issued from forked repositories

### Description
When submitting a pull request from a forked GitHub repository, a GitHub workflow that validates the change cannot publish a Build Scan®
Expand Down Expand Up @@ -232,7 +267,7 @@ The action will publish Build Scans® if the initial pull-request author belongs
The following permissions are required for this action to operate:
- `actions: write`: to delete a workflow artifact

**Action inputs**:
### Action inputs

| Name | Description | Default |
|----------------------------------|------------------------------------------------------------------------------|-----------------------|
Expand All @@ -241,3 +276,11 @@ The following permissions are required for this action to operate:
| `develocity-allow-untrusted` | *Optional*: Develocity allow-untrusted flag | `false` |
| `authorized-users-list` | *Optional*: CSV List of users allowed to publish Build Scans | `''` |
| `github-token` | *Optional*: Github token | `${{ github.token }}` |

---

## Build the action

```bash
npm run all
```
Binary file not shown.
22 changes: 5 additions & 17 deletions maven-build-scan-capture-extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@
<version>5.10.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.10.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand All @@ -76,13 +70,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.12.0</version>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -94,8 +82,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>11</source>
<target>11</target>
<source>8</source>
<target>8</target>
<annotationProcessorPaths>
<path>
<groupId>org.eclipse.sisu</groupId>
Expand All @@ -119,8 +107,8 @@
<configuration>
<rules>
<requireJavaVersion>
<!-- force jdk 11 to allow backward compatibility until this version -->
<version>(11,12)</version>
<!-- force jdk 8 to allow backward compatibility until this version -->
<version>8</version>
</requireJavaVersion>
</rules>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ public final class MavenBuildScanCaptureListener implements DevelocityListener {

private static final Logger LOGGER = LoggerFactory.getLogger(MavenBuildScanCaptureListener.class);
private static final String SCAN_DUMP_REGEX = ".*/build-scan-data/.*/previous/.*/scan.scan";
private final BuildState buildState = new BuildState();
private BuildState buildState = new BuildState();
private Configuration configuration = DefaultConfiguration.get();
private FileManager fileManager = new DefaultFileManager();

public void setBuildState(BuildState buildState) {
this.buildState = buildState;
}

public void setConfiguration(Configuration configuration) {
this.configuration = configuration;
}

public void setFileManager(FileManager fileManager) {
this.fileManager = fileManager;
}
Expand Down Expand Up @@ -99,7 +104,8 @@ private void addToGitHubOutput(String key, String value) {
try {
String githubOutput = System.getenv("GITHUB_OUTPUT");
if (githubOutput != null) {
Files.writeString(Paths.get(githubOutput), key + "=" + value + "\n", StandardCharsets.UTF_8, StandardOpenOption.APPEND);
String content = key + "=" + value + "\n";
Files.write(Paths.get(githubOutput), content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
}
} catch (IOException e) {
LOGGER.info("Unable to add " + key + " to GitHub output " + e.getMessage());
Expand Down
Loading

0 comments on commit 1d769fc

Please sign in to comment.