action-electron-builder icon indicating copy to clipboard operation
action-electron-builder copied to clipboard

Cache deps

Open HaNdTriX opened this issue 5 years ago • 4 comments
trafficstars

Thanks a lot for sharing your code!


Issue

It would be awesome if we cache deps. This will speed up the process dramatically:

Cacheable Entries

  • node_modules
  • electron (ELECTRON_CACHE)
  • electron_builder (ELECTRON_BUILDER_CACHE)

Example

name: Release

on: [push]

jobs:
  test:
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: [macos-latest, windows-latest]
        # Lets use the preinstalled node version (much faster)
        node-version: [12.x]

    env:
      ELECTRON_CACHE: ${{ github.workspace }}/.cache/electron
      ELECTRON_BUILDER_CACHE: ${{ github.workspace }}/.cache/electron-builder

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v1

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}

      - name: Get yarn cache
        id: yarn-cache
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - name: Cache Node.js modules
        uses: actions/cache@v1
        with:
          path: ${{ steps.yarn-cache.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - name: Cache Electron
        uses: actions/cache@v1
        with:
          path: ${{ github.workspace }}/.cache/electron
          key: ${{ runner.os }}-electron-cache-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }}
          restore-keys: |
            ${{ runner.os }}-electron-cache-

      - name: Cache Electron-Builder
        uses: actions/cache@v1
        with:
          path: ${{ github.workspace }}/.cache/electron-builder
          key: ${{ runner.os }}-electron-builder-cache-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }}
          restore-keys: |
            ${{ runner.os }}-electron-builder-cache-

      - name: Install dependencies
        run: yarn install

      - name: Build Electron app
        uses: samuelmeuli/action-electron-builder@v1
        with:
          github_token: ${{ secrets.github_token }}

HaNdTriX avatar Jan 11 '20 13:01 HaNdTriX

If I understand this correctly, your approach is the correct way of implementing caching – it seems like it needs to be done on the workflow level, not on the action level.

Maybe adding an example to the README would help?

samuelmeuli avatar Jan 11 '20 15:01 samuelmeuli

@HaNdTriX Would you be interested in sharing your setup using a PR? :)

samuelmeuli avatar Jan 12 '20 22:01 samuelmeuli

@HaNdTriX @samuelmeuli , is the example above a working example of caching dependencies?

b-zurg avatar May 04 '20 22:05 b-zurg

the example provide install command, while action-electron-builder also automatic run install , from my experience I need custom install command , I use lock file which install from local registry , while on GitHub CI , I need install from original registry.

bung87 avatar Mar 26 '21 11:03 bung87