Skip to content

Commit

Permalink
🏗 Consolidate remaining CircleCI VM setup steps into separate scripts (…
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimha committed Jan 29, 2021
1 parent 4443062 commit 71469e7
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 31 deletions.
22 changes: 3 additions & 19 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,14 @@ commands:
- browser-tools/install-chrome:
replace-existing: true
- run:
name: 'Install Google Cloud SDK'
command: |
cd ~/
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:
name: 'Setup Storage'
command: ./.circleci/setup-storage.sh
name: 'Setup Google Cloud Storage'
command: ./.circleci/setup_storage.sh
- run:
name: 'Configure 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
- run:
name: 'Install Node LTS'
command: |
nvm install 'lts/*'
echo "export PATH=`which node`:$PATH" >> $BASH_ENV
- run:
name: 'Install Dependencies'
command: |
npm install --global gulp-cli
npm ci
command: ./.circleci/install_dependencies.sh

jobs:
'Checks':
Expand Down
16 changes: 9 additions & 7 deletions .circleci/fetch_merge_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
set -e
err=0

GREEN() { echo -e "\n\033[0;32m$1\033[0m"; }
RED() { echo -e "\n\033[0;31m$1\033[0m"; }

# CIRCLE_PULL_REQUEST is present for PR builds, and absent for push builds.
if [[ -z "$CIRCLE_PULL_REQUEST" ]]; then
echo -e "Nothing to do because this is not a PR build."
echo $(GREEN "Nothing to do because this is not a PR build.")
exit 0
fi

# 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."
echo $(RED "This is a PR build, but on a repo other than ampproject/amphtml.")
exit 1
fi

Expand All @@ -47,16 +50,15 @@ fi
# 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/$PR_NUMBER/merge"
echo $(GREEN "Fetching merge commit from $MERGE_BRANCH...")
(set -x && git pull --ff-only origin "$MERGE_BRANCH") || err=$?


# If a clean merge is not possible, do not proceed with the build. GitHub's UI
# will show an error indicating there was a merge conflict.
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."
echo $(RED "Detected a merge conflict between $CIRCLE_BRANCH and master.")
echo $(RED "Please rebase your PR branch.")
exit $err
fi

echo -e "Successfully fetched merge commit of $CIRCLE_BRANCH with master."
echo $(GREEN "Successfully fetched merge commit of $CIRCLE_BRANCH with master.")
44 changes: 44 additions & 0 deletions .circleci/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/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 install project dependencies.

set -e

GREEN() { echo -e "\033[0;32m$1\033[0m"; }

echo $(GREEN "Installing NVM...")
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

echo $(GREEN "Setting up NVM environment...")
export NVM_DIR="/opt/circleci/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

echo $(GREEN "Installing Node LTS...")
nvm install 'lts/*'

echo $(GREEN "Installing gulp-cli...")
npm install --global gulp-cli

echo $(GREEN "Installing dependencies...")
npm ci

echo $(GREEN "Setting up environment...")
NODE_BIN=`which node`
(set -x && echo "export PATH=`dirname $NODE_BIN`:$PATH" >> $BASH_ENV)

echo $(GREEN "Successfully installed all project dependencies.")
20 changes: 15 additions & 5 deletions .circleci/setup-storage.sh → .circleci/setup_storage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,31 @@

set -e

GREEN() { echo -e "\033[0;32m$1\033[0m"; }
RED() { echo -e "\033[0;31m$1\033[0m"; }

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

echo "Extracting credentials..."
echo $(GREEN "Installing Google Cloud SDK...")
(set -x && cd ~/ && 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 $(GREEN "Setting up Cloud SDK environment...")
(set -x && echo "source ~/google-cloud-sdk/path.bash.inc" >> $BASH_ENV)
source $BASH_ENV

echo $(GREEN "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..."
echo $(GREEN "Authenticating with GCP storage...")
gcloud auth activate-service-account --key-file=sa-travis-key.json

echo "Applying settings..."
echo $(GREEN "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."
echo $(GREEN "Successfully set up GCP storage.")

0 comments on commit 71469e7

Please sign in to comment.