Created
October 20, 2021 21:03
-
-
Save ajmorris/4bfb97e89c8224719cf5f43b598cd2bf to your computer and use it in GitHub Desktop.
Simple workflow file for Github Actions to deploy your WordPress theme
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
# This is a basic workflow to help you get started with Actions | |
# The name of the script you are intending to run. | |
name: Deployment | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on push or pull request events but only for the main branch. | |
# I left my branch name as main, but you could change this to whatever your branches are called. | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
# This workflow contains a single job called "build" | |
build: | |
# The type of runner that the job will run on | |
# I think this is related to the server you are "borrowing" from Github to run the actions on. | |
runs-on: ubuntu-latest | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
# I'm not sure why you need this other than to suggest that you are using a GH server to run these scripts, | |
# so you likely need to run a little checkout of the repo so you have files locally before sending them | |
# to your server. | |
- uses: actions/checkout@v2 | |
# Runs a set of commands using the runners shell | |
- name: Sync | |
env: | |
dest: 'ssh-user@server-ip-or-domain:/file/location/to/wp-content/themes/your-theme-name/' | |
# The run below is what you would run if you were using rsync between your local computer and server. | |
# The fist 2 lines are necessary to pull the deploy key out of the secret so you can connect to the server. | |
# I chose to exclude the deploy_key, .git and .github folders as they are not necessary for the theme to run on the | |
# server. If you wanted to include those you could. | |
run: | | |
echo "${{secrets.DEPLOY_KEY}}" > deploy_key | |
chmod 600 ./deploy_key | |
rsync -chav --delete \ | |
-e 'ssh -i ./deploy_key -o StrictHostKeyChecking=no' \ | |
--exclude /deploy_key \ | |
--exclude /.git/ \ | |
--exclude /.github/ \ | |
./ ${{env.dest}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment