Skip to content

Testing existing multidev #2

Testing existing multidev

Testing existing multidev #2

Workflow file for this run

name: Push to Pantheon Multidev
on:
push:
branches:
- "multidev-*"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Set variables
id: vars
run: |
COMMIT_MESSAGE="${{ github.event.head_commit.message }}"
BRANCH_NAME="${{ github.ref }}"
DEPLOY_ENV=${BRANCH_NAME#refs/heads/multidev-}
echo "deploy_env=$DEPLOY_ENV" >> $GITHUB_OUTPUT
# This method ensures that the multi-line commit message is correctly stored as an output variable and can be used in subsequent steps or jobs within your workflow.
echo "deploy_note<<EOF" >> $GITHUB_OUTPUT
echo "$COMMIT_MESSAGE" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Get SSH Key from Pantheon
id: set_ssh_key
shell: bash
# Pantheon server is the server name you get from SSH Clone URL when you click on Connection info in pantheon dashboard.
run: |
echo "sshkey=$(ssh-keyscan -t rsa -H -p 2222 ${{ secrets.PANTHEON_SERVER }})" >> $GITHUB_OUTPUT
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.ref }} # Check out the branch that triggered the workflow.
fetch-depth: 0 # Fetch the full commit history.
- name: Setup SSH
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.PANTHEON_GH_ACTIONS_KEY }} # Private Key generated with ssh-keygen -t rsa -b 4096 -C "[email protected]" -f pantheon_gh_actions_key
config: ${{ vars.SSH_CONFIG }}
known_hosts: ${{ steps.set_ssh_key.outputs.sshkey }}
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.1" # Set the PHP version you're using
- name: Install Terminus
run: |
curl -O https://raw.githubusercontent.com/pantheon-systems/terminus-installer/master/builds/installer.phar && php installer.phar install
echo "$GITHUB_WORKSPACE/vendor/bin" >> $GITHUB_PATH
- name: Clone Pantheon repository
id: clone
run: |
terminus auth:login --machine-token=${{ secrets.PANTHEON_MACHINE_TOKEN }}
terminus connection:set ${{ vars.PANTHEON_SITE }}.dev git
terminus connection:info ${{ vars.PANTHEON_SITE }}.dev --field='git_url' > pantheon_repo_url.txt
export PANTHEON_REPO_URL=$(cat pantheon_repo_url.txt)
git clone $PANTHEON_REPO_URL pantheon_repo
cd pantheon_repo
git config user.name "The World GitHub Actions Bot"
git config user.email "[email protected]"
git remote add github_repo $GITHUB_WORKSPACE
git fetch github_repo
# Review this because it is merging things from a repo that is not the correct i think
git merge --allow-unrelated-histories -X theirs github_repo/${{ github.ref_name }}
- name: Check for Multidev Environment and create if it does not exist
id: check-multidev
run: |
# Check if the multidev environment already exists.
EXISTING_ENV=$(terminus multidev:list ${{ vars.PANTHEON_SITE }} --format=list --field=Name | grep -w ${{ steps.vars.outputs.deploy_env }} || true)
if [[ -z "$EXISTING_ENV" ]]; then
terminus multidev:create ${{ vars.PANTHEON_SITE }}.live ${{ steps.vars.outputs.deploy_env }}
fi
cd pantheon_repo
git checkout -b ${{ steps.vars.outputs.deploy_env }}
# we must force the update because the github repo is the source of truth.
git push origin ${{ steps.vars.outputs.deploy_env }} -f
- name: Clear Pantheon Cache
if: steps.vars.outputs.deploy_env != ''
run: |
terminus env:clear-cache ${{ vars.PANTHEON_SITE }}.${{ steps.vars.outputs.deploy_env }}