Last active
February 9, 2023 14:20
-
-
Save Sean12mps/d15f6b17a7e39a7b0d0b9e2d4e57ee62 to your computer and use it in GitHub Desktop.
Deploy Theme or Plugin to Pantheon from Github
This file contains hidden or 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: "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 | |
| 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' | |
| 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 }} | |
| known_hosts: ${{ inputs.known_hosts }} | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@master | |
| with: | |
| php-version: ${{ inputs.php_version }} | |
| tools: composer:${{ inputs.composer_version }} | |
| # 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: Terminus - Listing Sites | |
| shell: bash | |
| if: success() | |
| run: terminus site:list |
This file contains hidden or 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: Deploy to Pantheon | |
| on: | |
| push: | |
| branches: | |
| - 'master' | |
| pull_request: | |
| branches: | |
| - 'master' | |
| jobs: | |
| build: | |
| name: Build and push to Pantheon | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v2.3.4 | |
| ## Setup runner. | |
| - name: Setup Runner | |
| id: setup-runner | |
| uses: ./.github/actions/setup-runner | |
| with: | |
| pantheon_ssh_key: ${{ secrets.PANTHEON_SSH_KEY }} | |
| pantheon_machine_token: ${{ secrets.PANTHEON_MACHINE_TOKEN }} | |
| php_version: '8.2' | |
| composer_version: '2.2' | |
| terminus_version: '^3.0' | |
| ## Set Pantheon to SFTP mode. | |
| - name: Set Pantheon site to SFTP | |
| env: | |
| pantheon_site: ${{ secrets.PANTHEON_SITE_NAME }} | |
| pantheon_env: 'dev' | |
| run: | | |
| terminus connection:set $pantheon_site.$pantheon_env -- sftp | |
| ## Prepare for Pantheon | |
| - name: Prepare files | |
| run: | | |
| rsync -Rr ./ ${{ secrets.SFTP_FOLDER }} | |
| rm -r ${{ secrets.SFTP_FOLDER }}/.git | |
| rm -r ${{ secrets.SFTP_FOLDER }}/.github | |
| ## SFTP deploy to Pantheon. | |
| - name: SFTP deploy | |
| id: upload | |
| uses: Creepios/sftp-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.SFTP_HOST }} | |
| port: 2222 | |
| username: ${{ secrets.SFTP_USERNAME }} | |
| password: ${{ secrets.SFTP_PASSWORD }} | |
| # The local folder to copy, defaults to root project folder. | |
| localPath: ${{ secrets.SFTP_FOLDER }} | |
| # The remote path to copy into. | |
| remotePath: 'code/${{ secrets.SFTP_TARGET }}/${{ secrets.SFTP_FOLDER }}' | |
| ## Wait for Pantheon changes. | |
| - name: Sleep for 8 seconds | |
| run: sleep 8s | |
| shell: bash | |
| ## Commit changes. | |
| - name: Commit changes | |
| env: | |
| pantheon_site: ${{ secrets.PANTHEON_SITE_NAME }} | |
| 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 env:commit $pantheon_site.$pantheon_env --message="$commit_message"; | |
| ## Wait for Pantheon changes. | |
| - name: Sleep for 8 seconds | |
| run: sleep 8s | |
| shell: bash | |
| ## Push changes to test. | |
| - name: Pushing to Test environment. | |
| env: | |
| pantheon_site: ${{ secrets.PANTHEON_SITE_NAME }} | |
| run: | | |
| terminus env:deploy $pantheon_site.test --note="Deploy from Github." | |
| ## Wait for Pantheon changes. | |
| - name: Sleep for 8 seconds | |
| run: sleep 8s | |
| shell: bash | |
| ## Push changes to live. | |
| - name: Pushing to Live environment. | |
| env: | |
| pantheon_site: ${{ secrets.PANTHEON_SITE_NAME }} | |
| run: | | |
| terminus env:deploy $pantheon_site.live --note="Deploy from Github." | |
| ## Set Pantheon to git mode. | |
| - name: Set Pantheon site to Git | |
| env: | |
| pantheon_site: ${{ secrets.PANTHEON_SITE_NAME }} | |
| pantheon_env: 'dev' | |
| run: | | |
| terminus connection:set $pantheon_site.$pantheon_env -- git |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Secrets:
Can use your local SSH key.
Use machine token registered for your account.
Site name like when you're using Terminus.
Host information from Pantheon site - connection info.
Host information from Pantheon site - connection info.
Your account password.
Folder name to wrap your repo theme or plugin.
Target folder to send SFTP_FOLDER into.