diff --git a/README.md b/README.md index 0480474..35ea01e 100644 --- a/README.md +++ b/README.md @@ -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://`) - The secret name holding the Develocity access key (here ``) - +- If using the [Maven wrapper](https://maven.apache.org/wrapper/), check the [relevant section](#Usage with Maven Wrapper) + ### Implementation details #### maven-build-scan-setup @@ -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**: @@ -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. diff --git a/maven-build-scan-capture-extension/dist/maven-build-scan-capture-extension.jar b/maven-build-scan-capture-extension/dist/maven-build-scan-capture-extension.jar index ce3a0c1..28a125d 100644 Binary files a/maven-build-scan-capture-extension/dist/maven-build-scan-capture-extension.jar and b/maven-build-scan-capture-extension/dist/maven-build-scan-capture-extension.jar differ diff --git a/maven-build-scan-setup/action.yml b/maven-build-scan-setup/action.yml index e3ecea7..86460a1 100644 --- a/maven-build-scan-setup/action.yml +++ b/maven-build-scan-setup/action.yml @@ -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 diff --git a/maven-build-scan-setup/dist/main/index.js b/maven-build-scan-setup/dist/main/index.js index 578366f..f9ef5c5 100644 --- a/maven-build-scan-setup/dist/main/index.js +++ b/maven-build-scan-setup/dist/main/index.js @@ -33601,7 +33601,7 @@ function wrappy (fn, cb) { /***/ }), -/***/ 884: +/***/ 8029: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; @@ -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 */ @@ -33665,7 +33665,7 @@ run(); /***/ }), -/***/ 7183: +/***/ 9581: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; @@ -33707,7 +33707,7 @@ exports.handle = handle; /***/ }), -/***/ 2121: +/***/ 6921: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; @@ -33766,7 +33766,7 @@ exports.getBuildScanCaptureLinkEnabled = getBuildScanCaptureLinkEnabled; /***/ }), -/***/ 8431: +/***/ 9126: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; @@ -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"; @@ -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/'; @@ -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)}`); @@ -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__; /******/ /******/ })() diff --git a/maven-build-scan-setup/dist/post/index.js b/maven-build-scan-setup/dist/post/index.js index 7100991..3902949 100644 --- a/maven-build-scan-setup/dist/post/index.js +++ b/maven-build-scan-setup/dist/post/index.js @@ -32298,7 +32298,7 @@ function wrappy (fn, cb) { /***/ }), -/***/ 7393: +/***/ 9949: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; @@ -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)); @@ -32371,7 +32371,7 @@ run(); /***/ }), -/***/ 7183: +/***/ 9581: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; @@ -32413,7 +32413,7 @@ exports.handle = handle; /***/ }), -/***/ 2121: +/***/ 6921: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; @@ -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"; @@ -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/'; @@ -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)}`); @@ -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__; /******/ /******/ })() diff --git a/maven-build-scan-setup/src/utils/io.ts b/maven-build-scan-setup/src/utils/io.ts index 0323196..d93e243 100644 --- a/maven-build-scan-setup/src/utils/io.ts +++ b/maven-build-scan-setup/src/utils/io.ts @@ -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}) +} diff --git a/maven-build-scan-setup/src/utils/layout.ts b/maven-build-scan-setup/src/utils/layout.ts index 6e5a142..610ad33 100644 --- a/maven-build-scan-setup/src/utils/layout.ts +++ b/maven-build-scan-setup/src/utils/layout.ts @@ -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' @@ -34,10 +36,17 @@ export async function mavenBuildScanCaptureExtensionTarget(): Promise { 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)}`) diff --git a/package.json b/package.json index 937e757..895f16b 100644 --- a/package.json +++ b/package.json @@ -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",