Skip to content

Commit

Permalink
CircleCI 2.0 tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson authored and Pantheon Automation committed Dec 14, 2022
1 parent 4f7b51f commit 6b05c97
Show file tree
Hide file tree
Showing 15 changed files with 562 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .circleci/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
local.test
local.env
local.ssh
17 changes: 17 additions & 0 deletions .circleci/behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# behat.yml
default:
suites:
default:
paths:
- features
contexts:
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- FeatureContext
extensions:
Behat\MinkExtension:
# base_url set by ENV
goutte: ~
Drupal\DrupalExtension:
blackbox: ~
api_driver: 'drush'
33 changes: 33 additions & 0 deletions .circleci/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Echo commands as they are executed, but don't allow errors to stop the script.
set -x

if [ -z "$TERMINUS_SITE" ] || [ -z "$TERMINUS_ENV" ]; then
echo "TERMINUS_SITE and TERMINUS_ENV environment variables must be set"
exit 1
fi

# Only delete old environments if there is a pattern defined to
# match environments eligible for deletion. Otherwise, delete the
# current multidev environment immediately.
#
# To use this feature, set MULTIDEV_DELETE_PATTERN to '^ci-' or similar
# in the CI server environment variables.
if [ -z "$MULTIDEV_DELETE_PATTERN" ] ; then
terminus env:delete $TERMINUS_SITE.$TERMINUS_ENV --delete-branch --yes
exit 0
fi

# List all but the newest two environments.
OLDEST_ENVIRONMENTS=$(terminus env:list "$TERMINUS_SITE" --format=list | grep -v dev | grep -v test | grep -v live | sort -k2 | grep "$MULTIDEV_DELETE_PATTERN" | sed -e '$d' | sed -e '$d')

# Exit if there are no environments to delete
if [ -z "$OLDEST_ENVIRONMENTS" ] ; then
exit 0
fi

# Go ahead and delete the oldest environments.
for ENV_TO_DELETE in $OLDEST_ENVIRONMENTS ; do
terminus env:delete $TERMINUS_SITE.$ENV_TO_DELETE --delete-branch --yes
done
58 changes: 58 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
test-defaults: &test-defaults
docker:
- image: quay.io/pantheon-public/build-tools-ci:2.x
working_directory: ~/work/d7
environment:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
TERM: dumb

merge-defaults: &merge-defaults
docker:
- image: quay.io/getpantheon/upstream-update-build:1.x
working_directory: ~/work/d7
environment:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
TERM: dumb

version: 2
jobs:
test:
<<: *test-defaults
steps:
- checkout
- run:
name: Set up environment
command: ./.circleci/set-up-globals.sh
- run:
name: Prepare
command: ./.circleci/prepare.sh
- run:
name: Test
command: ./.circleci/test.sh --strict
- run:
name: Cleanup
command: ./.circleci/cleanup.sh
- run:
name: Confirm that it is safe to merge
command: ./.circleci/confirm-safety.sh
merge:
<<: *merge-defaults
steps:
- checkout
- run:
# https://github.com/pantheon-systems/upstream-update-build/blob/1.x/bin/automerge.sh
name: Merge the default branch back to the master branch
command: automerge.sh

workflows:
version: 2
drops7:
jobs:
- test
- merge:
requires:
- test
filters:
branches:
only:
- default
48 changes: 48 additions & 0 deletions .circleci/confirm-safety.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

#
# The purpose of this script is to examine the base branch that this PR is
# set to merge into by usig the GitHub API. We are only querying a public
# repo here, so we do not need to use the GITHUB_TOKEN.
#

# Exit if we are not running on Circle CI.
if [ -z "$CIRCLECI" ] ; then
exit 0
fi

# We only need to make this check for branches forked from default (right) / master (wrong).
# Skip the test for the default branch. (The .circleci directory will never be added to the master branch).
if [ "$CIRCLE_BRANCH" == "default" ] ; then
exit 0
fi

# We cannot continue unless we have a pull request.
if [ -z "$CIRCLE_PULL_REQUEST" ] ; then
echo "No CIRCLE_PULL_REQUEST defined; please create a pull request."
exit 1
fi

# CIRCLE_PULL_REQUEST=https://github.com/ORG/PROJECT/pull/NUMBER
PR_NUMBER=$(echo $CIRCLE_PULL_REQUEST | sed -e 's#.*/pull/##')

# Display the API call we are using
echo curl https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pulls/$PR_NUMBER

base=$(curl https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pulls/$PR_NUMBER 2>/dev/null | jq .base.ref)

echo "The base branch is $base"

# If the PR merges into 'default', then it is safe to merge.
if [ "$base" == '"default"' ] ; then
echo "It is safe to merge this PR into the $base branch"
exit 0
fi

# Force a test failure if the PR's base is the master branch.
if [ "$base" == '"master"' ] ; then
echo "ERROR: merging this PR into the $base branch is not allowed. Change the base branch for the PR to merge into the \"default\" branch instead."
exit 1
fi

echo "Merging probably okay, if you are merging one PR into another. Use caution; do not merge to the \"master\" branch."
10 changes: 10 additions & 0 deletions .circleci/features/0-install.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: Installer
In order to know that we can install the site via drush
As a website user
I need to be able to install a Drupal site

Scenario: Installer is ready
Given I have wiped the site
And I have reinstalled "CI Drops-7 [{site-name}.{env}]"
And I visit "/"
Then I should see "Welcome to CI Drops-7"
Loading

0 comments on commit 6b05c97

Please sign in to comment.