Skip to content

Commit

Permalink
Fix MAVEN_HOME when using Maven wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
jprinet committed Dec 6, 2023
1 parent fe8ab6a commit db2bd8f
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 39 deletions.
44 changes: 35 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ Some parameters need to be adjusted here:
- The workflow name (here `PR Build`) triggered when a pull-request is submitted
- The Develocity URL (here `https://<MY_DEVELOCITY_URL>`)
- The secret name holding the Develocity access key (here `<DEVELOCITY_ACCESS_KEY>`)

- If using the [Maven wrapper](https://maven.apache.org/wrapper/), check the [relevant section](#Usage with Maven Wrapper)

### Implementation details

#### maven-build-scan-setup
Expand Down Expand Up @@ -96,14 +97,14 @@ The `MAVEN_HOME` environment variable is used if present, otherwise, the csv lis

**Action inputs**:

| Name | Description | Default |
|------------------------------------------|-------------------------------------------------------------------------|------------------------------------------------------------------------------------|
| `workflow-filename` | *Optional*: Name of the workflow triggering the build | `${{ github.workflow }}` |
| `job-filename` | *Optional*: Name of the job triggering the build | `${{ github.job }}` |
| `maven-home-search-patterns` | *Optional*: List of patterns to search for maven home (csv format) | `/usr/share/apache-maven-*/,C:/ProgramData/chocolatey/lib/maven/apache-maven-*/` |
| `build-scan-capture-strategy` | *Optional*: Build Scan capture strategy (ALWAYS, ON_FAILURE, ON_DEMAND) | `ALWAYS` |
| `build-scan-capture-unpublished-enabled` | *Optional*: Flag to enable unpublished Build Scan capture | `true` |
| `build-scan-capture-link-enabled` | *Optional*: Flag to enable Build Scan link capture | `true` |
| Name | Description | Default |
|------------------------------------------|-------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `workflow-filename` | *Optional*: Name of the workflow triggering the build | `${{ github.workflow }}` |
| `job-filename` | *Optional*: Name of the job triggering the build | `${{ github.job }}` |
| `maven-home-search-patterns` | *Optional*: List of patterns to search for maven home (csv format) | `~/.m2/wrapper/dists/apache-maven-*/*/apache-maven-*/,/usr/share/apache-maven-*/,C:/Users/runneradmin/.m2/wrapper/dists/apache-maven-*/*/apache-maven-*/,C:/ProgramData/chocolatey/lib/maven/apache-maven-*/` |
| `build-scan-capture-strategy` | *Optional*: Build Scan capture strategy (ALWAYS, ON_FAILURE, ON_DEMAND) | `ALWAYS` |
| `build-scan-capture-unpublished-enabled` | *Optional*: Flag to enable unpublished Build Scan capture | `true` |
| `build-scan-capture-link-enabled` | *Optional*: Flag to enable Build Scan link capture | `true` |

**Usage**:

Expand All @@ -122,6 +123,31 @@ jobs:
[...]
```

#### Usage with Maven Wrapper

When using the Maven wrapper, the Maven extension can't be registered once at the beginning of the build by copying it to `$MAVEN_HOME/lib/ext` as the folder is created on first `mvnw` invocation (and emptied if already present).

There are two options in this situation:
1. Add a minimal `mvnw help` step at the beginning of the job and reference `gradle/github-actions/maven-build-scan-setup` step after
2. Register the Maven extension as a Maven CLI argument (`-Dmaven.ext.class.path`)

In details, the approach 2. which copies the Maven extension in `./maven-build-scan-capture/lib/ext` (using a relative path makes this approach compatible with Windows OS):
```yaml
name: PR Build
jobs:
[...]
build:
[...]
- name: Setup Develocity Build Scan capture
uses: gradle/github-actions/maven-build-scan-setup@v0.2.1
env:
MAVEN_HOME: maven-build-scan-capture
job-name: "Initial JDK 17 Build"
- name: Build with Maven
run: ./mvnw clean package -Dmaven.ext.class.path=maven-build-scan-capture/lib/ext/maven-build-scan-capture-extension.jar
[...]
```

#### maven-build-scan-publish

The action will download any saved Build Scan® and publish them to Develocity.
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion maven-build-scan-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ inputs:
maven-home-search-patterns:
description: 'List of patterns to search for maven home (csv format)'
required: false
default: /usr/share/apache-maven-*/,C:/ProgramData/chocolatey/lib/maven/apache-maven-*/
default: ~/.m2/wrapper/dists/apache-maven-*/*/apache-maven-*/,/usr/share/apache-maven-*/,C:/Users/runneradmin/.m2/wrapper/dists/apache-maven-*/*/apache-maven-*/,C:/ProgramData/chocolatey/lib/maven/apache-maven-*/
build-scan-capture-strategy:
description: 'Build Scan capture strategy (ALWAYS, ON_FAILURE, ON_DEMAND)'
required: false
Expand Down
37 changes: 23 additions & 14 deletions maven-build-scan-setup/dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33601,7 +33601,7 @@ function wrappy (fn, cb) {

/***/ }),

/***/ 884:
/***/ 8029:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand Down Expand Up @@ -33633,10 +33633,10 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.run = void 0;
const core = __importStar(__nccwpck_require__(2186));
const github = __importStar(__nccwpck_require__(5438));
const input = __importStar(__nccwpck_require__(2121));
const layout = __importStar(__nccwpck_require__(3460));
const io = __importStar(__nccwpck_require__(8431));
const errorHandler = __importStar(__nccwpck_require__(7183));
const input = __importStar(__nccwpck_require__(6921));
const layout = __importStar(__nccwpck_require__(5932));
const io = __importStar(__nccwpck_require__(9126));
const errorHandler = __importStar(__nccwpck_require__(9581));
/**
* Main entrypoint for the action
*/
Expand Down Expand Up @@ -33665,7 +33665,7 @@ run();

/***/ }),

/***/ 7183:
/***/ 9581:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand Down Expand Up @@ -33707,7 +33707,7 @@ exports.handle = handle;

/***/ }),

/***/ 2121:
/***/ 6921:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand Down Expand Up @@ -33766,7 +33766,7 @@ exports.getBuildScanCaptureLinkEnabled = getBuildScanCaptureLinkEnabled;

/***/ }),

/***/ 8431:
/***/ 9126:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand All @@ -33775,17 +33775,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.copyFileSync = void 0;
exports.mkdirSync = exports.copyFileSync = void 0;
const fs_1 = __importDefault(__nccwpck_require__(7147));
function copyFileSync(source, dest) {
fs_1.default.copyFileSync(source, dest);
}
exports.copyFileSync = copyFileSync;
function mkdirSync(dir) {
fs_1.default.mkdirSync(dir, { recursive: true });
}
exports.mkdirSync = mkdirSync;


/***/ }),

/***/ 3460:
/***/ 5932:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand Down Expand Up @@ -33819,9 +33823,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.mavenBuildScanDataCopy = exports.mavenBuildScanDataOriginal = exports.mavenBuildScanCaptureExtensionTarget = exports.mavenBuildScanCaptureExtensionSource = void 0;
const path_1 = __importDefault(__nccwpck_require__(1017));
const params = __importStar(__nccwpck_require__(2121));
const core = __importStar(__nccwpck_require__(2186));
const glob = __importStar(__nccwpck_require__(8090));
const params = __importStar(__nccwpck_require__(6921));
const io = __importStar(__nccwpck_require__(9126));
const ENV_KEY_HOME = 'HOME';
const ENV_KEY_MAVEN_HOME = 'MAVEN_HOME';
const BUILD_SCAN_DIR_ORIGINAL = '.m2/.gradle-enterprise/build-scan-data/';
Expand All @@ -33840,11 +33845,15 @@ async function mavenBuildScanCaptureExtensionTarget() {
const mavenHome = process.env[ENV_KEY_MAVEN_HOME];
if (mavenHome) {
core.info(`Using MAVEN_HOME=${mavenHome}`);
return `${mavenHome}${LIB_EXT}${MAVEN_BUILD_SCAN_CAPTURE_EXTENSION_JAR}`;
const libExtDir = `${mavenHome}${LIB_EXT}`;
// Create folder if missing
core.info(`Creating ${libExtDir}`);
io.mkdirSync(libExtDir);
return `${libExtDir}${MAVEN_BUILD_SCAN_CAPTURE_EXTENSION_JAR}`;
}
else {
core.info(`Searching maven home in ${params.getMavenHomeSearchPatterns()}`);
const globber = await glob.create(params.getMavenHomeSearchPatterns().replace(',', '\n'));
const globber = await glob.create(params.getMavenHomeSearchPatterns().replaceAll(',', '\n'));
const mavenHomeGlob = await globber.glob();
if (mavenHomeGlob && mavenHomeGlob.at(0)) {
core.info(`Found maven home in ${mavenHomeGlob.at(0)}`);
Expand Down Expand Up @@ -35775,7 +35784,7 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
/******/ var __webpack_exports__ = __nccwpck_require__(884);
/******/ var __webpack_exports__ = __nccwpck_require__(8029);
/******/ module.exports = __webpack_exports__;
/******/
/******/ })()
Expand Down
48 changes: 38 additions & 10 deletions maven-build-scan-setup/dist/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32298,7 +32298,7 @@ function wrappy (fn, cb) {

/***/ }),

/***/ 7393:
/***/ 9949:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand Down Expand Up @@ -32331,8 +32331,8 @@ exports.run = void 0;
const core = __importStar(__nccwpck_require__(2186));
const artifact_1 = __nccwpck_require__(2605);
const glob = __importStar(__nccwpck_require__(8090));
const layout = __importStar(__nccwpck_require__(3460));
const errorHandler = __importStar(__nccwpck_require__(7183));
const layout = __importStar(__nccwpck_require__(5932));
const errorHandler = __importStar(__nccwpck_require__(9581));
const BUILD_SCAN_ARTIFACT_NAME = 'maven-build-scan-data';
// Catch and log any unhandled exceptions.
process.on('uncaughtException', e => errorHandler.handle(e));
Expand Down Expand Up @@ -32371,7 +32371,7 @@ run();

/***/ }),

/***/ 7183:
/***/ 9581:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand Down Expand Up @@ -32413,7 +32413,7 @@ exports.handle = handle;

/***/ }),

/***/ 2121:
/***/ 6921:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand Down Expand Up @@ -32472,7 +32472,30 @@ exports.getBuildScanCaptureLinkEnabled = getBuildScanCaptureLinkEnabled;

/***/ }),

/***/ 3460:
/***/ 9126:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";

var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.mkdirSync = exports.copyFileSync = void 0;
const fs_1 = __importDefault(__nccwpck_require__(7147));
function copyFileSync(source, dest) {
fs_1.default.copyFileSync(source, dest);
}
exports.copyFileSync = copyFileSync;
function mkdirSync(dir) {
fs_1.default.mkdirSync(dir, { recursive: true });
}
exports.mkdirSync = mkdirSync;


/***/ }),

/***/ 5932:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand Down Expand Up @@ -32506,9 +32529,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.mavenBuildScanDataCopy = exports.mavenBuildScanDataOriginal = exports.mavenBuildScanCaptureExtensionTarget = exports.mavenBuildScanCaptureExtensionSource = void 0;
const path_1 = __importDefault(__nccwpck_require__(1017));
const params = __importStar(__nccwpck_require__(2121));
const core = __importStar(__nccwpck_require__(2186));
const glob = __importStar(__nccwpck_require__(8090));
const params = __importStar(__nccwpck_require__(6921));
const io = __importStar(__nccwpck_require__(9126));
const ENV_KEY_HOME = 'HOME';
const ENV_KEY_MAVEN_HOME = 'MAVEN_HOME';
const BUILD_SCAN_DIR_ORIGINAL = '.m2/.gradle-enterprise/build-scan-data/';
Expand All @@ -32527,11 +32551,15 @@ async function mavenBuildScanCaptureExtensionTarget() {
const mavenHome = process.env[ENV_KEY_MAVEN_HOME];
if (mavenHome) {
core.info(`Using MAVEN_HOME=${mavenHome}`);
return `${mavenHome}${LIB_EXT}${MAVEN_BUILD_SCAN_CAPTURE_EXTENSION_JAR}`;
const libExtDir = `${mavenHome}${LIB_EXT}`;
// Create folder if missing
core.info(`Creating ${libExtDir}`);
io.mkdirSync(libExtDir);
return `${libExtDir}${MAVEN_BUILD_SCAN_CAPTURE_EXTENSION_JAR}`;
}
else {
core.info(`Searching maven home in ${params.getMavenHomeSearchPatterns()}`);
const globber = await glob.create(params.getMavenHomeSearchPatterns().replace(',', '\n'));
const globber = await glob.create(params.getMavenHomeSearchPatterns().replaceAll(',', '\n'));
const mavenHomeGlob = await globber.glob();
if (mavenHomeGlob && mavenHomeGlob.at(0)) {
core.info(`Found maven home in ${mavenHomeGlob.at(0)}`);
Expand Down Expand Up @@ -34438,7 +34466,7 @@ module.exports = parseParams
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
/******/ var __webpack_exports__ = __nccwpck_require__(7393);
/******/ var __webpack_exports__ = __nccwpck_require__(9949);
/******/ module.exports = __webpack_exports__;
/******/
/******/ })()
Expand Down
4 changes: 4 additions & 0 deletions maven-build-scan-setup/src/utils/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ import fs from 'fs'
export function copyFileSync(source: string, dest: string): void {
fs.copyFileSync(source, dest)
}

export function mkdirSync(dir: string): void {
fs.mkdirSync(dir, {recursive: true})
}
15 changes: 12 additions & 3 deletions maven-build-scan-setup/src/utils/layout.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import path from 'path'

import * as params from './input'
import * as core from '@actions/core'
import * as glob from '@actions/glob'

import * as params from './input'
import * as io from './io'

const ENV_KEY_HOME = 'HOME'
const ENV_KEY_MAVEN_HOME = 'MAVEN_HOME'

Expand Down Expand Up @@ -34,10 +36,17 @@ export async function mavenBuildScanCaptureExtensionTarget(): Promise<string> {

if (mavenHome) {
core.info(`Using MAVEN_HOME=${mavenHome}`)
return `${mavenHome}${LIB_EXT}${MAVEN_BUILD_SCAN_CAPTURE_EXTENSION_JAR}`

const libExtDir = `${mavenHome}${LIB_EXT}`

// Create folder if missing
core.info(`Creating ${libExtDir}`)
io.mkdirSync(libExtDir)

return `${libExtDir}${MAVEN_BUILD_SCAN_CAPTURE_EXTENSION_JAR}`
} else {
core.info(`Searching maven home in ${params.getMavenHomeSearchPatterns()}`)
const globber = await glob.create(params.getMavenHomeSearchPatterns().replace(',', '\n'))
const globber = await glob.create(params.getMavenHomeSearchPatterns().replaceAll(',', '\n'))
const mavenHomeGlob = await globber.glob()
if (mavenHomeGlob && mavenHomeGlob.at(0)) {
core.info(`Found maven home in ${mavenHomeGlob.at(0)}`)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"format:test": "prettier --write **/__tests__/**/*.ts",
"lint": "eslint */src/**/*.ts",
"package-maven-build-scan-capture-extension": "mvn clean package -f maven-build-scan-capture-extension/pom.xml",
"package-maven-build-scan-setup-main": "ncc build maven-build-scan-setup/src/main.ts --out maven-build-scan-capture/dist/main",
"package-maven-build-scan-setup-post": "ncc build maven-build-scan-setup/src/post.ts --out maven-build-scan-capture/dist/post",
"package-maven-build-scan-setup-main": "ncc build maven-build-scan-setup/src/main.ts --out maven-build-scan-setup/dist/main",
"package-maven-build-scan-setup-post": "ncc build maven-build-scan-setup/src/post.ts --out maven-build-scan-setup/dist/post",
"package-maven-build-scan-setup": "npm run package-maven-build-scan-setup-main && npm run package-maven-build-scan-setup-post && npm run package-maven-build-scan-capture-extension",
"package-maven-build-scan-publish": "ncc build maven-build-scan-publish/src/main.ts --out maven-build-scan-publish/dist",
"package": "npm run package-maven-build-scan-setup && npm run package-maven-build-scan-publish",
Expand Down

0 comments on commit db2bd8f

Please sign in to comment.