Setting up Github
In Github, go to the project’s Settings page. Under Security, click Secrets and then Actions.
To create a new variable, click the New repository secret button. We will need to create the following variables to the following values:
KNOWN_HOSTS
A single space is finePANTHEON_MACHINE_TOKEN
On 1Password, the Machine Token value under Pantheon Dashboard: KalaCommitBotPANTHEON_REPO
URL for the project’s pantheon repo. You can find this on the pantheon page by clicking Connection Info, then coping the url part of the Git: SSH clone URL commandPANTHEON_SITE_NAME
Machine name for the project’s pantheon site (PANTHEON_SITE_NAME.env in the site url)PANTHEON_SSH_KEY
On 1Password, under “KalaCommitBot Private SSH Key”SSH_CONFIG
Host *.drush.in StrictHostKeyChecking no
Github action scripts
In the project’s root directory, create a folder called .github, and inside that directory create a folder called workflows. Github action scripts will be .yml files inside the .github/workflows/ directory.
Create multi-dev environment
To have a github action create a multi-dev environment whenever a pull request is created in github, create a file in .github/workflows with a name like pr-open-create-multidev.yml with the following code:
name: Create Pantheon Multidev for Pull Request on: pull_request: types: [opened] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 with: fetch-depth: 0 - uses: shimataro/ssh-key-action@v2 with: key: ${{ secrets.PANTHEON_SSH_KEY }} config: ${{ secrets.SSH_CONFIG }} known_hosts: ${{ secrets.KNOWN_HOSTS }} - name: Installing Terminus env: pantheon_machine_token: ${{ secrets.PANTHEON_MACHINE_TOKEN }} run: | composer global require pantheon-systems/terminus ~/.composer/vendor/bin/terminus auth:login --machine-token=$pantheon_machine_token - name: deployer env: pantheon_repo: '${{ secrets.PANTHEON_REPO }}' pantheon_site_name: '${{ secrets.PANTHEON_SITE_NAME }}' run: | BRANCH_NAME=$(echo ${GITHUB_HEAD_REF}) git remote add pantheon $pantheon_repo git push -uf pantheon HEAD:$BRANCH_NAME ~/.composer/vendor/bin/terminus multidev:create $pantheon_site_name.dev $BRANCH_NAME
Delete multi-dev environment
To have a github action delete a corresponding multi-dev environment whenever a pull request is closed in github, create a file in .github/workflows with a name like pr-close-delete-multidev.yml with the following code:
name: Delete Pantheon Multidev on Closing Pull Request on: pull_request: types: [closed] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 with: fetch-depth: 0 - uses: shimataro/ssh-key-action@v2 with: key: ${{ secrets.PANTHEON_SSH_KEY }} config: ${{ secrets.SSH_CONFIG }} known_hosts: ${{ secrets.KNOWN_HOSTS }} - name: Installing Terminus env: pantheon_machine_token: ${{ secrets.PANTHEON_MACHINE_TOKEN }} run: | composer global require pantheon-systems/terminus ~/.composer/vendor/bin/terminus auth:login --machine-token=$pantheon_machine_token - name: deployer env: pantheon_site_name: '${{ secrets.PANTHEON_SITE_NAME }}' run: | BRANCH_NAME=$(echo ${GITHUB_HEAD_REF}) ~/.composer/vendor/bin/terminus multidev:delete --yes -- $pantheon_site_name.$BRANCH_NAME