Skip to content

Commit 7ed4811

Browse files
committedJun 8, 2020
Init use of PFE Orb for preview deployment
1 parent 7e9fabe commit 7ed4811

20 files changed

+9478
-23268
lines changed
 

‎.circleci/config.yml

+70-132
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,112 @@
11
version: 2.1
2+
23
orbs:
4+
pfe: pantheon-systems/front-end@dev:master
35
queue: eddiewebb/queue@1.5.0
6+
7+
workflows:
8+
build-preview-test-deploy:
9+
jobs:
10+
- pfe/gatsby-build-and-deploy:
11+
filters:
12+
branches:
13+
ignore: master
14+
use-yarn: false
15+
deployment-path: docs
16+
incremental-build: true
17+
gcp-bucket: "static.pantheonfrontend.website"
18+
gatsby-cache-version: "v1.2"
19+
pre-steps:
20+
- checkout
21+
- run:
22+
name: Import Functions and Variables
23+
command: .circleci/scripts/set-env.sh && source $BASH_ENV
24+
- run:
25+
name: Install PHP
26+
command: sudo apt-get install -y php-cli php-xml
27+
- run:
28+
name: Install Terminus
29+
command: |
30+
php .circleci/scripts/terminus-installer.php
31+
- run:
32+
name: Import Tokens
33+
command: gatsby-tokens
34+
- run:
35+
name: Import External Data
36+
command: .circleci/scripts/import-external-data.sh
37+
- persist_to_workspace:
38+
root: .
39+
paths:
40+
- ./
41+
- test-links:
42+
requires:
43+
- pfe/gatsby-build-and-deploy
44+
- lighthouse:
45+
requires:
46+
- pfe/gatsby-build-and-deploy
47+
filters:
48+
branches:
49+
ignore: master
50+
- deploy:
51+
requires:
52+
- test-links
53+
filters:
54+
branches:
55+
only: master
56+
457
jobs:
5-
build:
58+
test-links:
659
docker:
7-
- image: circleci/php:7.2-cli-node
60+
- image: circleci/php:7.2-cli-node-browsers
861
environment:
9-
BUILD_PATH: /home/circleci/build
10-
working_directory: ~/build
62+
BUILD_PATH: /home/circleci/project
63+
working_directory: ~/project
1164
steps:
65+
- pfe/set-terminus-env
1266
- checkout
1367
- run:
1468
name: Import Functions and Variables
1569
command: .circleci/scripts/set-env.sh && source $BASH_ENV
16-
- restore_cache:
17-
keys:
18-
- v2.5.9-always-
19-
- restore_cache:
20-
keys:
21-
- npm-v2.8.4-
22-
- run:
23-
name: Install Terminus
24-
command: |
25-
php .circleci/scripts/terminus-installer.php
26-
- run:
27-
name: Install Gatsby
28-
command: |
29-
npm install -E
30-
- run:
31-
name: Import Gatsby Tokens
32-
command: gatsby-tokens
3370
- run:
34-
name: Update external data files
35-
command: |
36-
bash .circleci/scripts/import-external-data.sh
37-
- run:
38-
name: Gatsby Build
39-
command: |
40-
npm run-script build
41-
- run:
42-
name: Remove empty directories
43-
command: |
44-
find ~/build/public -type d -empty -delete
71+
name: Install Broken Link Checker
72+
command: sudo npm install -g alexlouden/broken-link-checker
4573
- run:
4674
name: Check for merge conflicts
4775
command: .circleci/scripts/merge_conflicts.sh
48-
- persist_to_workspace:
49-
root: .
50-
paths:
51-
- ./
52-
53-
test:
54-
docker:
55-
- image: circleci/php:7.2-cli-node-browsers
56-
environment:
57-
BUILD_PATH: /home/circleci/build
58-
working_directory: ~/build
59-
steps:
60-
- attach_workspace:
61-
at: .
62-
- run:
63-
name: Import Functions and Variables
64-
command: .circleci/scripts/set-env.sh && source $BASH_ENV
65-
- run:
66-
name: Serve Gatsby
67-
command: |
68-
./node_modules/gatsby/node_modules/.bin/gatsby serve --prefix-paths
69-
background: true
70-
- run:
71-
name: Wait...
72-
command: |
73-
dockerize -wait tcp://localhost:9000
7476
- run:
7577
name: Test links
76-
command: .circleci/tests/link-checker.sh
78+
command: .circleci/tests/link-checker.sh "https://${TERMINUS_ENV}--${TERMINUS_SITE}.my.pantheonfrontend.website/docs"
7779
- save_cache:
7880
key: npm-v2.8.4-{{ checksum "package-lock.json" }}
7981
paths:
8082
- ~/build/node_modules
8183

82-
preview:
83-
docker:
84-
- image: circleci/php:7.2-cli-node
85-
environment:
86-
BUILD_PATH: /home/circleci/build
87-
working_directory: ~/build
88-
steps:
89-
- attach_workspace:
90-
at: .
91-
- run:
92-
name: Import Functions and Variables
93-
command: .circleci/scripts/set-env.sh && source $BASH_ENV
94-
- run:
95-
name: Install rsync
96-
command: sudo apt-get update && sudo apt-get install -y rsync
97-
- run:
98-
name: Install Terminus
99-
command: php .circleci/scripts/terminus-installer.php
100-
- run:
101-
name: Deploy Multidev environment
102-
command: bash .circleci/scripts/deploy-multidev.sh
103-
no_output_timeout: 15m
104-
- store_artifacts:
105-
path: multidev-log.txt
106-
destination: multidev-log.txt
107-
10884
lighthouse:
10985
docker:
11086
- image: circleci/php:7.2-cli-node-browsers
11187
environment:
112-
BUILD_PATH: /home/circleci/build
113-
working_directory: ~/build/
88+
BUILD_PATH: /home/circleci/project
89+
working_directory: ~/project
11490
steps:
11591
- attach_workspace:
11692
at: .
93+
- pfe/set-terminus-env
11794
- run:
11895
name: Import Functions and Variables
11996
command: .circleci/scripts/set-env.sh && source $BASH_ENV
12097
- run:
12198
name: Lighthouse Audit
122-
command: .circleci/tests/lighthouse/run
99+
command: npm ci && .circleci/tests/lighthouse/run
123100
- store_artifacts:
124101
path: lighthouse_data/
125102
destination: lighthouse_data/
126103

127104
deploy:
128105
docker:
129-
- image: circleci/php:7.2-cli-node
106+
- image: circleci/php:7.2-cli
130107
environment:
131-
BUILD_PATH: /home/circleci/build
132-
working_directory: ~/build
108+
BUILD_PATH: /home/circleci/project
109+
working_directory: ~/project
133110
steps:
134111
- queue/until_front_of_line:
135112
time: '15'
@@ -152,45 +129,6 @@ jobs:
152129
.circleci/scripts/deploy-live.sh
153130
fi
154131
no_output_timeout: 15m
155-
- save_cache:
156-
key: v2.5.9-always-{{ epoch }}
157-
paths:
158-
- ~/build/public
159-
- ~/build/.cache
160132
- store_artifacts:
161-
path: deployment-log.txt
162-
destination: deployment-log.txt
163-
164-
workflows:
165-
version: 2.1
166-
build-test-preview-and-deploy:
167-
jobs:
168-
- build
169-
- test:
170-
requires:
171-
- build
172-
- preview:
173-
filters:
174-
branches:
175-
ignore: master
176-
requires:
177-
- build
178-
- lighthouse:
179-
filters:
180-
branches:
181-
ignore: master
182-
requires:
183-
- preview
184-
- deploy:
185-
filters:
186-
branches:
187-
only: master
188-
requires:
189-
- test
190-
191-
# Below is CircleCI 1.0 Config Syntax that is still supported on CircleCI 2.0
192-
experimental:
193-
notify:
194-
branches:
195-
only:
196-
- master
133+
path: deployment-log.txt
134+
destination: deployment-log.txt

‎.circleci/scripts/functions.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ protected-branches() {
3131

3232
gatsby-tokens() {
3333
# Set GitHub API token
34-
touch $BUILD_PATH/.env.production
35-
echo "GITHUB_API=$GITHUB_TOKEN" > $BUILD_PATH/.env.production
36-
echo "SEGMENT_KEY=$SEGMENT_KEY" >> $BUILD_PATH/.env.production
34+
touch .env.production
35+
echo "GITHUB_API=$GITHUB_TOKEN" > .env.production
36+
echo "SEGMENT_KEY=$SEGMENT_KEY" >> .env.production
3737
echo "GTM_ID=$GTM_ID" >> .env.production
3838
}
3939

‎.circleci/scripts/import-external-data.sh

+13-12
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,37 @@ cd $BUILD_PATH
88

99
## Import Terminus releases and command reference
1010
echo "Generate a new Terminus commands.json file"
11-
terminus list --format=json > source/data/commands.json
11+
touch ~/project/source/data/commands.json
12+
terminus list --format=json > ~/project/source/data/commands.json
1213

1314
echo "Ajusting output..."
14-
sed -i 's/site_env/site>\.<env/g' source/data/commands.json
15-
sed -i 's/drush_command/command/g' source/data/commands.json
16-
sed -i 's/wp_command/command/g' source/data/commands.json
15+
sed -i 's/site_env/site>\.<env/g' ~/project/source/data/commands.json
16+
sed -i 's/drush_command/command/g' ~/project/source/data/commands.json
17+
sed -i 's/wp_command/command/g' ~/project/source/data/commands.json
1718

1819
echo "Update Terminus releases"
19-
curl -v -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/pantheon-systems/terminus/releases > source/data/terminusReleases.json
20+
curl -v -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/pantheon-systems/terminus/releases > ~/project/source/data/terminusReleases.json
2021

2122

2223
## Import Localdev releases
2324
echo "Downloading Localdev changelog..."
24-
wget -O ./source/data/localdev/changelog.yml https://pantheon-localdev.s3.amazonaws.com/changelog.yml
25+
wget -O ~/project/source/data/localdev/changelog.yml https://pantheon-localdev.s3.amazonaws.com/changelog.yml
2526

2627
echo "Apply markdown callout"
27-
sed -i -e 's/|/!markdown |/g' source/data/localdev/changelog.yml
28+
sed -i -e 's/|/!markdown |/g' ~/project/source/data/localdev/changelog.yml
2829

2930
## Import Drush releases
3031
echo "Downloading Localdev changelog..."
31-
curl -v -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/drush-ops/drush/releases -o ./source/data/drushReleases.json
32+
curl -v -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/drush-ops/drush/releases -o ~/project/source/data/drushReleases.json
3233

3334
echo "Convert local Issue and Pull references to Markdown links"
34-
sed -i -E "s/(#)([0-9][0-9][0-9][0-9])/\[#\2\]\(https:\/\/github.com\/drush-ops\/drush\/issues\/\2)/g" ./source/data/drushReleases.json
35+
sed -i -E "s/(#)([0-9][0-9][0-9][0-9])/\[#\2\]\(https:\/\/github.com\/drush-ops\/drush\/issues\/\2)/g" ~/project/source/data/drushReleases.json
3536
echo "Convert local commit refs to links"
36-
sed -i -E "s/\ ([a-fA-F0-9]{7})([^0-9,])/\ \[\1\]\(https:\/\/github.com\/drush-ops\/drush\/commit\/\1\)\2/g" ./source/data/drushReleases.json
37+
sed -i -E "s/\ ([a-fA-F0-9]{7})([^0-9,])/\ \[\1\]\(https:\/\/github.com\/drush-ops\/drush\/commit\/\1\)\2/g" ~/project/source/data/drushReleases.json
3738

3839

3940
## Import Build Tools Releases
4041
echo "Downloading Build Tools Changelog"
41-
curl -v -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/pantheon-systems/terminus-build-tools-plugin/releases > source/data/buildToolsReleases.json
42+
curl -v -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/pantheon-systems/terminus-build-tools-plugin/releases > ~/project/source/data/buildToolsReleases.json
4243
echo "Convert local Issue and Pull references to Markdown links"
43-
sed -i -E "s/(#)([0-9]{3})/\[#\2\]\(https:\/\/github.com\/pantheon-systems\/terminus-build-tools-plugin\/issues\/\2)/g" ./source/data/buildToolsReleases.json
44+
sed -i -E "s/(#)([0-9]{3})/\[#\2\]\(https:\/\/github.com\/pantheon-systems\/terminus-build-tools-plugin\/issues\/\2)/g" ~/project/source/data/buildToolsReleases.json

‎.circleci/scripts/set-env.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fi
2727

2828

2929
# Export Variables
30+
echo "export BUILD_PATH='/home/circleci/project"
3031
echo "export MULTIDEV_NAME=$MULTIDEV_NAME" >> $BASH_ENV
3132
echo "export MULTIDEV_SITE_URL='https://${MULTIDEV_NAME}-docs-preview.pantheonsite.io/docs/'" >> $BASH_ENV
3233
echo "export CI_BUILD_URL='${CIRCLE_BUILD_URL}'" >> $BASH_ENV
@@ -39,4 +40,4 @@ echo "export ARTIFACTS_DIR_URL='${CIRCLE_BUILD_URL}/artifacts/${CIRCLE_NODE_INDE
3940
echo "export ARTIFACTS_FULL_DIR='${BUILD_PATH}/artifacts'" >> $BASH_ENV
4041

4142
# Export functions
42-
echo "source $BUILD_PATH/.circleci/scripts/functions.sh" >> $BASH_ENV
43+
echo "source .circleci/scripts/functions.sh" >> $BASH_ENV

‎.circleci/tests/link-checker.sh

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
#! /bin/bash
2-
set -e
32

4-
# This script assumes you're already serving the site using --prefix-paths
3+
# This script takes as an argument a target URL to test, then checks recursively for broken (relative) links.
4+
5+
set -e
56

6-
echo "Checking for broken links.."
7+
# Exits if no target is provided as an argument.
8+
if [ "$1" = "" ]; then
9+
echo "You forgot to provide a target."
10+
exit 1
11+
fi
712

8-
cd $BUILD_PATH
13+
echo "Checking for broken links on ${1} .."
914

10-
if ./node_modules/broken-link-checker/bin/blc -q -r -e -o http://localhost:9000/docs
15+
if blc -q -r -e -o $1
1116
then
1217
echo "No broken internal links!"
1318
else
1419
exit 1
1520
fi
16-

0 commit comments

Comments
 (0)
Please sign in to comment.