Skip to content

Commit b3949da

Browse files
eladhaimmeeroslav
andauthored
feat: add allow not run workflow option (#55)
* feat: add allow not run workflow option * fix: Update src/commands/set-shas.yml * Update custom.yml * Update src/scripts/set-shas.sh * Update find-successful-workflow.js * Update find-successful-workflow.js --------- Co-authored-by: Miroslav Jonaš <missing.manual@gmail.com>
1 parent bb4449c commit b3949da

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

src/commands/set-shas.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ parameters:
2525
description: |
2626
By default, only workflows with CircleCI status of "success" will be detected for the main branch.
2727
Enable this option to also detect workflows with CircleCI status of "on_hold" in case your workflow requires manual approvals.
28+
allow-not-run-workflow:
29+
type: boolean
30+
default: false
31+
description: |
32+
By default, only workflows with CircleCI status of "success" will be detected for the main branch.
33+
Enable this option to also detect workflows with CircleCI status of "not_run" in case your workflow requires manual approvals.
2834
skip-branch-filter:
2935
type: boolean
3036
default: false
@@ -39,6 +45,7 @@ steps:
3945
PARAM_ERROR_ON_NO_SUCCESSFUL_WORKFLOW: <<parameters.error-on-no-successful-workflow>>
4046
PARAM_WORKFLOW_NAME: <<parameters.workflow-name>>
4147
PARAM_ALLOW_ON_HOLD: <<parameters.allow-on-hold-workflow>>
48+
PARAM_ALLOW_NOT_RUN: <<parameters.allow-not-run-workflow>>
4249
PARAM_SKIP_BRANCH_FILTER: <<parameters.skip-branch-filter>>
4350
PARAM_SCRIPT: <<include(scripts/find-successful-workflow.js)>>
4451
name: Derives SHAs for base and head for use in `nx affected` commands

src/scripts/find-successful-workflow.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ const branchName = process.argv[3];
77
const mainBranchName = process.env.MAIN_BRANCH_NAME || process.argv[4];
88
const errorOnNoSuccessfulWorkflow = process.argv[5] === '1';
99
const allowOnHoldWorkflow = process.argv[6] === '1';
10-
const skipBranchFilter = process.argv[7] === '1';
11-
const workflowName = process.argv[8];
10+
const allowNotRunWorkflow = process.argv[7] == '1';
11+
const skipBranchFilter = process.argv[8] === '1';
12+
const workflowName = process.argv[9];
1213
const circleToken = process.env.CIRCLE_API_TOKEN;
1314

1415
const [, host, project] = buildUrl.match(/https?:\/\/([^\/]+)\/(.*)\/\d+/);
@@ -139,11 +140,28 @@ function commitExists(commitSha) {
139140

140141
async function isWorkflowSuccessful(pipelineId, workflowName) {
141142
if (!workflowName) {
142-
return getJson(`https://${host}/api/v2/pipeline/${pipelineId}/workflow`)
143-
.then(({ items }) => items.every(item => (item.status === 'success') || (allowOnHoldWorkflow && item.status === 'on_hold')));
143+
return getJson(
144+
`https://${host}/api/v2/pipeline/${pipelineId}/workflow`
145+
).then(({ items }) =>
146+
items.every(
147+
(item) =>
148+
item.status === 'success' ||
149+
(allowOnHoldWorkflow && item.status === 'on_hold') ||
150+
(allowNotRunWorkflow && item.status === 'not_run')
151+
)
152+
);
144153
} else {
145-
return getJson(`https://${host}/api/v2/pipeline/${pipelineId}/workflow`)
146-
.then(({ items }) => items.some(item => ((item.status === 'success') || (allowOnHoldWorkflow && item.status === 'on_hold')) && item.name === workflowName));
154+
return getJson(
155+
`https://${host}/api/v2/pipeline/${pipelineId}/workflow`
156+
).then(({ items }) =>
157+
items.some(
158+
(item) =>
159+
(item.status === 'success' ||
160+
(allowOnHoldWorkflow && item.status === 'on_hold') ||
161+
(allowNotRunWorkflow && item.status === 'not_run')) &&
162+
item.name === workflowName
163+
)
164+
);
147165
}
148166
}
149167

src/scripts/set-shas.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if [ -z "$CIRCLE_BRANCH" ]; then
66
else
77
TARGET_BRANCH=$CIRCLE_BRANCH
88
fi
9-
RESPONSE=$(node index.cjs $CIRCLE_BUILD_URL $TARGET_BRANCH $PARAM_MAIN_BRANCH $PARAM_ERROR_ON_NO_SUCCESSFUL_WORKFLOW $PARAM_ALLOW_ON_HOLD $PARAM_SKIP_BRANCH_FILTER $PARAM_WORKFLOW_NAME)
9+
RESPONSE=$(node index.cjs $CIRCLE_BUILD_URL $TARGET_BRANCH $PARAM_MAIN_BRANCH $PARAM_ERROR_ON_NO_SUCCESSFUL_WORKFLOW $PARAM_ALLOW_ON_HOLD $PARAM_ALLOW_NOT_RUN $PARAM_SKIP_BRANCH_FILTER $PARAM_WORKFLOW_NAME)
1010
echo "$RESPONSE"
1111
BASE_SHA=$(echo "$RESPONSE" | grep 'Commit:' | sed 's/.*Commit: //')
1212
HEAD_SHA=$(git rev-parse HEAD)

0 commit comments

Comments
 (0)