-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathconfig.yml
More file actions
164 lines (153 loc) · 5.1 KB
/
config.yml
File metadata and controls
164 lines (153 loc) · 5.1 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
orbs:
continuation: circleci/continuation@1.1.0
circleci-cli: circleci/circleci-cli@0.1.9
setup: true
version: 2.1
workflows:
setup-workflow:
jobs:
- pack-workflows
- launch-primary-workflow:
requires:
- pack-workflows
parameters:
publish-binary-branch:
type: string
default: main
force-persist-artifacts:
type: boolean
default: false
commands:
persist:
steps:
- persist_to_workspace:
root: .
paths:
- .circleci/packed
persist-to-workspace-and-exit-early:
steps:
- run:
name: Check cache status and exit early if needed
command: |
if [[ -d ".circleci/packed" ]] && [[ "$(ls -A .circleci/packed 2>/dev/null)" ]]; then
echo "📦 Cache hit - packed configurations exist"
echo "✅ Persisting packed configurations to workspace and halting job"
echo "CACHE_HIT=true" >> $BASH_ENV
else
echo "📦 Cache miss - continuing with packaging"
echo "CACHE_HIT=false" >> $BASH_ENV
mkdir -p .circleci/packed # persist empty dir to workspace
fi
- persist
- run:
name: End job if cache hit
command: |
if [[ "$CACHE_HIT" == "true" ]] && [[ "$(ls -A .circleci/packed 2>/dev/null)" ]]; then
echo "✅ Cache hit - packed configurations exist"
circleci-agent step halt
else
echo "📦 Cache miss - continuing with packaging"
fi
pack-workflows:
steps:
- circleci-cli/install
- run:
name: Pack workflows
command: |
./scripts/pack-ci.sh --all
validate-workflows:
steps:
- run:
name: Validate workflows
command: |
./scripts/pack-ci.sh --validate --pack=false
# Retrieving and saving packed workflows based on the checksum of the hash
# of the yml files in ./.circleci/src
calc-src-checksum:
steps:
- run:
name: Generate config checksum for cache lookup
# this is saved to a file, so that we can use {{ checksum }} - which
# can only operate on the contents of a single file, not a list of
# files or a directory.
command: |
find .circleci/src -name "*.yml" -type f | \
sort | \
xargs cat | \
md5sum | \
cut -d' ' -f1 > /tmp/config_checksum.txt
restore-src-checksum-cache:
steps:
- calc-src-checksum
- restore_cache:
keys:
- circleci-packed-pipelines-{{ checksum "/tmp/config_checksum.txt" }}
paths:
- .circleci/packed
save-src-checksum-cache:
steps:
- calc-src-checksum
- save_cache:
key: circleci-packed-pipelines-{{ checksum "/tmp/config_checksum.txt" }}
paths:
- .circleci/packed
cancel-draft-prs:
steps:
- when:
condition:
not:
or:
- equal: [<<pipeline.trigger_source>>, 'api']
- equal: [<<pipeline.git.branch>>, 'develop']
- matches:
pattern: /^release\/.*/
value: <<pipeline.git.branch>>
steps:
- run:
name: Cancel CI
command: |
cancel_build() {
circleci-agent step halt
}
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 - to trigger CI , click the 'Trigger Pipeline' button in the CircleCI UI."
cancel_build
fi
echo "Always run CI for PR that is ready for review."
exit 0
fi
# otherwise, the build is not a PR so we cancel it
cancel_build
jobs:
pack-workflows:
docker:
- image: cimg/base:stable
resource_class: small
steps:
- cancel-draft-prs
- checkout:
method: blobless
- restore-src-checksum-cache
- persist-to-workspace-and-exit-early
- pack-workflows
- save-src-checksum-cache
- persist
launch-primary-workflow:
docker:
- image: cimg/base:stable
resource_class: small
steps:
- cancel-draft-prs
- attach_workspace:
at: .
- run:
name: Check for primary workflow definition
command: |
if [ ! -f .circleci/packed/pipeline.yml ]; then
echo "❌ Primary workflow definition not found in .circleci/packed/pipeline.yml!"
exit 1
fi
- continuation/continue:
configuration_path: .circleci/packed/pipeline.yml