Skip to content

Commit

Permalink
Merge pull request #3 from digitalpolygon/automatic-documentation-syn…
Browse files Browse the repository at this point in the history
…chronization

Automatic documentation synchronization.
  • Loading branch information
adrian-morelos authored May 3, 2024
2 parents 0672464 + 728bf62 commit c776057
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/dev-multidev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# ###
# Deploys Drupal-Docs project Pantheon multidev and dev environments.
# ###

# Exit if anything fails
set -eo pipefail

# Cut gitignore at the cut mark.
terminus build:gitignore:cut

# Authenticate with Terminus
terminus -n auth:login --machine-token="$TERMINUS_TOKEN"

# Environment from which multidevs will be created.
CREATE_MDS_FROM="dev"
TERMINUS_ENV="dev"

if [[ "$CI_BRANCH" == "$DEVELOPMENT_BRANCH" ]]; then
# Use develop as the environment.
TERMINUS_ENV="develop"
fi

if [[ "$BASE_BRANCH" == "$DEVELOPMENT_BRANCH" ]]; then
# Use develop as the environment.
CREATE_MDS_FROM="develop"
fi

# If its a PR to development or production branch, create a multidev.
if [[ -n "$PR_NUMBER" ]] ; then
TERMINUS_ENV="pr-${PR_NUMBER}"
fi

echo "Preparing $TERMINUS_ENV multidev from $CREATE_MDS_FROM for $TERMINUS_SITE"

set +e
TERMINUS_ENV_EXISTS=$(terminus env:list "$TERMINUS_SITE" --field=ID | grep -w $TERMINUS_ENV)
set -e

if [[ -z "$TERMINUS_ENV_EXISTS" ]]
then
echo "Site $TERMINUS_SITE does not have a $TERMINUS_ENV multidev..."
else
echo "Syncing documentation $TERMINUS_ENV on $TERMINUS_SITE"
# Run The migration deploy.
terminus drush "$TERMINUS_SITE.$TERMINUS_ENV" -- migrate:import schemaorg_metata -y;
fi
62 changes: 62 additions & 0 deletions .github/workflows/build_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build and Deploy to Pantheon

on:
push:
branches:
- main
pull_request:
branches:
- main

defaults:
run:
shell: bash

env:
TERMINUS_TOKEN: ${{ secrets.TERMINUS_TOKEN }}
CI_BRANCH: ${{ github.head_ref || github.ref_name }}
BASE_BRANCH: ${{ github.base_ref }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_OWNER: ${{ github.repository_owner }}
PRODUCTION_BRANCH: 'main'
DEVELOPMENT_BRANCH: 'develop'
PR_NUMBER: ${{ github.event.number }}
TERMINUS_SITE: 'drupaldocs'

jobs:
deploy_to_pantheon:
name: Deploy to pantheon
runs-on: ubuntu-latest
steps:
- name: Set ownership
run: |
chown -R $(id -u):$(id -g) $PWD
- name: Setup PHP
id: setup-php
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'

- name: Install Terminus
uses: pantheon-systems/terminus-github-actions@main
with:
pantheon-machine-token: ${{ secrets.TERMINUS_TOKEN }}

- name: Install Terminus Build Tools
run: |
terminus self:plugin:install terminus-build-tools-plugin
- name: Checkout source branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
fetch-depth: 0

# Deploy to Pantheon Downstream sites
- name: Deploy to Pantheon
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
.github/dev-multidev.sh

0 comments on commit c776057

Please sign in to comment.