Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
pantheon: pantheon-systems/pantheon@0.7.1
Use pantheon
elements in your existing workflows and jobs.
Opt-in to use of uncertified orbs on your organization’s Security settings page.
The simplest example of using this Orb.
1
2
3
4
5
6
7
8
version: 2.1
workflows:
version: 2
just_push:
jobs:
- pantheon/push
orbs:
pantheon: pantheon-systems/pantheon@0.2.0
Compile Sass in a separate job before pushing to Pantheon. Also run tests. See this example in use at https://github.com/kporras07/circleci-orb-demo
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
version: 2.1
workflows:
version: 2
build_deploy_and_test:
jobs:
- pantheon/static_tests
- npmbuild_and_persist
- pantheon/push:
requires:
- npmbuild_and_persist
- pantheon/static_tests
checkout: false
pre-steps:
- checkout
- attach_workspace:
at: .
- run: rm web/themes/custom/default/.gitignore
- run: ./.ci/build/php
- pantheon/visual_regression:
requires:
- pantheon/push
filters:
branches:
ignore:
- master
- pantheon/behat_tests:
requires:
- pantheon/visual_regression
scheduled_update_check:
triggers:
- schedule:
cron: 10 21 * * *
filters:
branches:
only:
- master
jobs:
- pantheon/composer_lock_updater
orbs:
pantheon: pantheon-systems/pantheon@0.2.0
jobs:
npmbuild_and_persist:
docker:
- image: node:12.16.1
steps:
- checkout
- run:
name: install npm dependencies in a custom Drupal child theme
command: cd web/themes/custom/default && yarn install
- run:
name: Compile Sass
command: >-
cd web/themes/custom/default && yarn production && rm -rf
web/themes/custom/default/node_modules
- persist_to_workspace:
root: .
paths:
- web/themes/custom/default
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
resource_class | Override the resource class used by the job | No | medium | string |
checkout | Should this job checkout your repository as the first step? Set to false if you are calling 'checkout' in 'pre-steps' | No | true | boolean |
set_env_vars | Should this job run a script to set env vars like TERMINUS_ENV? Set to false if you set variables in 'pre-steps' | No | true | boolean |
static_tests_script | Script to run static tests | No | ./.ci/test/static/run | string |
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
resource_class | Override the resource class used by the job | No | medium | string |
directory_to_push | The directory within the repository to push to Pantheon. Defaults to the git root: '.' Use this setting if you have a more complex repo structure that puts your Pantheon root in a deeper directory. For instance, if you are using a monorepo to manage a backend CMS on Pantheon and a decoupled frontend deployed elsewhere, set this param to the name of the directory that holds your `pantheon.yml` file. | No | . | string |
checkout | Should this job checkout your repository as the first step? Set to false if you are calling 'checkout' in 'pre-steps' | No | true | boolean |
set_env_vars | Should this job run a script to set env vars like TERMINUS_ENV? Set to false if you set variables in 'pre-steps' | No | true | boolean |
env_create_max_time | The maximum amount of time to wait for Pantheon environment creation (terminus -n build:env:create). This parameter maps to CircleCI's native 'no_output_timeout' option. | No | 10m | string |
terminus_clone_env | The source environment from which the database and uploaded files are cloned. | No | dev | string |
clone_content | Determines whether or not every build will re-clone content from the environment set in terminus_clone_env. Set to false if cloning the database and files means builds are taking too long. | No | true | boolean |
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
resource_class | Override the resource class used by the job | No | medium | string |
checkout | Should this job checkout your repository as the first step? Set to false if you are calling 'checkout' in 'pre-steps' | No | true | boolean |
set_env_vars | Should this job run a script to set env vars like TERMINUS_ENV? Set to false if you set variables in 'pre-steps' | No | true | boolean |
vrt_run_script | Script to run vrt | No | ./.ci/test/visual-regression/run | string |
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
resource_class | Override the resource class used by the job | No | medium | string |
checkout | Should this job checkout your repository as the first step? Set to false if you are calling 'checkout' in 'pre-steps' | No | true | boolean |
set_env_vars | Should this job run a script to set env vars like TERMINUS_ENV? Set to false if you set variables in 'pre-steps' | No | true | boolean |
behat_initialize_script | Script to initialize behat tests | No | ./.ci/test/behat/initialize | string |
behat_run_script | Script to run behat tests | No | ./.ci/test/behat/run | string |
behat_clean_script | Script to clean behat tests | No | ./.ci/test/behat/cleanup | string |
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
resource_class | Override the resource class used by the job | No | medium | string |
checkout | Should this job checkout your repository as the first step? Set to false if you are calling 'checkout' in 'pre-steps' | No | true | boolean |
set_env_vars | Should this job run a script to set env vars like TERMINUS_ENV? Set to false if you set variables in 'pre-steps' | No | true | boolean |
Default executor to use when running this orb's jobs
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
resource_class | - | No | medium | string |
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
version: 2.1
description: |
Use CircleCI to push code to Pantheon Dev and Multidev Environments and run some tests.
display:
source_url: https://github.com/pantheon-systems/circleci-orb
home_url: https://pantheon.io/
executors:
default:
description: "Default executor to use when running this orb's jobs"
parameters:
resource_class:
type: string
default: "medium"
docker:
- image: quay.io/pantheon-public/build-tools-ci:8.x-php8.1
resource_class: <<parameters.resource_class>>
jobs:
static_tests:
working_directory: ~/sitedir
environment:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
TERM: dumb
parameters:
resource_class:
description: "Override the resource class used by the job"
default: "medium"
type: string
checkout:
description: "Should this job checkout your repository as the first step? Set to false if you are calling 'checkout' in 'pre-steps'"
default: true
type: boolean
set_env_vars:
description: "Should this job run a script to set env vars like TERMINUS_ENV? Set to false if you set variables in 'pre-steps'"
default: true
type: boolean
static_tests_script:
description: "Script to run static tests"
default: "./.ci/test/static/run"
type: string
executor:
name: default
resource_class: <<parameters.resource_class>>
steps:
- when:
condition: <<parameters.checkout>>
steps:
- checkout
- restore_cache:
keys:
- composer-cache-{{ checksum "composer.lock" }}
- composer-cache-
# Set TERMINUS_ENV and related environment variables.
# https://github.com/pantheon-systems/docker-build-tools-ci/blob/6.x/scripts/set-environment
- when:
condition: <<parameters.set_env_vars>>
steps:
- run:
name: Derive environment variables
command: /build-tools-ci/scripts/set-environment
- run:
name: Run static tests
command: << parameters.static_tests_script >>
- save_cache:
key: composer-cache-{{ checksum "composer.lock" }}
paths:
- ~/.composer/cache
push:
working_directory: ~/sitedir
environment:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
TERM: dumb
PANTHEON_REPO_DIR: "/tmp/pantheon_repo"
NOTIFY: 'scripts/github/add-commit-comment {project} {sha} "Created multidev environment [{site}#{env}]({dashboard-url})." {site-url}'
ADMIN_USERNAME: admin
parameters:
resource_class:
description: "Override the resource class used by the job"
default: "medium"
type: string
directory_to_push:
description: "The directory within the repository to push to Pantheon. Defaults to the git root: '.' Use this setting if you have a more complex repo structure that puts your Pantheon root in a deeper directory. For instance, if you are using a monorepo to manage a backend CMS on Pantheon and a decoupled frontend deployed elsewhere, set this param to the name of the directory that holds your `pantheon.yml` file."
default: "."
type: string
checkout:
description: "Should this job checkout your repository as the first step? Set to false if you are calling 'checkout' in 'pre-steps'"
default: true
type: boolean
set_env_vars:
description: "Should this job run a script to set env vars like TERMINUS_ENV? Set to false if you set variables in 'pre-steps'"
default: true
type: boolean
env_create_max_time:
description: "The maximum amount of time to wait for Pantheon environment creation (terminus -n build:env:create). This parameter maps to CircleCI's native 'no_output_timeout' option."
default: "10m"
type: string
terminus_clone_env:
description: "The source environment from which the database and uploaded files are cloned."
default: "dev"
type: string
clone_content:
description: "Determines whether or not every build will re-clone content from the environment set in terminus_clone_env. Set to false if cloning the database and files means builds are taking too long."
default: true
type: boolean
executor:
name: default
resource_class: <<parameters.resource_class>>
steps:
- when:
condition: <<parameters.checkout>>
steps:
- checkout
# Set TERMINUS_ENV and related environment variables.
# https://github.com/pantheon-systems/docker-build-tools-ci/blob/6.x/scripts/set-environment
- when:
condition: <<parameters.set_env_vars>>
steps:
- run:
name: Derive environment variables
command: /build-tools-ci/scripts/set-environment
# Later commands require being signed in to Pantheon.
- run:
name: Authenticate with Pantheon's CLI using a machine token
command: terminus -n auth:login --machine-token="$TERMINUS_TOKEN"
# This section is a convoluted way of ensure that there are not git
# conflicts when pushing to Pantheon.
# Rather than pushing the history from GitHub/BitBucket to Pantheon,
# the Pantheon history is cloned to a tmp directory, changes are copied
# (rsync) to the Pantheon repo to be committed on top of history that can
# then push with no chance of a merge conflict (other than a race
# condition caused by a push going to Pantheon from elsewhere)
- restore_cache:
keys:
- pantheon-repo-{{ .Branch }}
- pantheon-repo-
- run:
name: Checkout site repository from Pantheon
command: |
# Ensure that there's a Pantheon repo locally. If one was not
# restored from cache, clone it fresh.
if [ ! -d "$PANTHEON_REPO_DIR/.git" ]; then
mkdir $PANTHEON_REPO_DIR
cd $PANTHEON_REPO_DIR
git init
git remote add pantheon $(terminus connection:info $TERMINUS_SITE.dev --field=git_url)
# Make the BitBucket or GitHub url be the origin so that Build Tools sets
# that url appropriately in the metadata file.
git remote add origin $CIRCLE_REPOSITORY_URL
git remote -v
fi
git fetch pantheon
# If the current branch is on Pantheon, check it out.
# If it is not, checkout master and then make a new branch.
if git ls-remote pantheon | grep "refs/heads/$TERMINUS_ENV$" > /dev/null; then
git checkout $TERMINUS_ENV
git pull
else
git checkout master
git pull
git checkout -b $TERMINUS_ENV
fi
- save_cache:
key: pantheon-repo-{{ .Branch }}
paths:
- $PANTHEON_REPO_DIR
# terminus build:env:delete can take around a minute.
# So only run it when the current build needs to
# make a new Multidev environment.
- run:
name: Delete old Multidevs if this build needs to create a new one
command: |
if [[ $TERMINUS_ENV = ci-* || $TERMINUS_ENV = pr-* ]]
then
echo "May need to delete old ci- or pr- environments to make room for this one"
echo "Getting list of all environments"
export ENV_LIST=$(terminus env:list $TERMINUS_SITE --field=id)
echo "Checking if current environment is in list of existing environments"
if [[ $(echo "${ENV_LIST}" | grep -x ${TERMINUS_ENV}) ]]
then
echo "${TERMINUS_ENV} found in the list of environments"
exit 0
else
echo "${TERMINUS_ENV} not found in the list of environments."
echo "Running clean-up script to delete old pr- environments"
terminus -n build:env:delete:pr "$TERMINUS_SITE" --yes
if [[ $TERMINUS_ENV = ci-* ]]
then
echo "Running clean-up script to delete old ci- environments"
terminus -n build:env:delete:ci "$TERMINUS_SITE" --keep=2 --yes
else
echo "Skipping deletion of ci- envs"
fi
fi
fi
- run:
name: Copy code to the local clone of the Pantheon repository
command: |
rsync -av --exclude='.git' << parameters.directory_to_push >>/ $PANTHEON_REPO_DIR --delete
# For easier debugging, show what files have changed.
git -C $PANTHEON_REPO_DIR status
- run:
name: Commit code to Pantheon repository and push to Pantheon
no_output_timeout: <<parameters.env_create_max_time>>
command: |
export COMMIT_MSG=$(git log -1 --pretty=%B)
cd $PANTHEON_REPO_DIR
if [ "true" = "<<parameters.clone_content>>" ] ; then
export CLONE_CONTENT="--clone-content"
else
export CLONE_CONTENT=""
fi
if [ ! -z $CI_PULL_REQUEST ] ; then
PR_ID=${CI_PULL_REQUEST##*/}
export PR_ID_ARG="--pr-id=$PR_ID"
else
export PR_ID_ARG=""
fi
# This command will commit any changed files and push to Pantheon.
# New multidevs will be created as necessary.
terminus -n build:env:create "$TERMINUS_SITE.<< parameters.terminus_clone_env >>" "$TERMINUS_ENV" --yes $CLONE_CONTENT --message="CI: $COMMIT_MSG" $PR_ID_ARG --no-git-force
# @todo, Check back with CircleCI DevRel team. They mentioned possibly
# adding a CircleCI-maintained Orb step to do this concept.
- run:
name: Copy environment variables to persist to workspace for use in subsequent jobs.
command: cp $BASH_ENV bash_env.txt
- persist_to_workspace:
root: .
paths:
- bash_env.txt
visual_regression:
docker:
- image: backstopjs/backstopjs:4.1.9
working_directory: ~/sitedir
environment:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
TERM: dumb
parameters:
resource_class:
description: "Override the resource class used by the job"
default: "medium"
type: string
checkout:
description: "Should this job checkout your repository as the first step? Set to false if you are calling 'checkout' in 'pre-steps'"
default: true
type: boolean
set_env_vars:
description: "Should this job run a script to set env vars like TERMINUS_ENV? Set to false if you set variables in 'pre-steps'"
default: true
type: boolean
vrt_run_script:
description: "Script to run vrt"
default: "./.ci/test/visual-regression/run"
type: string
executor:
name: default
resource_class: <<parameters.resource_class>>
steps:
- when:
condition: <<parameters.checkout>>
steps:
- checkout
- attach_workspace:
at: /tmp/workspace
- when:
condition: <<parameters.set_env_vars>>
steps:
- run:
name: Derive environment variables
command: |
cp /tmp/workspace/bash_env.txt $BASH_ENV
echo "export CI_BUILD_URL='${CIRCLE_BUILD_URL}'" >> $BASH_ENV
echo "export CI_NODE_INDEX='${CIRCLE_NODE_INDEX}'" >> $BASH_ENV
echo "export CI_REPOSITORY_URL='${CIRCLE_REPOSITORY_URL}'" >> $BASH_ENV
echo "export ARTIFACTS_DIR_URL='${CIRCLE_BUILD_URL}/artifacts/${CIRCLE_NODE_INDEX}/artifacts'" >> $BASH_ENV
source $BASH_ENV
- run:
name: Run visual regression tests
command: << parameters.vrt_run_script >>
- store_artifacts:
path: /tmp/artifacts
destination: artifacts
behat_tests:
working_directory: ~/sitedir
environment:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
TERM: dumb
parameters:
resource_class:
description: "Override the resource class used by the job"
default: "medium"
type: string
checkout:
description: "Should this job checkout your repository as the first step? Set to false if you are calling 'checkout' in 'pre-steps'"
default: true
type: boolean
set_env_vars:
description: "Should this job run a script to set env vars like TERMINUS_ENV? Set to false if you set variables in 'pre-steps'"
default: true
type: boolean
behat_initialize_script:
description: "Script to initialize behat tests"
default: "./.ci/test/behat/initialize"
type: string
behat_run_script:
description: "Script to run behat tests"
default: "./.ci/test/behat/run"
type: string
behat_clean_script:
description: "Script to clean behat tests"
default: "./.ci/test/behat/cleanup"
type: string
executor:
name: default
resource_class: <<parameters.resource_class>>
steps:
- when:
condition: <<parameters.checkout>>
steps:
- checkout
- restore_cache:
keys:
- composer-cache-{{ checksum "composer.lock" }}
- composer-cache-
# Set TERMINUS_ENV and related environment variables.
# https://github.com/pantheon-systems/docker-build-tools-ci/blob/6.x/scripts/set-environment
- when:
condition: <<parameters.set_env_vars>>
steps:
- run:
name: Derive environment variables
command: /build-tools-ci/scripts/set-environment
- run:
name: Initialize behat tests
command: << parameters.behat_initialize_script >>
- run:
name: Run behat tests
command: << parameters.behat_run_script >>
- run:
name: Cleanup behat tests
command: << parameters.behat_clean_script >>
when: always
- save_cache:
key: composer-cache-{{ checksum "composer.lock" }}
paths:
- ~/.composer/cache
- store_artifacts:
path: /tmp/artifacts
destination: artifacts
composer_lock_updater:
working_directory: ~/sitedir
environment:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
TERM: dumb
parameters:
resource_class:
description: "Override the resource class used by the job"
default: "medium"
type: string
checkout:
description: "Should this job checkout your repository as the first step? Set to false if you are calling 'checkout' in 'pre-steps'"
default: true
type: boolean
set_env_vars:
description: "Should this job run a script to set env vars like TERMINUS_ENV? Set to false if you set variables in 'pre-steps'"
default: true
type: boolean
executor:
name: default
resource_class: <<parameters.resource_class>>
steps:
- when:
condition: <<parameters.checkout>>
steps:
- checkout
# Set TERMINUS_ENV and related environment variables.
# https://github.com/pantheon-systems/docker-build-tools-ci/blob/6.x/scripts/set-environment
- when:
condition: <<parameters.set_env_vars>>
steps:
- run:
name: Derive environment variables
command: /build-tools-ci/scripts/set-environment
- run:
name: Authenticate with Terminus
command: terminus -n auth:login --machine-token="$TERMINUS_TOKEN"
- run:
name: run composer lock updater
command: set -e && terminus project:clu $TERMINUS_SITE
examples:
just_push:
description: |
The simplest example of using this Orb.
usage:
version: 2.1
workflows:
version: 2
just_push:
jobs:
- pantheon/push
orbs:
pantheon: pantheon-systems/pantheon@0.2.0
full_example:
description: |
Compile Sass in a separate job before pushing to Pantheon. Also run tests. See this example in use at https://github.com/kporras07/circleci-orb-demo
usage:
version: 2.1
workflows:
version: 2
build_deploy_and_test:
jobs:
- pantheon/static_tests
- npmbuild_and_persist
- pantheon/push:
# This "requires" section tells CircleCI the order in which
# jobs must be run.
requires:
- npmbuild_and_persist
- pantheon/static_tests
# Because the checkout command is called from pre-steps, it should
# not be run inside the orb-defined steps.
checkout: false
pre-steps:
# Perform a git checkout of the code from GitHub/Bitbucket so that
# custom commands (the rm below) can alter the code before it is
# pushed to Pantheon.
- checkout
# Attach this dist directory created in npmbuild_and_persist
# which contains the compiled css.
- attach_workspace:
at: .
# The dist directory that holds the compiled Sass is git ignored.
# It needs to be committed on Pantheon.
# Removing this .gitignore file makes it available for committing.
# Pantheon's Composer examples use a more complicated
# technique of "cutting" the top level .gitignore
# file so that lines specifying build artifact directories are removed.
# https://github.com/pantheon-systems/example-drops-8-composer/blob/670ae310c601dabbb7b35411ff3e08e4b1fac7a3/composer.json#L67
- run: rm web/themes/custom/default/.gitignore
# Optional: Run a script to build needed stuff if you are not using IC or if you have further needs.
- run: ./.ci/build/php
- pantheon/visual_regression:
requires:
- pantheon/push
filters:
branches:
ignore:
- master
- pantheon/behat_tests:
requires:
- pantheon/visual_regression
scheduled_update_check:
triggers:
- schedule:
cron: "10 21 * * *"
filters:
branches:
only:
- master
jobs:
- pantheon/composer_lock_updater
orbs:
pantheon: pantheon-systems/pantheon@0.2.0
jobs:
# This job compiles Sass and then saves (persists) the directory
# containing the compiled css for reuse in the pantheon/push job.
npmbuild_and_persist:
docker:
- image: node:12.16.1
steps:
- checkout
- run:
name: install npm dependencies in a custom Drupal child theme
command: cd web/themes/custom/default && yarn install
- run:
name: Compile Sass
command: cd web/themes/custom/default && yarn production && rm -rf web/themes/custom/default/node_modules
- persist_to_workspace:
root: .
paths:
- web/themes/custom/default