Skip to content

GCP Previews #5639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 70 additions & 132 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,135 +1,112 @@
version: 2.1

orbs:
pfe: pantheon-systems/front-end@dev:master
queue: eddiewebb/[email protected]

workflows:
build-preview-test-deploy:
jobs:
- pfe/gatsby-build-and-deploy:
filters:
branches:
ignore: master
use-yarn: false
deployment-path: docs
incremental-build: true
gcp-bucket: "static.pantheonfrontend.website"
gatsby-cache-version: "v1.2"
pre-steps:
- checkout
- run:
name: Import Functions and Variables
command: .circleci/scripts/set-env.sh && source $BASH_ENV
- run:
name: Install PHP
command: sudo apt-get install -y php-cli php-xml
- run:
name: Install Terminus
command: |
php .circleci/scripts/terminus-installer.php
- run:
name: Import Tokens
command: gatsby-tokens
- run:
name: Import External Data
command: .circleci/scripts/import-external-data.sh
- persist_to_workspace:
root: .
paths:
- ./
- test-links:
requires:
- pfe/gatsby-build-and-deploy
- lighthouse:
requires:
- pfe/gatsby-build-and-deploy
filters:
branches:
ignore: master
- deploy:
requires:
- test-links
filters:
branches:
only: master

jobs:
build:
test-links:
docker:
- image: circleci/php:7.2-cli-node
- image: circleci/php:7.2-cli-node-browsers
environment:
BUILD_PATH: /home/circleci/build
working_directory: ~/build
BUILD_PATH: /home/circleci/project
working_directory: ~/project
steps:
- pfe/set-terminus-env
- checkout
- run:
name: Import Functions and Variables
command: .circleci/scripts/set-env.sh && source $BASH_ENV
- restore_cache:
keys:
- v2.5.9-always-
- restore_cache:
keys:
- npm-v2.8.4-
- run:
name: Install Terminus
command: |
php .circleci/scripts/terminus-installer.php
- run:
name: Install Gatsby
command: |
npm install -E
- run:
name: Import Gatsby Tokens
command: gatsby-tokens
- run:
name: Update external data files
command: |
bash .circleci/scripts/import-external-data.sh
- run:
name: Gatsby Build
command: |
npm run-script build
- run:
name: Remove empty directories
command: |
find ~/build/public -type d -empty -delete
name: Install Broken Link Checker
command: sudo npm install -g alexlouden/broken-link-checker
- run:
name: Check for merge conflicts
command: .circleci/scripts/merge_conflicts.sh
- persist_to_workspace:
root: .
paths:
- ./

test:
docker:
- image: circleci/php:7.2-cli-node-browsers
environment:
BUILD_PATH: /home/circleci/build
working_directory: ~/build
steps:
- attach_workspace:
at: .
- run:
name: Import Functions and Variables
command: .circleci/scripts/set-env.sh && source $BASH_ENV
- run:
name: Serve Gatsby
command: |
./node_modules/gatsby/node_modules/.bin/gatsby serve --prefix-paths
background: true
- run:
name: Wait...
command: |
dockerize -wait tcp://localhost:9000
- run:
name: Test links
command: .circleci/tests/link-checker.sh
command: .circleci/tests/link-checker.sh "https://${TERMINUS_ENV}--${TERMINUS_SITE}.my.pantheonfrontend.website/docs"
- save_cache:
key: npm-v2.8.4-{{ checksum "package-lock.json" }}
paths:
- ~/build/node_modules

preview:
docker:
- image: circleci/php:7.2-cli-node
environment:
BUILD_PATH: /home/circleci/build
working_directory: ~/build
steps:
- attach_workspace:
at: .
- run:
name: Import Functions and Variables
command: .circleci/scripts/set-env.sh && source $BASH_ENV
- run:
name: Install rsync
command: sudo apt-get update && sudo apt-get install -y rsync
- run:
name: Install Terminus
command: php .circleci/scripts/terminus-installer.php
- run:
name: Deploy Multidev environment
command: bash .circleci/scripts/deploy-multidev.sh
no_output_timeout: 15m
- store_artifacts:
path: multidev-log.txt
destination: multidev-log.txt

lighthouse:
docker:
- image: circleci/php:7.2-cli-node-browsers
environment:
BUILD_PATH: /home/circleci/build
working_directory: ~/build/
BUILD_PATH: /home/circleci/project
working_directory: ~/project
steps:
- attach_workspace:
at: .
- pfe/set-terminus-env
- run:
name: Import Functions and Variables
command: .circleci/scripts/set-env.sh && source $BASH_ENV
- run:
name: Lighthouse Audit
command: .circleci/tests/lighthouse/run
command: npm ci && .circleci/tests/lighthouse/run
- store_artifacts:
path: lighthouse_data/
destination: lighthouse_data/

deploy:
docker:
- image: circleci/php:7.2-cli-node
- image: circleci/php:7.2-cli
environment:
BUILD_PATH: /home/circleci/build
working_directory: ~/build
BUILD_PATH: /home/circleci/project
working_directory: ~/project
steps:
- queue/until_front_of_line:
time: '15'
Expand All @@ -152,45 +129,6 @@ jobs:
.circleci/scripts/deploy-live.sh
fi
no_output_timeout: 15m
- save_cache:
key: v2.5.9-always-{{ epoch }}
paths:
- ~/build/public
- ~/build/.cache
- store_artifacts:
path: deployment-log.txt
destination: deployment-log.txt

workflows:
version: 2.1
build-test-preview-and-deploy:
jobs:
- build
- test:
requires:
- build
- preview:
filters:
branches:
ignore: master
requires:
- build
- lighthouse:
filters:
branches:
ignore: master
requires:
- preview
- deploy:
filters:
branches:
only: master
requires:
- test

# Below is CircleCI 1.0 Config Syntax that is still supported on CircleCI 2.0
experimental:
notify:
branches:
only:
- master
path: deployment-log.txt
destination: deployment-log.txt
6 changes: 3 additions & 3 deletions .circleci/scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ protected-branches() {

gatsby-tokens() {
# Set GitHub API token
touch $BUILD_PATH/.env.production
echo "GITHUB_API=$GITHUB_TOKEN" > $BUILD_PATH/.env.production
echo "SEGMENT_KEY=$SEGMENT_KEY" >> $BUILD_PATH/.env.production
touch .env.production
echo "GITHUB_API=$GITHUB_TOKEN" > .env.production
echo "SEGMENT_KEY=$SEGMENT_KEY" >> .env.production
echo "GTM_ID=$GTM_ID" >> .env.production
}

Expand Down
25 changes: 13 additions & 12 deletions .circleci/scripts/import-external-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,37 @@ cd $BUILD_PATH

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

echo "Ajusting output..."
sed -i 's/site_env/site>\.<env/g' source/data/commands.json
sed -i 's/drush_command/command/g' source/data/commands.json
sed -i 's/wp_command/command/g' source/data/commands.json
sed -i 's/site_env/site>\.<env/g' ~/project/source/data/commands.json
sed -i 's/drush_command/command/g' ~/project/source/data/commands.json
sed -i 's/wp_command/command/g' ~/project/source/data/commands.json

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


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

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

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

echo "Convert local Issue and Pull references to Markdown links"
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
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
echo "Convert local commit refs to links"
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
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


## Import Build Tools Releases
echo "Downloading Build Tools Changelog"
curl -v -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/pantheon-systems/terminus-build-tools-plugin/releases > source/data/buildToolsReleases.json
curl -v -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/pantheon-systems/terminus-build-tools-plugin/releases > ~/project/source/data/buildToolsReleases.json
echo "Convert local Issue and Pull references to Markdown links"
sed -i -E "s/(#)([0-9]{3})/\[#\2\]\(https:\/\/github.com\/pantheon-systems\/terminus-build-tools-plugin\/issues\/\2)/g" ./source/data/buildToolsReleases.json
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
3 changes: 2 additions & 1 deletion .circleci/scripts/set-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fi


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

# Export functions
echo "source $BUILD_PATH/.circleci/scripts/functions.sh" >> $BASH_ENV
echo "source .circleci/scripts/functions.sh" >> $BASH_ENV
16 changes: 10 additions & 6 deletions .circleci/tests/link-checker.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#! /bin/bash
set -e

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

set -e

echo "Checking for broken links.."
# Exits if no target is provided as an argument.
if [ "$1" = "" ]; then
echo "You forgot to provide a target."
exit 1
fi

cd $BUILD_PATH
echo "Checking for broken links on ${1} .."

if ./node_modules/broken-link-checker/bin/blc -q -r -e -o http://localhost:9000/docs
if blc -q -r -e -o $1
then
echo "No broken internal links!"
else
exit 1
fi

Loading