forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.yml
75 lines (62 loc) · 2.91 KB
/
config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
version: 2.1
setup: true
orbs:
continuation: circleci/continuation@0.3.1
jobs:
verify-ci-should-run:
docker:
- image: cimg/node:current
steps:
- run:
name: Verify CI should run
command: |
# run CI when manually triggers via CircleCi Dashboard
if [ <<pipeline.trigger_source>> == 'api' ]; then
echo "Always run CI when manually triggered from the UI."
exit 0
fi
if [[ "$CIRCLE_BRANCH" == "develop" || "$CIRCLE_BRANCH" == "release/"* ]]; then
echo "Always run CI for develop and for release candidate branches."
exit 0
fi
LAST_COMMIT_MESSAGE=$(curl --silent "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/commits/${CIRCLE_BRANCH}" | jq '.commit.message')
if [[ "$LAST_COMMIT_MESSAGE" =~ "run ci" ]]; then
echo "Always run CI when the commit message includes 'run ci'."
exit 0
fi
cancel_build () {
echo "Canceling the CI build..."
curl --request POST \
--url https://circleci.com/api/v2/workflow/$CIRCLE_WORKFLOW_ID/cancel \
--header "Circle-Token: ${CIRCLE_TOKEN}"
sleep 30 # Give cancellation a chance to run. This script then won't continue running.
exit 1 # If cancellation didn't run for some reason, fail the build.
}
TRIGGER_INSTRUCTIONS="to trigger CI , include 'run ci' in the commit message or click the 'Trigger Pipeline' button in the CircleCI UI."
if [ ! -z "${CIRCLE_PULL_REQUEST##*/}" ]; then
DRAFT=$(curl --silent "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PULL_REQUEST##*/}" | jq '.draft')
if [[ "${DRAFT}" == true ]]; then
echo "Skipping CI; PR is in draft - $TRIGGER_INSTRUCTIONS"
cancel_build
fi
echo "Always run CI for PR that is ready for review."
exit 0
fi
echo "Skipping CI; branch in progress - $TRIGGER_INSTRUCTIONS"
cancel_build
- run:
name: Download .circleci/workflows.yaml
command: |
if [[ "$CIRCLE_BRANCH" == "pull/"* ]]; then
curl -o workflows.yml https://raw.githubusercontent.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/develop/.circleci/workflows.yml
else
curl -o workflows.yml https://raw.githubusercontent.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/${CIRCLE_BRANCH}/.circleci/workflows.yml
fi
- continuation/continue:
configuration_path: workflows.yml
workflows:
# the setup-workflow workflow is always triggered.
setup-workflow:
jobs:
- verify-ci-should-run:
context: workflow-setup