|
1 |
| -version: 2.1 |
2 |
| -setup: true |
3 |
| - |
4 |
| -orbs: |
5 |
| - continuation: circleci/[email protected] |
6 |
| - |
7 | 1 | jobs:
|
8 |
| - verify-ci-should-run: |
9 |
| - resource_class: small |
10 |
| - docker: |
11 |
| - - image: cimg/node:current |
12 |
| - steps: |
13 |
| - - run: |
14 |
| - name: Verify CI should run |
15 |
| - command: | |
16 |
| - # run CI when manually triggers via CircleCi Dashboard |
17 |
| - if [ <<pipeline.trigger_source>> == 'api' ]; then |
18 |
| - echo "Always run CI when manually triggered from the UI." |
19 |
| - exit 0 |
20 |
| - fi |
21 |
| -
|
22 |
| - if [[ "$CIRCLE_BRANCH" == "develop" || "$CIRCLE_BRANCH" == "release/"* ]]; then |
23 |
| - echo "Always run CI for develop and for release candidate branches." |
24 |
| - exit 0 |
25 |
| - fi |
26 |
| -
|
27 |
| - LAST_COMMIT_MESSAGE=$(curl --silent "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/commits/${CIRCLE_BRANCH}" | jq '.commit.message') |
28 |
| -
|
29 |
| - if [[ "$LAST_COMMIT_MESSAGE" =~ "run ci" ]]; then |
30 |
| - echo "Always run CI when the commit message includes 'run ci'." |
31 |
| - exit 0 |
32 |
| - fi |
33 |
| -
|
34 |
| - cancel_build () { |
35 |
| - echo "Canceling the CI build..." |
36 |
| - circleci-agent step halt |
37 |
| - } |
38 |
| -
|
39 |
| - TRIGGER_INSTRUCTIONS="to trigger CI , include 'run ci' in the commit message or click the 'Trigger Pipeline' button in the CircleCI UI." |
40 |
| -
|
41 |
| - if [ ! -z "${CIRCLE_PULL_REQUEST##*/}" ]; then |
42 |
| - DRAFT=$(curl --silent "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PULL_REQUEST##*/}" | jq '.draft') |
43 |
| -
|
44 |
| - if [[ "${DRAFT}" == true ]]; then |
45 |
| - echo "Skipping CI; PR is in draft - $TRIGGER_INSTRUCTIONS" |
46 |
| - cancel_build |
47 |
| - fi |
48 |
| -
|
49 |
| - echo "Always run CI for PR that is ready for review." |
50 |
| - exit 0 |
51 |
| - fi |
52 |
| -
|
53 |
| - echo "Skipping CI; branch in progress - $TRIGGER_INSTRUCTIONS" |
54 |
| - cancel_build |
55 |
| - - checkout |
56 |
| - - continuation/continue: |
57 |
| - configuration_path: .circleci/workflows.yml |
58 |
| - |
| 2 | + verify-ci-should-run: |
| 3 | + docker: |
| 4 | + - image: cimg/node:current |
| 5 | + resource_class: small |
| 6 | + steps: |
| 7 | + - run: |
| 8 | + command: | |
| 9 | + # run CI when manually triggers via CircleCi Dashboard |
| 10 | + if [ <<pipeline.trigger_source>> == 'api' ]; then |
| 11 | + echo "Always run CI when manually triggered from the UI." |
| 12 | + exit 0 |
| 13 | + fi |
| 14 | +
|
| 15 | + if [[ "$CIRCLE_BRANCH" == "develop" || "$CIRCLE_BRANCH" == "release/"* ]]; then |
| 16 | + echo "Always run CI for develop and for release candidate branches." |
| 17 | + exit 0 |
| 18 | + fi |
| 19 | +
|
| 20 | + LAST_COMMIT_MESSAGE=$(curl --silent "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/commits/${CIRCLE_BRANCH}" | jq '.commit.message') |
| 21 | +
|
| 22 | + if [[ "$LAST_COMMIT_MESSAGE" =~ "run ci" ]]; then |
| 23 | + echo "Always run CI when the commit message includes 'run ci'." |
| 24 | + exit 0 |
| 25 | + fi |
| 26 | +
|
| 27 | + cancel_build () { |
| 28 | + echo "Canceling the CI build..." |
| 29 | + circleci-agent step halt |
| 30 | + } |
| 31 | +
|
| 32 | + TRIGGER_INSTRUCTIONS="to trigger CI , include 'run ci' in the commit message or click the 'Trigger Pipeline' button in the CircleCI UI." |
| 33 | +
|
| 34 | + if [ ! -z "${CIRCLE_PULL_REQUEST##*/}" ]; then |
| 35 | + DRAFT=$(curl --silent "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PULL_REQUEST##*/}" | jq '.draft') |
| 36 | +
|
| 37 | + if [[ "${DRAFT}" == true ]]; then |
| 38 | + echo "Skipping CI; PR is in draft - $TRIGGER_INSTRUCTIONS" |
| 39 | + cancel_build |
| 40 | + fi |
| 41 | +
|
| 42 | + echo "Always run CI for PR that is ready for review." |
| 43 | + exit 0 |
| 44 | + fi |
| 45 | +
|
| 46 | + echo "Skipping CI; branch in progress - $TRIGGER_INSTRUCTIONS" |
| 47 | + cancel_build |
| 48 | + name: Verify CI should run |
| 49 | + - checkout |
| 50 | + - continuation/continue: |
| 51 | + configuration_path: .circleci/workflows.yml |
| 52 | +orbs: |
| 53 | + continuation: circleci/[email protected] |
| 54 | +setup: true |
| 55 | +version: 2.1 |
59 | 56 | workflows:
|
60 |
| - # the setup-workflow workflow is always triggered. |
61 |
| - setup-workflow: |
62 |
| - jobs: |
63 |
| - - verify-ci-should-run |
| 57 | + setup-workflow: |
| 58 | + jobs: |
| 59 | + - verify-ci-should-run |
| 60 | + |
0 commit comments