From 747ee6630fe8874bab927c5a796655f112d342a7 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Wed, 7 Jul 2021 08:53:58 -0400 Subject: [PATCH 1/4] Add inDir argument for version and deploy Signed-off-by: Timothy Johnson --- .../pipelines/nodejs/NodeJSPipeline.groovy | 24 +++++++++++++++---- .../arguments/DeployStageArguments.groovy | 5 ++++ .../NodeJSVersionStageArguments.groovy | 5 ++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy b/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy index b0858d0b..62a098e0 100644 --- a/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy +++ b/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy @@ -505,7 +505,9 @@ class NodeJSPipeline extends GenericPipeline { // the tag to point to an invalid commit hash. steps.sh "npm version ${steps.env.DEPLOY_VERSION} --allow-same-version --no-git-tag-version" } else { - steps.sh "npx lerna version ${steps.env.DEPLOY_VERSION} --exact --include-merged-tags --no-git-tag-version --yes" + wrapInDir(arguments.inDir) { + steps.sh "npx lerna version ${steps.env.DEPLOY_VERSION} --exact --include-merged-tags --no-git-tag-version --yes" + } } steps.sh "git add -u" // Safe because we ran "git reset" above if (arguments.updateChangelogArgs) { @@ -732,7 +734,7 @@ class NodeJSPipeline extends GenericPipeline { throw deployException } - runForEachMonorepoPackage(LernaFilter.CHANGED) { + (isLernaMonorepo ? runForEachMonorepoPackage(LernaFilter.CHANGED) : wrapInDir(deployArguments.inDir)) { // Login to the registry def npmRegistry = steps.sh returnStdout: true, script: "node -e \"process.stdout.write(require('./package.json').publishConfig.registry)\"" @@ -1253,8 +1255,6 @@ expect { * * @param filter Specify how package list should be filtered. * @param body Closure to run for each package - * - * @Note The onlyIfChanged param has no effect for single package repos. */ protected void runForEachMonorepoPackage(LernaFilter filter, Closure body) { if (!isLernaMonorepo) { @@ -1269,6 +1269,22 @@ expect { } } + /** + * Run a closure inside a specific directory, if one is specified. + * + * @param inDir The directory to enter + * @param body Closure to run + */ + protected void wrapInDir(String inDir, Closure body) { + if (!inDir) { + body() + } else { + steps.dir(inDir) { + body() + } + } + } + /** * Returns list of package directories to check for changelog files in. * If the list is empty, only the root directory is checked. diff --git a/src/org/zowe/pipelines/nodejs/arguments/DeployStageArguments.groovy b/src/org/zowe/pipelines/nodejs/arguments/DeployStageArguments.groovy index fd7c0b48..38bc7358 100644 --- a/src/org/zowe/pipelines/nodejs/arguments/DeployStageArguments.groovy +++ b/src/org/zowe/pipelines/nodejs/arguments/DeployStageArguments.groovy @@ -24,6 +24,11 @@ class DeployStageArguments extends GenericStageArguments { */ String name = "Package" + /** + * If specified, the deploy stage will run in this project subdirectory. + */ + String inDir + /** * The custom login operation. * diff --git a/src/org/zowe/pipelines/nodejs/arguments/NodeJSVersionStageArguments.groovy b/src/org/zowe/pipelines/nodejs/arguments/NodeJSVersionStageArguments.groovy index 041e82d8..279e734c 100644 --- a/src/org/zowe/pipelines/nodejs/arguments/NodeJSVersionStageArguments.groovy +++ b/src/org/zowe/pipelines/nodejs/arguments/NodeJSVersionStageArguments.groovy @@ -22,4 +22,9 @@ class NodeJSVersionStageArguments extends VersionStageArguments { * with them. */ Map updateChangelogArgs + + /** + * If specified, the version stage will run in this project subdirectory. + */ + String inDir } From f07d86892929df7fbd9c0260e761f428c3801025 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Wed, 7 Jul 2021 11:03:41 -0400 Subject: [PATCH 2/4] Add customInstallScript to setup args Signed-off-by: Timothy Johnson --- src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy | 6 +++++- .../pipelines/nodejs/arguments/NodeJSSetupArguments.groovy | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy b/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy index 62a098e0..c1c7d5f0 100644 --- a/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy +++ b/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy @@ -928,7 +928,11 @@ class NodeJSPipeline extends GenericPipeline { branch = changeInfo.branchName } - steps.sh "npm install" + if (arguments.customInstallScript) { + steps.sh "npm run ${arguments.customInstallScript}" + } else { + steps.sh "npm install" + } if (isLernaMonorepo) { for (filter in LernaFilter.values()) { diff --git a/src/org/zowe/pipelines/nodejs/arguments/NodeJSSetupArguments.groovy b/src/org/zowe/pipelines/nodejs/arguments/NodeJSSetupArguments.groovy index 1b5d765c..e7d17a2b 100644 --- a/src/org/zowe/pipelines/nodejs/arguments/NodeJSSetupArguments.groovy +++ b/src/org/zowe/pipelines/nodejs/arguments/NodeJSSetupArguments.groovy @@ -44,4 +44,10 @@ class NodeJSSetupArguments extends GenericSetupArguments { * NPM version to install (e.g., "^7") */ String npmVersion + + /** + * NPM script to use for installing dependencies (e.g., "install:all"). + * If undefined, the default behavior is to run "npm install". + */ + String customInstallScript } From 72d884f2bfaa7c560e4c70ca2a23a3157f6fe67f Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Wed, 7 Jul 2021 14:37:44 -0400 Subject: [PATCH 3/4] Fix invalid method signature in deploy stage Signed-off-by: Timothy Johnson --- src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy b/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy index c1c7d5f0..08dbf6a8 100644 --- a/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy +++ b/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy @@ -734,7 +734,7 @@ class NodeJSPipeline extends GenericPipeline { throw deployException } - (isLernaMonorepo ? runForEachMonorepoPackage(LernaFilter.CHANGED) : wrapInDir(deployArguments.inDir)) { + def innerOperation = { // Login to the registry def npmRegistry = steps.sh returnStdout: true, script: "node -e \"process.stdout.write(require('./package.json').publishConfig.registry)\"" @@ -805,6 +805,12 @@ class NodeJSPipeline extends GenericPipeline { steps.echo "Deploy Complete, please check this step for errors" } } + + if (isLernaMonorepo) { + runForEachMonorepoPackage(LernaFilter.CHANGED, innerOperation) + } else { + wrapInDir(deployArguments.inDir, innerOperation) + } } // Prevent versioning stage to be created by deployGeneric if no versionArguments were specified From c5d87fd5c386168d057c3922314f65d2338ee2de Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Wed, 7 Jul 2021 15:18:35 -0400 Subject: [PATCH 4/4] Fix flipped version logic for inDir Signed-off-by: Timothy Johnson --- src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy b/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy index 08dbf6a8..79043cbb 100644 --- a/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy +++ b/src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy @@ -503,11 +503,11 @@ class NodeJSPipeline extends GenericPipeline { // Don't let NPM perform Git commit and tag operations. We don't like the commit message generated by // NPM, so we want to amend the commit. If the commit has already been tagged, amending it will cause // the tag to point to an invalid commit hash. - steps.sh "npm version ${steps.env.DEPLOY_VERSION} --allow-same-version --no-git-tag-version" - } else { wrapInDir(arguments.inDir) { - steps.sh "npx lerna version ${steps.env.DEPLOY_VERSION} --exact --include-merged-tags --no-git-tag-version --yes" + steps.sh "npm version ${steps.env.DEPLOY_VERSION} --allow-same-version --no-git-tag-version" } + } else { + steps.sh "npx lerna version ${steps.env.DEPLOY_VERSION} --exact --include-merged-tags --no-git-tag-version --yes" } steps.sh "git add -u" // Safe because we ran "git reset" above if (arguments.updateChangelogArgs) { @@ -806,10 +806,10 @@ class NodeJSPipeline extends GenericPipeline { } } - if (isLernaMonorepo) { - runForEachMonorepoPackage(LernaFilter.CHANGED, innerOperation) - } else { + if (!isLernaMonorepo) { wrapInDir(deployArguments.inDir, innerOperation) + } else { + runForEachMonorepoPackage(LernaFilter.CHANGED, innerOperation) } }