Alterntively, it is possible to run gscan as part of your github action. There are 2 methods, that depend a bit on your ideal local setup and workflow.
Option 1 - using gscan as npm test
In the Casper repository, we have npm test
configured to run gscan.
You can do this, by:
- adding
gscan
as a dev dependency to your theme npm install gscan --save-dev
- adding a test script to package.json, e.g.
"scripts": {
"test": "gscan ."
}
- Configure the gscan command to work how you want, e.g.
gscan --fatal .
if you only want fatal errors.
Once this is setup, you can then add steps to your github action workflow .yml file to run npm test
on every build, which will then fail before attempting to upload to Ghost.
The extra steps go between the checkout step, and the deploy step, like this:
steps:
- uses: actions/checkout@master
- name: Use Node.js 10
uses: actions/setup-node@v1
with:
node-version: 10
- name: install and test
run: |
npm install
npm test
- name: Deploy Ghost Theme
uses: TryGhost/action-deploy-theme@v1.2.0
Now you can easily run npm test
to check gscan before pushing, but the build will catch this if you forget.
Option 2 - use gscan directly in workflow
Option 2 is quicker, and should keep your build time down as well as we only ever install gscan - whereas if you have other dependencies, option 1 would install those too.
This time, we just edit the workflow .yml file, again to add 2 new steps between the checkout step and the deploy step:
steps:
- uses: actions/checkout@master
- name: Use Node.js 10
uses: actions/setup-node@v1
with:
node-version: 10
- name: Run gscan
run: |
npm install --global gscan@latest
gscan --fatal --verbose $GITHUB_WORKSPACE
- name: Deploy Ghost Theme
uses: TryGhost/action-deploy-theme@v1.2.0
You can customise the gscan command - if you remove the --fatal
flag gscan will error if there’s even the smallest compatibility issue - great for theme developers who want to publish their work, less great for people making 1 off themes who might not care.