Merge pull request #230 from PRX/feat/229-smtp #133
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Push to Pantheon Core Environments | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set variables | |
id: vars | |
run: | | |
COMMIT_MESSAGE="${{ github.event.head_commit.message }}" | |
DEPLOY_ENV='dev' | |
# If the commit message contains [deploy:ENV], set the deploy environment. | |
if [[ $COMMIT_MESSAGE =~ \[deploy:(.*)\] ]]; then | |
DEPLOY_ENV=${BASH_REMATCH[1]} | |
fi | |
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 | |
git merge --allow-unrelated-histories -X theirs github_repo/${{ github.ref_name }} | |
- name: Push code to Pantheon Dev Environment | |
run: | | |
cd pantheon_repo | |
git push origin master | |
- name: Deploy to Test Environment | |
if: steps.vars.outputs.deploy_env == 'test' || steps.vars.outputs.deploy_env == 'live' | |
run: | | |
terminus env:deploy ${{ vars.PANTHEON_SITE }}.test --note "${{ steps.vars.outputs.deploy_note }}" | |
- name: Deploy to Live Environment | |
if: steps.vars.outputs.deploy_env == 'live' | |
run: | | |
terminus env:deploy ${{ vars.PANTHEON_SITE }}.live --note "${{ steps.vars.outputs.deploy_note }}" | |
- name: Clear Pantheon Cache | |
if: steps.vars.outputs.deploy_env != '' | |
run: | | |
terminus env:clear-cache ${{ vars.PANTHEON_SITE }}.${{ steps.vars.outputs.deploy_env }} |