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

Precommit can run multiple times in parallel, preventing the hook to pass #92

Closed
Brawdunoir opened this issue Jan 10, 2024 · 0 comments · Fixed by #93
Closed

Precommit can run multiple times in parallel, preventing the hook to pass #92

Brawdunoir opened this issue Jan 10, 2024 · 0 comments · Fixed by #93
Assignees

Comments

@Brawdunoir
Copy link
Contributor

Hello, I am sometimes getting a ERROR: error getting current Parameters section from README when using the precommit hook given in the README.

Problem

I experienced precommit running in parallel multiple instance of the javascript code in some setup.
Because it was running several times in parallel, I sometimes ended up with a failing job (race condition ?):

INFO: Inserting the new table into the README...
INFO: Checking missing metadata...
INFO: Metadata is correct!
INFO: Found parameters section at line: 3
INFO: The parameters section seems to be the last section in the file
INFO: Last parameter table line found at line: 190
chart/README.md # console.log(readmeFilePath)
[ 3, 190 ] # console.log(paramsSectionLimits);
INFO: Inserting the new table into the README...
INFO: Checking missing metadata...
INFO: Metadata is correct!
chart/README.md # console.log(readmeFilePath)
[] # console.log(paramsSectionLimits);
ERROR: error getting current Parameters section from README. Limits: 0
/home/lacroix/.cache/pre-commit/repodm9qdawz/node_env-default/lib/node_modules/@bitnami/readme-generator-for-helm/lib/render.js:123
    throw new Error('ERROR: error getting current Parameters section from README');
    ^

Error: ERROR: error getting current Parameters section from README
    at insertReadmeTable (/home/lacroix/.cache/pre-commit/repodm9qdawz/node_env-default/lib/node_modules/@bitnami/readme-generator-for-helm/lib/render.js:123:11)
    at runReadmeGenerator (/home/lacroix/.cache/pre-commit/repodm9qdawz/node_env-default/lib/node_modules/@bitnami/readme-generator-for-helm/index.js:59:7)
    at Object.<anonymous> (/home/lacroix/.cache/pre-commit/repodm9qdawz/node_env-default/lib/node_modules/@bitnami/readme-generator-for-helm/bin/index.js:22:1)
    at Module._compile (node:internal/modules/cjs/loader:1375:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1434:10)
    at Module.load (node:internal/modules/cjs/loader:1206:32)
    at Module._load (node:internal/modules/cjs/loader:1022:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
    at node:internal/main/run_main_module:28:49

I added some console.log to the code to see what’s going on.

Solution

On the client side, just add some hook options solves the problem:

hooks:
      - id: helm-readme-generator
        pass_filenames: false
        always_run: true

This prevent precommit to run multiple times (see (see pre-commit/pre-commit#1636).

We should update the README.md to add this options to the hook.

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

Successfully merging a pull request may close this issue.

2 participants