-
-
Save jeromecoupe/2a0314487546f6f11e695d7d774c9d3d to your computer and use it in GitHub Desktop.
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 |
run: composer install --no-interaction --no-progress --no-suggest --optimize-autoloader
I usually do
run: composer install --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader
On production builds.
@dingo-d thank you for chiming in, not a PHP or composer expert here but I'll make sure I have a closer look at those options with regards to standard Craft builds. Thanks again!
Interesting! I use buddy too for private stuff but it's to expensive. How long runs a build with GH Actions?
@davidhellmann Build times can vary but, looking at the last 20 builds on the live project I am testing this, they are hovering around 2 minutes, give or take.
Thanks for sharing this!
I'm not a Craft CMS user, but I stumbled upon this while attempting to troubleshoot a similar build process (PHP with composer
and npm
).
I'm not clear as to how composer
appears to be available in your environment automatically, i.e., you simply run composer install ...
without installing Composer anywhere explicitly.
Do you mind sharing how this works, exactly? Thank you!
@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
I wanted to reproduce a simplified version of what services like Buddy.Works are doing w/ Github Actions
Still a WIP but already tested it successfully with a small custom Craft website.
Basic steps
This blogpost by the fine people at Fortrabbit helped a lot: https://blog.fortrabbit.com/how-to-use-github-actions