Have you read the last post? Good, we can crack on with the automation! First up, create a new file at
.github/workflows/jsdoc.yml which is where the GitHub Action config will live:
name: Jsdocs on: push: branches: - main jobs: generate-jsdocs: runs-on: ubuntu-latest defaults: run: shell: bash working-directory: docs/jsdoc steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: "14" - name: Install and build docs run: | yarn install yarn build_jsdoc - name: Commit changes in jsdoc build folder run: | git config --global user.name "GitHub Actions" git config --global user.email "email@example.com" git add ./build git commit -m "Updating Jsdoc documentation" || echo "No changes to commit" git push
This GitHub Action will only trigger on pushes to my main branch as I only want to update my documentation when I have deployed to production. The action will use
docs/jsdoc as my working directory so all other commands will be relative to that directory. All dependencies are installed and
yarn build_jsdoc builds my static site in the
build directory as dictated by the script in
package.json. Finally, only changes in the
build directory are committed and then pushed to production.
docs/jsdoc folder. The GitHub Action will also kick in at this point and run the above steps. There are now changes in
docs/jsdoc so the Netlify build for https://jsdocs.jeffreyknox.dev/ will run all the way through this time. However the Netlify build for https://www.jeffreyknox.dev/ will also run again even though the only changes are in
docs/jsdoc and have no effect on this site.
Still with me?! I wanted to prevent this final unnecessary build so in the root of my repo I updated the
netlify.toml file to include a new
[build] ... ignore = "git show -s --format=%s | grep 'Updating Jsdoc documentation'" ...
So now if my commit message includes "Updating Jsdoc documentation" then the build will be cancelled for my https://www.jeffreyknox.dev/ site. At this point I also updated my
netlify.toml file in the
docs/jsdoc folder to look as follows:
[build] ... ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ." ...
so it continues to only run a Netlify build if there are changes in the