Skip to content

Commit 4a2aed8

Browse files
authored
Add custom Maven repository inputs to setup-maven action (#112)
1 parent f31838d commit 4a2aed8

13 files changed

Lines changed: 2198 additions & 86 deletions

File tree

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"project": "./tsconfig.json"
99
},
1010
"rules": {
11+
"@typescript-eslint/no-floating-promises": "error",
1112
"eslint-comments/no-use": "off",
1213
"import/no-namespace": "off",
1314
"i18n-text/no-en": "off",

README.md

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The action enables three features:
1313
- [Develocity extensions injection](#develocity-extensions-injection): Inject Develocity/CCUD Maven extensions
1414
- [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.
1515

16-
> [!NOTE]
16+
> [!NOTE]
1717
> This action can be combined with the `maven-publish-build-scan` action to publish Build Scan® in a fork context. See [the relevant section](#maven-publish-build-scan-action) for details.
1818
1919
### Usage
@@ -23,15 +23,15 @@ Insert the `Setup Maven` step once in each job having steps invoking Maven. Make
2323
```yaml
2424
name: PR Build
2525
jobs:
26-
build:
26+
build:
2727
- name: Setup Maven
2828
uses: gradle/develocity-actions/setup-maven@v1
2929
- name: Build with Maven
3030
run: ./mvnw clean package
3131
[...]
3232
```
3333

34-
> [!NOTE]
34+
> [!NOTE]
3535
> When authenticated access is required to publish a Build Scan®, it is recommended to provide as input `develocity-access-key` to the `setup-maven` 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.
3636
3737
---
@@ -49,7 +49,7 @@ The extension is automatically registered by configuring the environment `MAVEN_
4949
> If `MAVEN_OPTS` environment variable is set in the step invoking the `mvn` command, the extension won't be registered.
5050
Make sure to use `MAVEN_OPTS: ${{ env.MAVEN_OPTS }} <EXTRA_PARAMETERS>` construction to append the extra parameters and have the extension registered.
5151
52-
> [!WARNING]
52+
> [!WARNING]
5353
> 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.
5454
5555
###### Workflow Summary
@@ -69,8 +69,8 @@ The following permissions are required for this feature to work:
6969
- `pull-requests: write`: to comment the pull-request
7070

7171
> [!NOTE]
72-
> The pull-request comment is overwriting the previous summary comment if present, this means that if several jobs have a setup-maven step,
73-
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`).
72+
> The pull-request comment is overwriting the previous summary comment if present, this means that if several jobs have a setup-maven step,
73+
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`).
7474

7575
###### Raw Summary data
7676

@@ -115,7 +115,7 @@ If one wants to inject Develocity Maven Extension (and optionally CCUD Maven Ext
115115
```yaml
116116
name: PR Build
117117
jobs:
118-
build:
118+
build:
119119
- name: Setup Maven
120120
uses: gradle/develocity-actions/setup-maven@v1
121121
with:
@@ -169,34 +169,37 @@ The output name is `build-scan-url` and can be used in subsequent steps of the w
169169

170170
### Action inputs
171171

172-
| Name | Description | Default |
173-
|------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|----------|
174-
| `develocity-access-key` | *Optional*: Develocity access key. Should be set to a secret containing the Develocity Access key | `` |
175-
| `develocity-token-expiry` | *Optional*: Develocity short-lived access tokens expiry in hours | `2` |
176-
| `capture-strategy` | *Optional*: Build Scan capture strategy (ALWAYS, ON_FAILURE, ON_DEMAND) | `ALWAYS` |
177-
| `capture-unpublished-build-scans` | *Optional*: Enable unpublished Build Scans capture | `true` |
178-
| `capture-build-scan-links` | *Optional*: Enable Build Scan links capture | `true` |
179-
| `job-name` | *Optional*: Job name (used in summary and as artifact suffix) | |
180-
| `add-pr-comment` | *Optional*: Comment the pull-request with Build Scan links | `true` |
181-
| `add-job-summary` | *Optional*: Add a summary to the GitHub workflow | `true` |
182-
| `add-project-id-in-job-summary` | *Optional*: Add project id to the job summary / comment | `false` |
183-
| `develocity-injection-enabled` | *Optional*: Whether to enable or not Develocity/CCUD Maven Extensions injection | |
184-
| `develocity-url` | *Optional*: Develocity server URL | |
185-
| `develocity-maven-extension-version` | *Optional*: Develocity Maven Extension version to be injected | |
186-
| `develocity-ccud-maven-extension-version` | *Optional*: Common Custom User Data Maven Extension version to be injected | |
187-
| `develocity-allow-untrusted-server` | *Optional*: Whether to allow communicating with untrusted server | |
188-
| `develocity-enforce-url` | *Optional*: Whether to enforce the URL over any defined locally to the project | |
189-
| `develocity-capture-file-fingerprints` | *Optional*: Whether to enable/disable capturing of file fingerprints. This setting is enabled by default | |
190-
| `develocity-custom-develocity-maven-extension-coordinates` | *Optional*: Will not inject the Develocity Maven extension if an extension with provided coordinates is found (value is an artifactId of the extension) | |
191-
| `develocity-custom-ccud-extension-coordinates` | *Optional*: Will not inject the CCUD extension if an extension with provided coordinates is found (value is an artifactId of the extension) | |
172+
| Name | Description | Default |
173+
|------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------|
174+
| `develocity-access-key` | *Optional*: Develocity access key. Should be set to a secret containing the Develocity Access key | `` |
175+
| `develocity-token-expiry` | *Optional*: Develocity short-lived access tokens expiry in hours | `2` |
176+
| `capture-strategy` | *Optional*: Build Scan capture strategy (ALWAYS, ON_FAILURE, ON_DEMAND) | `ALWAYS` |
177+
| `capture-unpublished-build-scans` | *Optional*: Enable unpublished Build Scans capture | `true` |
178+
| `capture-build-scan-links` | *Optional*: Enable Build Scan links capture | `true` |
179+
| `job-name` | *Optional*: Job name (used in summary and as artifact suffix) | |
180+
| `add-pr-comment` | *Optional*: Comment the pull-request with Build Scan links | `true` |
181+
| `add-job-summary` | *Optional*: Add a summary to the GitHub workflow | `true` |
182+
| `add-project-id-in-job-summary` | *Optional*: Add project id to the job summary / comment | `false` |
183+
| `develocity-injection-enabled` | *Optional*: Whether to enable or not Develocity/CCUD Maven Extensions injection | |
184+
| `develocity-url` | *Optional*: Develocity server URL | |
185+
| `develocity-maven-extension-version` | *Optional*: Develocity Maven Extension version to be injected | |
186+
| `develocity-ccud-maven-extension-version` | *Optional*: Common Custom User Data Maven Extension version to be injected | |
187+
| `develocity-maven-repository-url` | *Optional*: URL of the repository to use when resolving the Develocity and CCUD extensions | https://repo1.maven.org/maven2 |
188+
| `develocity-maven-repository-username` | *Optional*: Username for the repository URL to use when resolving the Develocity and CCUD extensions | |
189+
| `develocity-maven-repository-password` | *Optional*: Password for the repository URL to use when resolving the Develocity and CCUD extensions | |
190+
| `develocity-allow-untrusted-server` | *Optional*: Whether to allow communicating with untrusted server | |
191+
| `develocity-enforce-url` | *Optional*: Whether to enforce the URL over any defined locally to the project | |
192+
| `develocity-capture-file-fingerprints` | *Optional*: Whether to enable/disable capturing of file fingerprints. This setting is enabled by default | |
193+
| `develocity-custom-develocity-maven-extension-coordinates` | *Optional*: Will not inject the Develocity Maven extension if an extension with provided coordinates is found (value is an artifactId of the extension) | |
194+
| `develocity-custom-ccud-extension-coordinates` | *Optional*: Will not inject the CCUD extension if an extension with provided coordinates is found (value is an artifactId of the extension) | |
192195

193196
---
194197

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

198201
### Description
199-
When submitting a pull request from a forked GitHub repository, a GitHub workflow that validates the change cannot publish a Build Scan®
202+
When submitting a pull request from a forked GitHub repository, a GitHub workflow that validates the change cannot publish a Build Scan®
200203
as workflows from forked repositories do not have access to secrets. An access token is required to publish a Build Scan®.
201204

202205
> [!NOTE]
@@ -214,7 +217,7 @@ In the GitHub workflow called to validate a pull-request, insert the `Setup Mave
214217
```yaml
215218
name: PR Build
216219
jobs:
217-
build:
220+
build:
218221
- name: Setup Maven
219222
uses: gradle/develocity-actions/setup-maven@v1
220223
- name: Build with Maven
@@ -254,12 +257,12 @@ jobs:
254257
> - The workflow name (here `PR Build`) triggered when a pull-request is submitted
255258
> - The Develocity URL (here `https://<MY_DEVELOCITY_URL>`)
256259
> - The secret name holding the Develocity access key (here `<DEVELOCITY_ACCESS_KEY>`)
257-
260+
258261
#### Implementation details
259262

260263
The action will download any saved Build Scan® and publish them to Develocity.
261264

262-
The list of pull-request authors allowed to publish a Build Scan® can be specified by the csv parameter `authorized-users-list`.
265+
The list of pull-request authors allowed to publish a Build Scan® can be specified by the csv parameter `authorized-users-list`.
263266
The action will publish Build Scans® if the initial pull-request author belongs to the list or if the list is empty.
264267

265268
**Event Triggers**:

build-scan-shared/src/setup/input.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ export function getCcudExtensionVersion(): string {
2222
return sharedInput.getInput('develocity-ccud-extension-version')
2323
}
2424

25+
export function getDevelocityMavenRepositoryUrl(): string {
26+
return sharedInput.getInput('develocity-maven-repository-url')
27+
}
28+
29+
export function getDevelocityMavenRepositoryUsername(): string {
30+
return sharedInput.getInput('develocity-maven-repository-username')
31+
}
32+
33+
export function getDevelocityMavenRepositoryPassword(): string {
34+
return sharedInput.getInput('develocity-maven-repository-password')
35+
}
36+
2537
export function getDevelocityCustomMavenExtensionCoordinates(): string {
2638
return sharedInput.getInput('develocity-custom-develocity-maven-extension-coordinates')
2739
}

build-scan-shared/src/utils/io.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,45 @@ export function renameSync(oldPath: string, newPath: string): void {
6161
fs.renameSync(oldPath, newPath)
6262
}
6363

64-
export async function downloadFile(url: string, downloadFolder: string): Promise<string> {
64+
export type Credentials = {
65+
username: string
66+
password: string
67+
}
68+
69+
export async function downloadFile(url: string, downloadFolder: string, credentials?: Credentials): Promise<string> {
6570
const fileName = path.basename(url)
6671
const filePath = path.join(downloadFolder, fileName)
72+
const options = credentials ? {auth: `${credentials.username}:${credentials.password}`} : {}
73+
74+
function close(file: fs.WriteStream): void {
75+
file.close()
76+
fs.unlink(filePath, unlinkErr => core.debug(`Could not cleanup ${filePath} after close error: ${unlinkErr}`))
77+
}
6778

6879
return new Promise((resolve, reject) => {
6980
// Ensure the download folder exists
7081
if (!existsSync(downloadFolder)) {
7182
mkdirSync(downloadFolder)
7283
}
7384

74-
const file = fs.createWriteStream(filePath)
85+
const file: fs.WriteStream = fs.createWriteStream(filePath)
7586
https
76-
.get(url, response => {
87+
.get(url, options, response => {
7788
if (response.statusCode !== 200) {
89+
response.resume()
90+
close(file)
7891
reject(new Error(`Failed to get '${url}' (${response.statusCode})`))
79-
return
92+
} else {
93+
response.pipe(file)
94+
file.on('finish', () => {
95+
file.close()
96+
resolve(filePath)
97+
})
8098
}
81-
response.pipe(file)
82-
file.on('finish', () => {
83-
file.close()
84-
resolve(filePath)
85-
})
8699
})
87100
.on('error', err => {
88-
fs.unlink(filePath, () => reject(err.message))
101+
close(file)
102+
reject(err)
89103
})
90104
})
91105
}

0 commit comments

Comments
 (0)