Last active
August 2, 2023 16:41
-
-
Save jeromecoupe/2a0314487546f6f11e695d7d774c9d3d to your computer and use it in GitHub Desktop.
Github actions: build and deploy Craft sites (WIP)
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: 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
@cbj4074 No problem. Glad it helped. The straightforward answer is that php and composer are included in the
ubuntu-latest
image used as the virtual environment by Github actions, as per the doc