Skip to content

Instantly share code, notes, and snippets.

@RyanRoberts
Forked from jeromecoupe/deploy.yaml
Created December 27, 2021 19:53
Show Gist options
  • Save RyanRoberts/62a4d02449a8c63804f50f15d58ee88b to your computer and use it in GitHub Desktop.
Save RyanRoberts/62a4d02449a8c63804f50f15d58ee88b to your computer and use it in GitHub Desktop.
Github actions: build and deploy Craft sites (WIP)
name: Craft CMS deployments
on:
push:
branches: [master]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# Pull repository into the current pipeline
- name: pull repository
uses: actions/checkout@v2
# Setup container with private SSH Key (used by rsync)
- name: Loads private SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_KEY }}
# Use a specific version of Node
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: "12.x"
# Install PHP dependencies
- name: Composer install
run: composer install --no-interaction --no-progress --no-suggest --optimize-autoloader
# Install NPM dependencies
- name: NPM install
run: npm ci
# Build assets using locally installed Gulp
- name: Build assets with Gulp
run: npx gulp build
# rsync
# exclude web/uploads is there to avoid deleting user uploaded files
# The StrictHostKeyChecking option avoids a failure when the client does not know the SSH host already
- name: deploy with rsync
run: |
rsync -azh --delete-after --exclude={'/web/uploads/','/node_modules/','/.git/','/.github/'} -e 'ssh -o StrictHostKeyChecking=no' ./ ${{ secrets.SSH_USER }}@${{ secrets.ssh_HOST }}:~/
# execute Craft commands on remote server
- name: Execute SSH commmands on remote server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.ssh_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
script: |
chmod a+x craft
php craft backup/db
php craft migrate/all
php craft project-config/apply
php craft clear-caches/all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment