Skip to content

Commit

Permalink
🏗 Clean up CircleCI config, move some setup steps into separate files (…
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimha committed Jan 25, 2021
1 parent 11d16c9 commit 6c62105
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 22 deletions.
20 changes: 4 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ commands:
- checkout
- run:
name: 'Fetch Merge Commit'
command: |
./.circleci/fetch_merge_commit.sh
command: ./.circleci/fetch_merge_commit.sh
- browser-tools/install-chrome:
replace-existing: true
- run:
Expand All @@ -41,25 +40,14 @@ commands:
curl -Ss --retry 5 https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-323.0.0-linux-x86_64.tar.gz | tar xz
echo 'source ~/google-cloud-sdk/path.bash.inc' >> $BASH_ENV
- run:
# TODO(rsimha, ampproject/amp-github-apps#1110): Update storage details.
name: 'Setup Storage'
command: |
openssl aes-256-cbc -k $GCP_TOKEN -in build-system/common/sa-travis-key.json.enc -out sa-travis-key.json -d
gcloud auth activate-service-account --key-file=sa-travis-key.json
gcloud config set account sa-travis@amp-travis-build-storage.iam.gserviceaccount.com
gcloud config set pass_credentials_to_gsutil true
gcloud config set project amp-travis-build-storage
command: ./.circleci/setup-storage.sh
- run:
name: 'Configure Hosts'
command: |
echo "127.0.0.1 ads.localhost" | sudo tee -a /etc/hosts
echo "127.0.0.1 iframe.localhost" | sudo tee -a /etc/hosts
echo "127.0.0.1 jgla3zmib2ggq5buc4hwi5taloh6jlvzukddfr4zltz3vay5s5rq.recaptcha.localhost" | sudo tee -a /etc/hosts
echo "127.0.0.1 fonts.googleapis.com" | sudo tee -a /etc/hosts
command: cat ./build-system/test-configs/hosts | sudo tee -a /etc/hosts
- run:
name: 'Install NVM'
command: |
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
command: curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
- run:
name: 'Install Node LTS'
command: |
Expand Down
21 changes: 15 additions & 6 deletions .circleci/fetch_merge_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,32 @@
# See the License for the specific language governing permissions and
# limitations under the license.
#
# This script fetches the merge commit of a PR branch with master.
# This script fetches the merge commit of a PR branch with master to make sure
# PRs are tested against all the latest changes.

set -e
err=0

if [ -z "$CIRCLE_PR_NUMBER" ]; then
# CIRCLE_PULL_REQUEST is present for PR builds, and absent for push builds.
# See https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables.
if [[ -z "$CIRCLE_PULL_REQUEST" ]]; then
echo -e "Nothing to do because this is not a PR build."
exit
exit 0
fi

# GitHub provides refs/pull/<PR_NUMBER>/merge for every PR branch that can be
# cleanly merged to `master`. See this discussion for more details:
# Make sure the PR is on ampproject/amphtml and not on a fork.
if [[ ! "$CIRCLE_PULL_REQUEST" =~ ^https://github.com/ampproject/amphtml* ]]; then
echo -e "This is a PR build, but on a repo other than ampproject/amphtml."
exit 1
fi

# GitHub provides refs/pull/<PR_NUMBER>/merge, an up-to-date merge branch for
# every PR branch that can be cleanly merged to master. For more details, see:
# https://discuss.circleci.com/t/show-test-results-for-prospective-merge-of-a-github-pr/1662
MERGE_BRANCH="refs/pull/$CIRCLE_PR_NUMBER/merge"
(set -x && git pull --ff-only origin "$MERGE_BRANCH") || err=$?

if [ "$err" -ne "0" ]; then
if [[ "$err" -ne "0" ]]; then
echo
echo -e "ERROR: Detected a merge conflict between $CIRCLE_BRANCH and master."
echo -e "Please rebase your PR branch."
Expand Down
39 changes: 39 additions & 0 deletions .circleci/setup-storage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
#
# Copyright 2021 The AMP HTML Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the license.
#
# Script used by AMP's CI builds to authenticate with their GCP storage bucket.
# TODO(rsimha, ampproject/amp-github-apps#1110): Update storage details.

set -e

if [[ -z "${GCP_TOKEN}" ]] ;
then
echo "Could not find the GCP_TOKEN environment variable. Exiting."
exit 1
fi

echo "Extracting credentials..."
openssl aes-256-cbc -k $GCP_TOKEN -in ./build-system/common/sa-travis-key.json.enc -out sa-travis-key.json -d

echo "Authenticating with GCP storage..."
gcloud auth activate-service-account --key-file=sa-travis-key.json

echo "Applying settings..."
gcloud config set account sa-travis@amp-travis-build-storage.iam.gserviceaccount.com
gcloud config set pass_credentials_to_gsutil true
gcloud config set project amp-travis-build-storage

echo "Successfully set up GCP storage."
12 changes: 12 additions & 0 deletions build-system/test-configs/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Used by various ads tests.
127.0.0.1 ads.localhost

# Used by various iframe tests.
127.0.0.1 iframe.localhost

# Used by tests that need a valid font host.
127.0.0.1 fonts.googleapis.com

# Used by integration tests for amp-recaptcha-input.
# The hash is the cURL subdomain for localhost:9876.
127.0.0.1 jgla3zmib2ggq5buc4hwi5taloh6jlvzukddfr4zltz3vay5s5rq.recaptcha.localhost

0 comments on commit 6c62105

Please sign in to comment.