Skip to content

Commit

Permalink
🏗 Use unique filenames to signal graceful halt of CircleCI Jobs (ampp…
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimha authored Apr 7, 2021
1 parent c504bb5 commit 1a999c0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ commands:
at: /tmp
- run:
name: 'Maybe Gracefully Halt'
command: if [[ -f "/tmp/workspace/.CI_GRACEFULLY_HALT" ]]; then echo "Gracefully halting this job."; circleci-agent step halt; fi
command: if ls .CI_GRACEFULLY_HALT_* 1>/dev/null 2>&1; then echo "Gracefully halting this job."; circleci-agent step halt; fi
setup_vm:
steps:
- run:
Expand Down
10 changes: 10 additions & 0 deletions build-system/common/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ function circleciPrMergeCommit() {
return isCircleci ? env('CIRCLECI_MERGE_COMMIT') : '';
}

/**
* Returns an identifier that is unique to each CircleCI job. This is different
* from the workflow ID, which is common across all jobs in a workflow.
* @return {string}
*/
function circleciBuildNumber() {
return isCircleci ? env('CIRCLE_BUILD_NUM') : '';
}

/**
* Returns the repo slug for the ongoing build.
* @return {string}
Expand Down Expand Up @@ -235,6 +244,7 @@ module.exports = {
ciPullRequestBranch,
ciPullRequestSha,
ciPushBranch,
circleciBuildNumber,
circleciPrMergeCommit,
ciRepoSlug,
isCiBuild,
Expand Down
12 changes: 10 additions & 2 deletions build-system/pr-check/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const fs = require('fs');
const {
ciBuildSha,
ciPullRequestSha,
circleciBuildNumber,
isCiBuild,
isCircleciBuild,
} = require('../common/ci');
Expand Down Expand Up @@ -110,13 +111,20 @@ function printChangeSummary() {
}

/**
* Signal to dependent jobs that they should be skipped.
* Signal to dependent jobs that they should be skipped. Uses an identifier that
* corresponds to the current job to eliminate conflicts if a parallel job also
* signals the same thing.
*
* Currently only relevant for CircleCI builds.
*/
function signalGracefulHalt() {
if (isCircleciBuild()) {
fs.closeSync(fs.openSync('/tmp/workspace/.CI_GRACEFULLY_HALT', 'w'));
fs.closeSync(
fs.openSync(
`/tmp/workspace/.CI_GRACEFULLY_HALT_${circleciBuildNumber()}`,
'w'
)
);
}
}

Expand Down

0 comments on commit 1a999c0

Please sign in to comment.