-
Notifications
You must be signed in to change notification settings - Fork 223
Pipeline template: New pre-commit hooks (large files, merge conflicts) #3935
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
base: dev
Are you sure you want to change the base?
Changes from all commits
a95fbb8
4babb88
0295768
8022ab4
7a2291e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #!/usr/bin/env bash | ||
| # This hook is used to block commits if they include staged files inside a directory | ||
| # which also contains a subdirectory called `pipeline_info`. The purpose of this is to | ||
| # prevent users from inadvertently committing output from pipeline test runs inside the | ||
| # development directory. | ||
|
|
||
| set -e | ||
|
|
||
| # list staged files | ||
| staged_files="$(git diff --cached --name-only)" | ||
|
|
||
| status=0 | ||
|
|
||
| for file in $staged_files; do | ||
| file_dir=$(dirname "$file") | ||
|
|
||
| # Walk up the directory tree and check if the current directory contains a subdirectory called `pipeline_info` | ||
| # or the staged file is itself inside a directory called `pipeline_info`. | ||
| while [ "$file_dir" != "." ] && [ "$file_dir" != "/" ]; do | ||
| if [ $(basename "$file_dir") == "pipeline_info" ] || [ -d "$file_dir/pipeline_info" ]; then | ||
| echo "❌ Commit blocked: Please do not commit output from pipeline test runs to the pipeline code itself." | ||
| echo "Use 'git restore --staged <file>...' to remove the output files from the staging area before proceeding." | ||
|
Comment on lines
+21
to
+22
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this also print out the offending path?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could change the script to print out $file, yes. However, I reckon that people may typically have added their whole output folder to the staging area and then it is more effective to remove all relevant files at once instead single files. I would, though, not want to make the call what that top-level folder is. |
||
| status=1 | ||
| break | ||
| fi | ||
| file_dir=$(dirname "$file_dir") | ||
| done | ||
| done | ||
|
|
||
| exit "$status" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,3 +25,20 @@ repos: | |
| subworkflows/nf-core/.*| | ||
| .*\.snap$ | ||
| )$ | ||
| - id: check-added-large-files | ||
| args: [--maxkb=5000] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the limit be defined as a variable somewhere and be used here? This would make it easier to adjust it for each pipeline, if necessary. Ideally it would be nice if it could be in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without needing another script, this file would be the place. |
||
| exclude: | | ||
| (?x)^( | ||
| .*ro-crate-metadata.json$| | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the RO crate be that big ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that was my logic. I just checked a semi-random selection of nf-core pipelines for the biggest files with the command given in the PR description and the RO-crate json was usually among the bigger files in a repo. Not that big, but I felt that it is safer to exclude it entirely as it is machine-generated. With the |
||
| .*\.snap$| | ||
| lib/nfcore_external_java_deps.jar$| | ||
| docs/.*\.(svg|pdf)$| | ||
| assets/.*$ | ||
| )$ | ||
| - id: check-merge-conflict | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have already https://nf-co.re/docs/nf-core-tools/api_reference/dev/pipeline_lint_tests/merge_markers, but this is a nicer approach
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main motivation for this PR was evidently the check-added-large-files. Phil just recommended to use the other one as well, because he has it on the MultiQC repo. If you think that I shouldn't bundle them in one PR to allow separate decisions, I am fine with removing it as well. |
||
| - repo: local | ||
| hooks: | ||
| - id: block-pipeline-outdir | ||
| name: Prevent committing output from pipeline test runs to the pipeline code itself | ||
| entry: ./.hooks/block_pipeline_outdir.sh | ||
| language: script | ||
Uh oh!
There was an error while loading. Please reload this page.