|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# |
| 5 | +# Copyright 2020 Google LLC |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +# you may not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +# |
| 19 | + |
| 20 | +# Custom deployment script for Pantheon environment. |
| 21 | +# Adapted from https://github.com/google/web-stories-wp/blob/ca31b552fc9fce8b567bda4b0f59e15e1ddbc22c/bin/deploy-to-test-environment.sh |
| 22 | + |
| 23 | +echo "Initializing deployment to Material design theme and plugin to test environment" |
| 24 | + |
| 25 | +PANTHEON_SITE="mdc-web" |
| 26 | +PANTHEON_BRANCH=$1 |
| 27 | +PANTHEON_UUID="395bf65b-d336-4308-9c86-311e8ddce422" |
| 28 | + |
| 29 | +cd "$(dirname "$0")/.." |
| 30 | +project_dir="$(pwd)" |
| 31 | +repo_dir="$HOME/deployment-targets/$PANTHEON_SITE" |
| 32 | + |
| 33 | +echo "Setting up SSH configuration" |
| 34 | + |
| 35 | +# Dynamic hosts through Pantheon mean constantly checking interactively |
| 36 | +# that we mean to connect to an unknown host. We ignore those here. |
| 37 | +echo "StrictHostKeyChecking no" > ~/.ssh/config |
| 38 | + |
| 39 | +if ! grep -q "codeserver.dev.$PANTHEON_UUID.drush.in" ~/.ssh/known_hosts; then |
| 40 | + ssh-keyscan -p 2222 codeserver.dev.$PANTHEON_UUID.drush.in >> ~/.ssh/known_hosts |
| 41 | +fi |
| 42 | + |
| 43 | +if ! grep -q "codeserver.dev.$PANTHEON_UUID.drush.in" ~/.ssh/config; then |
| 44 | + echo "" >> ~/.ssh/config |
| 45 | + echo "Host $PANTHEON_SITE" >> ~/.ssh/config |
| 46 | + echo " Hostname codeserver.dev.$PANTHEON_UUID.drush.in" >> ~/.ssh/config |
| 47 | + echo " User codeserver.dev.$PANTHEON_UUID" >> ~/.ssh/config |
| 48 | + echo " Port 2222" >> ~/.ssh/config |
| 49 | + echo " KbdInteractiveAuthentication no" >> ~/.ssh/config |
| 50 | +fi |
| 51 | + |
| 52 | +echo "Fetching remote repository" |
| 53 | + |
| 54 | +git config --global user.name "Travis CI" |
| 55 | +git config --global user.email "travis-ci+$PANTHEON_SITE@example.org" |
| 56 | + |
| 57 | +if [ ! -e "$repo_dir/.git" ]; then |
| 58 | + git clone -v ssh://codeserver.dev.$PANTHEON_UUID@codeserver.dev.$PANTHEON_UUID.drush.in:2222/~/repository.git --depth 1 --branch "$PANTHEON_BRANCH" --single-branch "$repo_dir" |
| 59 | +fi |
| 60 | + |
| 61 | +cd "$repo_dir" |
| 62 | + |
| 63 | +if git rev-parse --verify --quiet "origin/$PANTHEON_BRANCH" > /dev/null; then |
| 64 | + git reset --hard "origin/$PANTHEON_BRANCH" |
| 65 | +fi |
| 66 | + |
| 67 | +cd "$project_dir" |
| 68 | + |
| 69 | +echo "Moving files to repository" |
| 70 | + |
| 71 | +rsync -avz --delete ./build/plugin/material-design/ "$repo_dir/wp-content/plugins/material-design/" |
| 72 | +rsync -avz --delete ./build/theme/material-design-google/ "$repo_dir/wp-content/themes/material-design-google/" |
| 73 | +git --no-pager log -1 --format="Build material theme and plugin at %h: %s" > /tmp/commit-message.txt |
| 74 | + |
| 75 | +echo "Committing changes" |
| 76 | + |
| 77 | +# Commit and deploy. |
| 78 | +cd "$repo_dir" |
| 79 | +git add -A "wp-content/plugins/material-design/" "wp-content/themes/material-design-google/" |
| 80 | +git commit -F /tmp/commit-message.txt |
| 81 | + |
| 82 | +echo "Pushing new build to remote repository" |
| 83 | +git push origin $PANTHEON_BRANCH |
| 84 | + |
| 85 | +if [ "$PANTHEON_BRANCH" == "master" ]; then |
| 86 | + PANTHEON_ENV="dev" |
| 87 | +else |
| 88 | + PANTHEON_ENV="$PANTHEON_BRANCH" |
| 89 | +fi |
| 90 | + |
| 91 | +echo "Cleaning up project dir" |
| 92 | +rm -rf "$repo_dir" |
| 93 | + |
| 94 | +echo "View site at http://$PANTHEON_ENV-$PANTHEON_SITE.pantheonsite.io/" |
| 95 | +echo "Access Pantheon dashboard at https://dashboard.pantheon.io/sites/$PANTHEON_UUID#$PANTHEON_BRANCH" |
0 commit comments