Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache problem with Node.js #45

Closed
KOliver94 opened this issue Sep 7, 2020 · 5 comments
Closed

Cache problem with Node.js #45

KOliver94 opened this issue Sep 7, 2020 · 5 comments

Comments

@KOliver94
Copy link

Hi everybody,

I noticed a problem with pre-commit action's cache and using Node.js environment. I'm using eslint in pre-commit and to make eslint-plugin-import work properly I need to install the dependencies. So, my workflow looks the following:

jobs:
  pre-commit:
    name: Pre-commit hooks
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Set up Python 3.8
      uses: actions/setup-python@v2
      with:
        python-version: '3.8'
    - name: Use Node.js 14
      uses: actions/setup-node@v2-beta
      with:
        node-version: '14'
    - name: Cache Node.js modules
      uses: actions/cache@v2
      with:
        path: ~/.npm
        key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
        restore-keys: |
          ${{ runner.OS }}-node-
          ${{ runner.OS }}-
    - name: Install frontend dependencies
      run: npm install
      working-directory: frontend
    - name: Run pre-commit hooks
      uses: pre-commit/action@v2.0.0

The problem is that because I only use node-version: '14' in the setup-node phase the Node.js version will change after a while to a newer version but the pre-commit action's cache does not care for that and tries to use a cached version where a previous version of Node.js was used and the following error occurs:

eslint...................................................................Failed
- hook id: eslint
- exit code: 127

/home/runner/.cache/pre-commit/repoibq27hfw/node_env-system/bin/node: line 5: /opt/hostedtoolcache/node/14.8.0/x64/bin/node: No such file or directory
/home/runner/.cache/pre-commit/repoibq27hfw/node_env-system/bin/node: line 5: /opt/hostedtoolcache/node/14.8.0/x64/bin/node: No such file or directory

##[error]The process '/opt/hostedtoolcache/Python/3.8.5/x64/bin/pre-commit' failed with exit code 1

and I can see that the setup-node used version 14.9.0.

Run actions/setup-node@v2-beta
version: 14
Found in cache @ /opt/hostedtoolcache/node/14.9.0/x64

I used a "workaround" a specified a fully qualified node-version but I don't think this is the best solution. Is there any way to either disable the cache or make it sensitive for the Node.js version?

Thanks!

@asottile
Copy link
Member

asottile commented Sep 7, 2020

here's what we do for python:

action/index.js

Lines 52 to 53 in ef992f5

const py = getPythonVersion();
const cacheKey = `pre-commit-2-${hashString(py)}-${hashFile('.pre-commit-config.yaml')}`;

@FrancoisFerrariKpler
Copy link

FrancoisFerrariKpler commented Oct 5, 2020

Hi,
I have the same problem but using graphQL, and as I'm new to both typescript and graphQL, I have not yet been able to figure out what to do exactly to solve this problem.

I have tried to add a uses: actions/cache@v2 line in my .yml file but I think I'm missing the details of what is the action/index.js file you are mentioning above, where to create it, and what to put in this file for a typescript/graphql implementation ?

Would you have some hints to help me ?

Below is my .github/workflows/pre-commit.yml file:
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/setup-node@v2-beta
with:
node-version: 12
check-latest: true
- run: npm install
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- uses: pre-commit/action@v2.0.0

And it fails with:
/opt/hostedtoolcache/Python/3.8.5/x64/bin/pre-commit run --show-diff-on-failure --color=always --all-files
Check Yaml...............................................................Passed
Fix End of Files.........................................................Passed
Trim Trailing Whitespace.................................................Passed
Don't commit to branch...................................................Passed
CRLF end-lines checker...................................................Passed
CRLF end-lines remover...................................................Passed
Check hooks apply to the repository......................................Passed
Check for useless excludes...............................................Passed
Prettier.................................................................Failed

  • hook id: prettier
  • exit code: 127

/home/runner/.cache/pre-commit/repon7pcj2u6/node_env-system/bin/node: line 5: /opt/hostedtoolcache/node/12.18.3/x64/bin/node: No such file or directory
/home/runner/.cache/pre-commit/repon7pcj2u6/node_env-system/bin/node: line 5: /opt/hostedtoolcache/node/12.18.3/x64/bin/node: No such file or directory

ESLint...................................................................Passed
Error: The process '/opt/hostedtoolcache/Python/3.8.5/x64/bin/pre-commit' failed with exit code 1

@asottile
Copy link
Member

asottile commented Oct 5, 2020

this should be fixed already in the latest version of pre-commit, what version are you running?

@ineiti
Copy link

ineiti commented Nov 27, 2020

Running pre-commit/action@2.0.0 using a matrix here, and it still fails...

@asottile
Copy link
Member

then I'd recommend you try out https://pre-commit.ci instead -- it has better features anyway and github's stuff is probably un-repairably broken

you also haven't shown any output so I can't know whether this is the same issue or not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants