Skip to content

Commit

Permalink
Merge pull request #141 from zowe/feature-indir
Browse files Browse the repository at this point in the history
Add new stage arguments
  • Loading branch information
t1m0thyj authored Jul 8, 2021
2 parents 17b1cea + 085abea commit 55228bb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,9 @@ 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"
wrapInDir(arguments.inDir) {
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"
}
Expand Down Expand Up @@ -732,7 +734,7 @@ class NodeJSPipeline extends GenericPipeline {
throw deployException
}

runForEachMonorepoPackage(LernaFilter.CHANGED) {
def innerOperation = {
// Login to the registry
def npmRegistry = steps.sh returnStdout: true,
script: "node -e \"process.stdout.write(require('./package.json').publishConfig.registry)\""
Expand Down Expand Up @@ -822,6 +824,12 @@ class NodeJSPipeline extends GenericPipeline {
steps.echo "Deploy Complete, please check this step for errors"
}
}

if (!isLernaMonorepo) {
wrapInDir(deployArguments.inDir, innerOperation)
} else {
runForEachMonorepoPackage(LernaFilter.CHANGED, innerOperation)
}
}

// Prevent versioning stage to be created by deployGeneric if no versionArguments were specified
Expand Down Expand Up @@ -945,7 +953,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()) {
Expand Down Expand Up @@ -1272,8 +1284,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) {
Expand All @@ -1288,6 +1298,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class DeployStageArguments extends GenericStageArguments {
*/
Boolean smokeTest = true

/**
* If specified, the deploy stage will run in this project subdirectory.
*/
String inDir

/**
* The custom login operation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ class NodeJSVersionStageArguments extends VersionStageArguments {
* with them.
*/
Map<String, String> updateChangelogArgs

/**
* If specified, the version stage will run in this project subdirectory.
*/
String inDir
}

0 comments on commit 55228bb

Please sign in to comment.