Home > database >  Understanding npm packages inside github actions
Understanding npm packages inside github actions

Time:02-14

Here is my idea: build a static web page template, over time add .md files to a /posts directory and build a CI job to convert the .md files to html (with the showdownjs/showdown package). Is there a need to install the package on every push? Seems like a waste, but uploading /node-modules is incorrect as well. Is there a way to install the package once, and let github action just work with it (run the md to html converter on newly added files)?

CodePudding user response:

You have 2 options:

  1. Recommened: Use caching action to cache dependencies for your project - using a hash from package-lock.json as a key to make sure it rebuild when depenendencies has changed:
- name: Cache node modules
  uses: actions/cache@v2
  env:
     cache-name: cache-node-modules
     with:
     # npm cache files are stored in `~/.npm` on Linux/macOS
     path: ~/.npm
     key: ${{ hashFiles('**/package-lock.json') }}

- name: Install Dependencies
  run: npm install
  1. Push your node_modules to Git repository so it's checkout together with everything else

For optimising a need to run your converted you can use this action:

https://github.com/tj-actions/changed-files/ and detect if any files were modified at certain path

  • Related