Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add allow not run workflow option #55

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/commands/set-shas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ parameters:
description: |
By default, only workflows with CircleCI status of "success" will be detected for the main branch.
Enable this option to also detect workflows with CircleCI status of "on_hold" in case your workflow requires manual approvals.
allow-not-run-workflow:
type: boolean
default: false
description: |
By default, only workflows with CircleCI status of "success" will be detected for the main branch.
Enable this option to also detect workflows with CircleCI status of "not_run" in case your workflow requires manual approvals.
skip-branch-filter:
type: boolean
default: false
Expand All @@ -39,6 +45,7 @@ steps:
PARAM_ERROR_ON_NO_SUCCESSFUL_WORKFLOW: <<parameters.error-on-no-successful-workflow>>
PARAM_WORKFLOW_NAME: <<parameters.workflow-name>>
PARAM_ALLOW_ON_HOLD: <<parameters.allow-on-hold-workflow>>
PARMA_ALLOW_NOT_RUN: <<parameters.allow-not-run-workflow>>
PARAM_SKIP_BRANCH_FILTER: <<parameters.skip-branch-filter>>
PARAM_SCRIPT: <<include(scripts/find-successful-workflow.js)>>
name: Derives SHAs for base and head for use in `nx affected` commands
Expand Down
2 changes: 1 addition & 1 deletion src/examples/custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: >
usage:
version: 2.1
orbs:
nx: nrwl/nx@1.6.2
nx: nrwl/nx@1.7.2
jobs:
build:
docker:
Expand Down
2 changes: 1 addition & 1 deletion src/examples/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: >
usage:
version: 2.1
orbs:
nx: nrwl/nx@1.6.2
nx: nrwl/nx@1.7.2
jobs:
build:
docker:
Expand Down
2 changes: 1 addition & 1 deletion src/examples/private.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ description: >
usage:
version: 2.1
orbs:
nx: nrwl/nx@1.6.2
nx: nrwl/nx@1.7.2
2 changes: 1 addition & 1 deletion src/examples/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: >
usage:
version: 2.1
orbs:
nx: nrwl/nx@1.6.1
nx: nrwl/nx@1.7.2
jobs:
build:
docker:
Expand Down
26 changes: 22 additions & 4 deletions src/scripts/find-successful-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const errorOnNoSuccessfulWorkflow = process.argv[5] === '1';
const allowOnHoldWorkflow = process.argv[6] === '1';
const skipBranchFilter = process.argv[7] === '1';
const workflowName = process.argv[8];
const allowNotRunWorkflow = process.argv[9] == '1';
const circleToken = process.env.CIRCLE_API_TOKEN;

const [, host, project] = buildUrl.match(/https?:\/\/([^\/]+)\/(.*)\/\d+/);
Expand Down Expand Up @@ -108,11 +109,28 @@ function commitExists(commitSha) {

async function isWorkflowSuccessful(pipelineId, workflowName) {
if (!workflowName) {
return getJson(`https://${host}/api/v2/pipeline/${pipelineId}/workflow`)
.then(({ items }) => items.every(item => (item.status === 'success') || (allowOnHoldWorkflow && item.status === 'on_hold')));
return getJson(
`https://${host}/api/v2/pipeline/${pipelineId}/workflow`
).then(({ items }) =>
items.every(
(item) =>
item.status === "success" ||
(allowOnHoldWorkflow && item.status === "on_hold") ||
(allowNotRunWorkflow && item.status === "not_run")
)
);
} else {
return getJson(`https://${host}/api/v2/pipeline/${pipelineId}/workflow`)
.then(({ items }) => items.some(item => ((item.status === 'success') || (allowOnHoldWorkflow && item.status === 'on_hold')) && item.name === workflowName));
return getJson(
`https://${host}/api/v2/pipeline/${pipelineId}/workflow`
).then(({ items }) =>
items.some(
(item) =>
(item.status === "success" ||
(allowOnHoldWorkflow && item.status === "on_hold") ||
(allowNotRunWorkflow && item.status === "not_run")) &&
item.name === workflowName
)
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/scripts/set-shas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ -z "$CIRCLE_BRANCH" ]; then
else
TARGET_BRANCH=$CIRCLE_BRANCH
fi
RESPONSE=$(node index.js $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)
RESPONSE=$(node index.js $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 $PARMA_ALLOW_NOT_RUN)
echo "$RESPONSE"
BASE_SHA=$(echo "$RESPONSE" | grep 'Commit:' | sed 's/.*Commit: //')
HEAD_SHA=$(git rev-parse HEAD)
Expand Down