How to have GitHub actions build your theme assets so you don't need to have built files in source control.
A while back, I was chatting with my colleague Ryan about Ghost theme deployment and how cool it would be to not need to commit built files to source control and have GitHub Actions build them and then deploy.
Ryan took that idea and ran with it. He wrote a really nice article about how to achieve just what I was after.
I borrowed most of the code & ideas, and adapted it slightly to suit my needs. I use yarn
instead of npm
, so my version accounts for that and skips deploying to a demo site.
If you already use GitHub Actions to deploy your theme, you can probably drop this right in. You may need to adapt the build task, which is run: npm run build
in this yaml
file and "build": "gulp build",
in the scripts
in my package.json
file.
name: Deploy Theme
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: 'npm'
- run: |
if [ -e yarn.lock ]; then
yarn install --frozen-lockfile
elif [ -e package-lock.json ]; then
npm ci
else
npm i
fi
- run: npm run build
- name: Deploy site
uses: TryGhost/action-deploy-theme@v1
with:
api-url: ${{ secrets.GHOST_ADMIN_API_URL }}
api-key: ${{ secrets.GHOST_ADMIN_API_KEY }}
I'm mostly sharing this incase anyone with the same setup as me is in a ind and needs a quick solution. Happy building!