Skip to content

Instantly share code, notes, and snippets.

@daggerhart
Created December 18, 2021 23:08
Show Gist options
  • Save daggerhart/72563179b1ef0774433e2b71858f1781 to your computer and use it in GitHub Desktop.
Save daggerhart/72563179b1ef0774433e2b71858f1781 to your computer and use it in GitHub Desktop.
GitHub Composite Action for deploying to pantheon
name: "Setup Runner"
description: "Provides SSH, PHP, Terminus as a composite action"
inputs:
pantheon_ssh_key:
description: 'Pantheon SSH Private key in the PEM format.'
required: true
ssh_config:
description: 'Contents of the ssh/config file.'
required: true
pantheon_machine_token:
description: 'Pantheon Machine Token for Terminus.'
required: true
known_hosts:
description: 'Known hosts file contents. Defaults to single blank space.'
required: true
default: ' '
php_version:
description: 'PHP version'
required: true
default: '7.3'
composer_version:
description: 'Composer version'
required: true
default: 'v2'
node_version:
description: 'Node.js version'
required: true
default: '10.x'
terminus_version:
description: 'Terminus version number in composer dependency format.'
required: true
default: '^2.0'
terminus_build_tools_version:
description: 'Terminus build tools version number in composer dependency format.'
required: true
default: '^2.0'
runs:
using: "composite"
steps:
- name: Setup SSH
uses: shimataro/ssh-key-action@v2
with:
key: ${{ inputs.pantheon_ssh_key }}
config: ${{ inputs.ssh_config }}
known_hosts: ${{ inputs.known_hosts }}
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: ${{ inputs.node_version }}
- name: Setup PHP
uses: shivammathur/setup-php@master
with:
php-version: ${{ inputs.php_version }}
extensions: gd
tools: composer:${{ inputs.composer_version }}
# Composer caching.
- name: Get Composer Cache Directory
id: composer-cache
shell: bash
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Utilize Composer Cache Directory
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
# Terminus setup and test.
- name: Installing Terminus
shell: bash
run: |
composer global require pantheon-systems/terminus:${{ inputs.terminus_version }}
terminus auth:login --machine-token=${{ inputs.pantheon_machine_token }}
- name: Install Terminus build tools
shell: bash
if: success()
run: |
mkdir -p ~/.terminus/plugins
composer create-project --no-dev -d ~/.terminus/plugins pantheon-systems/terminus-build-tools-plugin:${{ inputs.terminus_build_tools_version }}
- name: Terminus - Listing Sites
shell: bash
if: success()
run: terminus site:list
## https://medium.com/swlh/pantheon-and-github-actions-automated-deployments-via-github-actions-c245aa954797
name: Deploy to Pantheon
on:
push:
branches:
- 'master'
jobs:
build:
name: Build and push to Pantheon
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- id: setup-runner
name: Setup Runner
uses: ./.github/actions/setup-runner
with:
pantheon_ssh_key: ${{ secrets.PANTHEON_SSH_KEY }}
ssh_config: ${{ secrets.SSH_CONFIG }}
pantheon_machine_token: ${{ secrets.PANTHEON_MACHINE_TOKEN }}
php_version: '7.3'
composer_version: 'v1'
terminus_version: '^2.0'
node_version: '10.x'
- name: Composer Install Dependencies
run: composer install --optimize-autoloader --no-dev --prefer-dist --no-progress --no-suggest
## Build Theme
- name: Build Theme Artifacts
run: |
cd web/themes/custom/<my theme here>
npm install
## Prepare for Pantheon
- name: Prepare for Pantheon
run: |
cp .gitignore.pantheon .gitignore
find ./web -type d -name ".git" | xargs rm -fr
## Deploy
- name: Deploy to Pantheon
env:
pantheon_site: '<pantheon site name here>'
pantheon_env: 'dev'
run: |
commit_message=$(git log -1 --pretty=%B)
git config user.name "$(git --no-pager log --format=format:'%an' -n 1)"
git config user.email "$(git --no-pager log --format=format:'%ae' -n 1)"
terminus build:env:push $pantheon_site.$pantheon_env --message="${{ github.actor }}: CI Deployment for: $commit_message"
## Terminus
- name: Terminus Drush Updates
env:
pantheon_site: '<pantheon site name here>'
pantheon_env: 'dev'
run: |
terminus -n drush $pantheon_site.$pantheon_env -- deploy -y
terminus -n env:clear-cache $pantheon_site.$pantheon_env
@daggerhart
Copy link
Author

Example of reusable composite custom action, and a workflow that uses it.

Gist doesn't allow forward slashes in filenames, so pretend the backslashes are forward slashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment