Skip to content

Commit

Permalink
Merge pull request #277 from material-components/add/deploy-action
Browse files Browse the repository at this point in the history
Add staging auto deploy script
  • Loading branch information
emeaguiar committed Mar 18, 2022
2 parents 0933da6 + a76ad0e commit ddcfe5a
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 0 deletions.
126 changes: 126 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Build plugin

on:
push:
# Don't run for irrelevant changes.
paths-ignore:
- '__mocks__/**'
- '__static__/**'
- 'bin/**'
- 'packages/e2e-test-utils/**'
- 'packages/e2e-tests/**'
- 'packages/karma-*/**'
- 'plugin/tests/**'
- '**.md'
- '**.yml'
- '**.js.snap'
- '**.neon.dist'
- '**.xml.dist'
- '.editorconfig'
- '.eslint*'
- '.prettier*'
- '.stylelint*'
- '.github/workflows/**'
- '!.github/workflows/build-and-deploy.yml'
branches:
- develop
- full-site-editing

jobs:
build:
name: Build and package artifacts
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v2.5.1
with:
node-version-file: '.nvmrc'
cache: npm

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
tools: composer

- name: Install dependencies
run: |
npm ci
env:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true

- name: Install PHP dependencies
uses: 'ramsey/composer-install@v1'
with:
composer-options: '--prefer-dist --no-progress --no-interaction'

- name: Build plugin
run: |
npm run build
mkdir -p build/plugin/ build/theme
- name: Bundle regular version
run: |
unzip material-design.zip -d "build/plugin/"
unzip material-design-google.zip -d "build/theme/"
- name: Upload regular bundle
uses: actions/upload-artifact@v2
with:
name: material-design
path: build/

deploy-to-staging:
name: Deploy to staging environment
runs-on: ubuntu-latest
timeout-minutes: 5
needs: build
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'

steps:
- name: Download full bundle
uses: actions/download-artifact@v2
with:
name: material-design
path: build

- name: Setup SSH Keys and known_hosts
uses: webfactory/ssh-agent@v0.5.4
with:
ssh-private-key: ${{ secrets.PANTHEON_DEPLOY_KEY }}

- name: Run deployment
run: bash bin/deploy-to-staging.sh master

deploy-to-fse:
name: Deploy to fse environment
runs-on: ubuntu-latest
timeout-minutes: 5
needs: build
if: github.ref == 'refs/heads/full-site-editing' && github.event_name == 'push'

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Download full bundle
uses: actions/download-artifact@v2
with:
name: material-design
path: build

- name: Setup SSH Keys and known_hosts
uses: webfactory/ssh-agent@v0.5.4
with:
ssh-private-key: ${{ secrets.PANTHEON_DEPLOY_KEY }}

- name: Run deployment to fse
run: bash bin/deploy-to-staging.sh fse

- name: Run deployment to traditional
run: bash bin/deploy-to-staging.sh traditional
95 changes: 95 additions & 0 deletions bin/deploy-to-staging.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash
set -e

#
# Copyright 2020 Google LLC
#
# 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
#
# https://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.
#

# Custom deployment script for Pantheon environment.
# Adapted from https://github.com/google/web-stories-wp/blob/ca31b552fc9fce8b567bda4b0f59e15e1ddbc22c/bin/deploy-to-test-environment.sh

echo "Initializing deployment to Material design theme and plugin to test environment"

PANTHEON_SITE="mdc-web"
PANTHEON_BRANCH=$1
PANTHEON_UUID="395bf65b-d336-4308-9c86-311e8ddce422"

cd "$(dirname "$0")/.."
project_dir="$(pwd)"
repo_dir="$HOME/deployment-targets/$PANTHEON_SITE"

echo "Setting up SSH configuration"

# Dynamic hosts through Pantheon mean constantly checking interactively
# that we mean to connect to an unknown host. We ignore those here.
echo "StrictHostKeyChecking no" > ~/.ssh/config

if ! grep -q "codeserver.dev.$PANTHEON_UUID.drush.in" ~/.ssh/known_hosts; then
ssh-keyscan -p 2222 codeserver.dev.$PANTHEON_UUID.drush.in >> ~/.ssh/known_hosts
fi

if ! grep -q "codeserver.dev.$PANTHEON_UUID.drush.in" ~/.ssh/config; then
echo "" >> ~/.ssh/config
echo "Host $PANTHEON_SITE" >> ~/.ssh/config
echo " Hostname codeserver.dev.$PANTHEON_UUID.drush.in" >> ~/.ssh/config
echo " User codeserver.dev.$PANTHEON_UUID" >> ~/.ssh/config
echo " Port 2222" >> ~/.ssh/config
echo " KbdInteractiveAuthentication no" >> ~/.ssh/config
fi

echo "Fetching remote repository"

git config --global user.name "Travis CI"
git config --global user.email "travis-ci+$PANTHEON_SITE@example.org"

if [ ! -e "$repo_dir/.git" ]; then
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"
fi

cd "$repo_dir"

if git rev-parse --verify --quiet "origin/$PANTHEON_BRANCH" > /dev/null; then
git reset --hard "origin/$PANTHEON_BRANCH"
fi

cd "$project_dir"

echo "Moving files to repository"

rsync -avz --delete ./build/plugin/material-design/ "$repo_dir/wp-content/plugins/material-design/"
rsync -avz --delete ./build/theme/material-design-google/ "$repo_dir/wp-content/themes/material-design-google/"
git --no-pager log -1 --format="Build material theme and plugin at %h: %s" > /tmp/commit-message.txt

echo "Committing changes"

# Commit and deploy.
cd "$repo_dir"
git add -A "wp-content/plugins/material-design/" "wp-content/themes/material-design-google/"
git commit -F /tmp/commit-message.txt

echo "Pushing new build to remote repository"
git push origin $PANTHEON_BRANCH

if [ "$PANTHEON_BRANCH" == "master" ]; then
PANTHEON_ENV="dev"
else
PANTHEON_ENV="$PANTHEON_BRANCH"
fi

echo "Cleaning up project dir"
rm -rf "$repo_dir"

echo "View site at http://$PANTHEON_ENV-$PANTHEON_SITE.pantheonsite.io/"
echo "Access Pantheon dashboard at https://dashboard.pantheon.io/sites/$PANTHEON_UUID#$PANTHEON_BRANCH"

0 comments on commit ddcfe5a

Please sign in to comment.