GitHub Action Cache with npm install -g (without package.json)

Viewed 644

Can Github Action cache be used to speedup globally installed node tools?

I am using semantic-release on a ruby repository and I don't want to pollute that repository with package.json

My configuration for semantic-release resides in .releaserc

I can run this GitAction to update my SemVer.

name: SemVer
on:
  push:
    branches: [ main ]
jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '16'

      - name: Install Global Dependencies
        run: npm -g install semantic-release @semantic-release/changelog @semantic-release/commit-analyzer @semantic-release/exec @semantic-release/git @semantic-release/release-notes-generator

      - name: Run SemVer
        run: semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

It takes 22 seconds to install dependencies

enter image description here

I have tried integrating cache configuration that I found into my workflow, but this is is not working and I assume it is because there is no package-lock.json to build a hash against.

key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

name: SemVer
on:
  push:
    branches: [ main ]
jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '16'

      - name: Cache node modules
        uses: actions/cache@v2
        id: cache-node-modules
        env:
          cache-name: cache-node-modules
        with:
          path: ~/.npm
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-build-${{ env.cache-name }}-
            ${{ runner.os }}-build-
            ${{ runner.os }}-

      - name: Install Global Dependencies
        if: steps.cache.outputs.cache-hit != 'true'
        run: npm -g install semantic-release @semantic-release/changelog @semantic-release/commit-analyzer @semantic-release/exec @semantic-release/git @semantic-release/release-notes-generator

      - name: Run SemVer
        run: semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

enter image description here

1 Answers
Related