practicalli / clojure

Practicalli Clojure REPL Driven Development
https://practical.li/clojure/
Creative Commons Attribution Share Alike 4.0 International
91 stars 36 forks source link

Add cache for Gitbook node modules to speed up book build #427

Closed practicalli-johnny closed 2 years ago

practicalli-johnny commented 2 years ago

Add a simple cache action configuration to the .github/workflows/publish-website.yaml workflow

      - name: Node Cache
        uses: actions/cache@v3
        with:
          path: '**/node_modules'
          key: cache-${{ hashFiles('**/book.json') }}

Reference: https://github.com/actions/cache/blob/main/examples.md#node---npm

Test that the Gitbook plugins and other node_modules are being cached on successive builds

practicalli-johnny commented 2 years ago

.github/workflows/publish-website.yaml configuration updated and pushed to see if cache is created.

practicalli-johnny commented 2 years ago

Cache is working on the initial run

image

Cache is not finding the path, so an update is required

image

practicalli-johnny commented 2 years ago

In the GitHub actions the setting up of Gitbook and building the book takes nearly 6 minutes without a cache

info: >> generation finished with success in 336.7s ! 

Setting the path using npm looks promising

      - name: Get npm cache directory
        id: npm-cache-dir
        run: |
          echo "::set-output name=dir::$(npm config get cache)"

image

practicalli-johnny commented 2 years ago

Cache is being restored successfully in subsequent runs of the Gitbook Publish workflow

image

The cache does save around 1 minute in build time. However, it seems most of the build time is due to installing Gitbook and its very many modules.

Further improvements in deployment time may come from creating a Docker image with Gitbook already installed along with all the plugins needed. This could then be cached by docker itself and would speed up builds.

TODO: Create separate issue to develop a Gitbook Docker image with relevant plugins pre-installed and use that as the basis of the Gitbook Publisher action