From 4090df2ca7d6d0d0bf41a6da8ba4ec38e8e6faba Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 5 Jan 2024 10:07:00 +0100 Subject: [PATCH 1/6] use pre-commit for all linting jobs # Conflicts: # .github/workflows/lint-code.yml # .pre-commit-config.yaml --- .github/workflows/create-lint-wf.yml | 25 +------ .../create-test-lint-wf-template.yml | 19 +----- .github/workflows/fix-linting.yml | 24 ++----- .github/workflows/lint-code.yml | 27 +------- .pre-commit-config.yaml | 11 +++- .../.github/workflows/fix-linting.yml | 29 ++++----- .../.github/workflows/linting.yml | 65 ++----------------- .../pipeline-template/.pre-commit-config.yaml | 7 +- 8 files changed, 46 insertions(+), 161 deletions(-) diff --git a/.github/workflows/create-lint-wf.yml b/.github/workflows/create-lint-wf.yml index 786a9a7f79..98e887b36b 100644 --- a/.github/workflows/create-lint-wf.yml +++ b/.github/workflows/create-lint-wf.yml @@ -35,6 +35,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.11 + cache: pip - name: Install python dependencies run: | @@ -47,19 +48,6 @@ jobs: with: version: ${{ matrix.NXF_VER }} - # Install the Prettier linting tools - - uses: actions/setup-node@v4 - with: - node-version: "20" - - - name: Install Prettier and editorconfig-checker - run: npm install -g prettier editorconfig-checker - - - name: Install ruff - run: | - python -m pip install --upgrade pip - pip install ruff - # Build a pipeline from the template - name: nf-core create run: | @@ -78,15 +66,8 @@ jobs: working-directory: create-lint-wf # Run code style linting - - name: Run Prettier --check - run: prettier --check create-lint-wf/nf-core-testpipeline - - - name: Run Ruff check - run: ruff check create-lint-wf/nf-core-testpipeline - - name: Run Ruff format - run: ruff format create-lint-wf/nf-core-testpipeline - - name: Run ECLint check - run: editorconfig-checker -exclude README.md $(find nf-core-testpipeline/.* -type f | grep -v '.git\|.py\|md\|json\|yml\|yaml\|html\|css\|work\|.nextflow\|build\|nf_core.egg-info\|log.txt\|Makefile') + - name: run pre-commit + run: pre-commit run --all-files working-directory: create-lint-wf # Update modules to the latest version diff --git a/.github/workflows/create-test-lint-wf-template.yml b/.github/workflows/create-test-lint-wf-template.yml index 37cbf65c7d..0dba0543d2 100644 --- a/.github/workflows/create-test-lint-wf-template.yml +++ b/.github/workflows/create-test-lint-wf-template.yml @@ -51,18 +51,6 @@ jobs: with: version: latest-everything - # Install the Prettier linting tools - - uses: actions/setup-node@v4 - with: - node-version: "20" - - - name: Install Prettier - run: npm install -g prettier - - # Install the editorconfig linting tools - - name: Install editorconfig-checker - run: npm install -g editorconfig-checker - # Create template files - name: Create template skip all (except github) run: | @@ -107,11 +95,8 @@ jobs: run: nf-core --log-file log.txt sync --dir create-test-lint-wf/my-prefix-testpipeline/ # Run code style linting - - name: Run Prettier --check - run: prettier --check create-test-lint-wf/my-prefix-testpipeline - - - name: Run ECLint check - run: editorconfig-checker -exclude README.md $(find my-prefix-testpipeline/.* -type f | grep -v '.git\|.py\|md\|json\|yml\|yaml\|html\|css\|work\|.nextflow\|build\|nf_core.egg-info\|log.txt\|Makefile') + - name: Run pre-commit + run: pre-commit run --all-files working-directory: create-test-lint-wf # Remove TODO statements diff --git a/.github/workflows/fix-linting.yml b/.github/workflows/fix-linting.yml index ad3383097a..cb7cf47187 100644 --- a/.github/workflows/fix-linting.yml +++ b/.github/workflows/fix-linting.yml @@ -24,29 +24,17 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.nf_core_bot_auth_token }} - - uses: actions/setup-node@v4 - with: - node-version: "20" - - - name: Install Prettier - run: npm install -g prettier @prettier/plugin-php - - - name: Run 'prettier --write' - run: prettier --write ${GITHUB_WORKSPACE} - - name: Set up Python 3.11 uses: actions/setup-python@v4 with: python-version: 3.11 + cache: "pip" - - name: Install Ruff - run: | - python -m pip install --upgrade pip - pip install ruff - - name: Run Ruff - run: | - ruff check --fix . - ruff format . + - name: Install pre-commit + run: pip install pre-commit + + - name: Run pre-commit + run: pre-commit run --all-files - name: Commit & push changes run: | diff --git a/.github/workflows/lint-code.yml b/.github/workflows/lint-code.yml index 43311848ad..cc69408334 100644 --- a/.github/workflows/lint-code.yml +++ b/.github/workflows/lint-code.yml @@ -100,28 +100,5 @@ jobs: python -m pip install --upgrade pip -r requirements-dev.txt pip install -e . - - name: Cache nf-test installation - id: cache-software - uses: actions/cache@v3 - with: - path: | - /usr/local/bin/nf-test - /home/runner/.nf-test/nf-test.jar - key: ${{ runner.os }}-${{ env.NFTEST_VER }}-nftest - - - name: Install nf-test - if: steps.cache-software.outputs.cache-hit != 'true' - run: | - wget -qO- https://code.askimed.com/install/nf-test | bash - sudo mv nf-test /usr/local/bin/ - - - name: Get Python changed files - id: changed-py-files - uses: tj-actions/changed-files@v23 - with: - files: | - *.py - **/*.py - - name: Run if any of the listed files above is changed - if: steps.changed-py-files.outputs.any_changed == 'true' - run: mypy ${{ steps.changed-py-files.outputs.all_changed_files }} + - name: Run pre-commit + run: pre-commit run --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8dc52f06fe..fb2a67bace 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,11 +6,18 @@ repos: args: [--fix, --exit-non-zero-on-fix] # sort imports and fix - id: ruff-format # formatter - repo: https://github.com/pre-commit/mirrors-prettier - rev: "v2.7.1" + rev: "v3.1.0" hooks: - id: prettier + + - repo: https://github.com/editorconfig-checker/editorconfig-checker.python + rev: "2.7.3" + hooks: + - id: editorconfig-checker + alias: ec + - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.8.0" # Use the sha / tag you want to point at + rev: "v1.8.0" hooks: - id: mypy additional_dependencies: diff --git a/nf_core/pipeline-template/.github/workflows/fix-linting.yml b/nf_core/pipeline-template/.github/workflows/fix-linting.yml index 31e8cd2b36..d9986bd30f 100644 --- a/nf_core/pipeline-template/.github/workflows/fix-linting.yml +++ b/nf_core/pipeline-template/.github/workflows/fix-linting.yml @@ -24,32 +24,25 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.nf_core_bot_auth_token }} - - uses: actions/setup-node@v4 - - - name: Install Prettier - run: npm install -g prettier @prettier/plugin-php + - name: Set up Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: 3.11 + cache: "pip" - # Check that we actually need to fix something - - name: Run 'prettier --check' - id: prettier_status - run: | - if prettier --check ${GITHUB_WORKSPACE}; then - echo "result=pass" >> $GITHUB_OUTPUT - else - echo "result=fail" >> $GITHUB_OUTPUT - fi + - name: Install pre-commit + run: pip install pre-commit - - name: Run 'prettier --write' - if: steps.prettier_status.outputs.result == 'fail' - run: prettier --write ${GITHUB_WORKSPACE} + - name: Run pre-commit + run: pre-commit run --all-files || echo "status=fail" >> $GITHUB_ENV - name: Commit & push changes - if: steps.prettier_status.outputs.result == 'fail' + if: env.status == 'fail' run: | git config user.email "core@nf-co.re" git config user.name "nf-core-bot" git config push.default upstream git add . git status - git commit -m "[automated] Fix linting with Prettier" + git commit -m "[automated] Fix linting with pre-commit" git push {%- endraw %} diff --git a/nf_core/pipeline-template/.github/workflows/linting.yml b/nf_core/pipeline-template/.github/workflows/linting.yml index 1cd46a1920..da6726a441 100644 --- a/nf_core/pipeline-template/.github/workflows/linting.yml +++ b/nf_core/pipeline-template/.github/workflows/linting.yml @@ -11,73 +11,22 @@ on: types: [published] jobs: - EditorConfig: + pre-commit: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - - - name: Install editorconfig-checker - run: npm install -g editorconfig-checker - - - name: Run ECLint check - run: editorconfig-checker -exclude README.md $(find .* -type f | grep -v '.git\|.py\|.md\|json\|yml\|yaml\|html\|css\|work\|.nextflow\|build\|nf_core.egg-info\|log.txt\|Makefile') - - Prettier: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - - - name: Install Prettier - run: npm install -g prettier - - - name: Run Prettier --check - run: prettier --check ${GITHUB_WORKSPACE} - - Ruff: - runs-on: ["self-hosted"] - steps: - - name: Check out source-code repository - uses: actions/checkout@v4 - - name: Set up Python 3.11 - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: 3.11 - - name: Install Ruff - run: | - python -m pip install --upgrade pip - pip install ruff - - name: Run Ruff check - run: ruff check . - - - name: Run Ruff format - run: ruff format . - - # If the above check failed, post a comment on the PR explaining the failure - - name: Post PR comment - if: failure() - uses: mshick/add-pr-comment@v2 - with: - message: | - ## Python linting (`ruff`) is failing - - To keep the code consistent with lots of contributors, we run automated code consistency checks. - To fix this CI test, please run: - - * Install [`ruff`](https://github.com/astral-sh/ruff): `pip install ruff` - * Fix formatting errors in your pipeline: `ruff check --fix .` and `ruff format .` - - Once you push these changes the test should pass, and you can hide this comment :+1: + cache: "pip" - We highly recommend setting up Ruff in your code editor so that this formatting is done automatically on save. Ask about it on Slack for help! + - name: Install pre-commit + run: pip install pre-commit - Thanks again for your contribution! - repo-token: ${{ secrets.GITHUB_TOKEN }} - allow-repeats: false + - name: Run pre-commit + run: pre-commit run --all-files nf-core: runs-on: ubuntu-latest diff --git a/nf_core/pipeline-template/.pre-commit-config.yaml b/nf_core/pipeline-template/.pre-commit-config.yaml index 0c31cdb99f..984321ff26 100644 --- a/nf_core/pipeline-template/.pre-commit-config.yaml +++ b/nf_core/pipeline-template/.pre-commit-config.yaml @@ -1,5 +1,10 @@ repos: - repo: https://github.com/pre-commit/mirrors-prettier - rev: "v2.7.1" + rev: "v3.1.1" hooks: - id: prettier + - repo: https://github.com/editorconfig-checker/editorconfig-checker.python + rev: "2.7.3" + hooks: + - id: editorconfig-checker + alias: ec From f58fd5cff57a050b93d26f0d66c93c43257d8233 Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 5 Jan 2024 10:07:16 +0100 Subject: [PATCH 2/6] fix editorconfig --- .editorconfig | 4 ++++ docs/api/Makefile | 4 ++-- nf_core/pipeline-template/.editorconfig | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index 014c2383bd..eaf7834976 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,3 +10,7 @@ indent_style = space [*.{md,yml,yaml,html,css,scss,js,cff}] indent_size = 2 + +# ignore python and markdown files +[*.{py,md}] +indent_style = unset diff --git a/docs/api/Makefile b/docs/api/Makefile index f961e4ded1..69f3987065 100644 --- a/docs/api/Makefile +++ b/docs/api/Makefile @@ -9,11 +9,11 @@ BUILDDIR = _build # Put it first so that "make" without argument is like "make help". help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) .PHONY: help Makefile # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/nf_core/pipeline-template/.editorconfig b/nf_core/pipeline-template/.editorconfig index b6b3190776..9b990088ab 100644 --- a/nf_core/pipeline-template/.editorconfig +++ b/nf_core/pipeline-template/.editorconfig @@ -22,3 +22,11 @@ indent_size = unset [/assets/email*] indent_size = unset + +# ignore Readme +[README.md] +indent_style = unset + +# ignore python +[*.{py}] +indent_style = unset From 8d9c38116075a8bc032013bee3cfc62fee40666a Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 5 Jan 2024 10:12:20 +0100 Subject: [PATCH 3/6] fix .editorconfig and makefile --- .editorconfig | 8 +++++++- docs/api/Makefile | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.editorconfig b/.editorconfig index eaf7834976..449f446a3b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,5 +12,11 @@ indent_style = space indent_size = 2 # ignore python and markdown files -[*.{py,md}] +[*.py] +indent_style = unset + +[**/{CONTRIBUTING,README}.md] +indent_style = unset + +[**/Makefile] indent_style = unset diff --git a/docs/api/Makefile b/docs/api/Makefile index 69f3987065..ab30a5051e 100644 --- a/docs/api/Makefile +++ b/docs/api/Makefile @@ -9,11 +9,11 @@ BUILDDIR = _build # Put it first so that "make" without argument is like "make help". help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) .PHONY: help Makefile # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) From 3fad2329418fe22cfe8d9d04943a3a905cd79611 Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 5 Jan 2024 10:19:54 +0100 Subject: [PATCH 4/6] use pre-commit for tools job as well --- .github/workflows/lint-code.yml | 78 ++------------------------------- 1 file changed, 3 insertions(+), 75 deletions(-) diff --git a/.github/workflows/lint-code.yml b/.github/workflows/lint-code.yml index cc69408334..69ad009851 100644 --- a/.github/workflows/lint-code.yml +++ b/.github/workflows/lint-code.yml @@ -13,81 +13,9 @@ concurrency: cancel-in-progress: true jobs: - EditorConfig: - runs-on: ["self-hosted"] - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - with: - node-version: "20" - - - name: Install editorconfig-checker - run: npm install -g editorconfig-checker - - # Run editor config check only on files not covered by a linter - - name: Run ECLint check - run: editorconfig-checker -exclude README.md $(git ls-files | grep -v 'test\|.py\|md\|json\|yml\|yaml\|html\|css\|Makefile') - - Prettier: - runs-on: ["self-hosted"] - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - with: - node-version: "20" - - - name: Install Prettier - run: npm install -g prettier - - - name: Run Prettier --check - run: prettier --check ${GITHUB_WORKSPACE} - - Ruff: - runs-on: ["self-hosted"] - steps: - - name: Check out source-code repository - uses: actions/checkout@v4 - - - name: Set up Python 3.11 - uses: actions/setup-python@v4 - with: - python-version: 3.11 - - name: Install Ruff - run: | - python -m pip install --upgrade pip - pip install ruff - - name: Run Ruff check - run: ruff check . - - - name: Run Ruff format - run: ruff format . - - # If the above check failed, post a comment on the PR explaining the failure - - name: Post PR comment - if: failure() - uses: mshick/add-pr-comment@v2 - with: - message: | - ## Python linting (`ruff`) is failing - - To keep the code consistent with lots of contributors, we run automated code consistency checks. - To fix this CI test, please run: - - * Install [`ruff`](https://github.com/astral-sh/ruff): `pip install ruff` - * Fix formatting errors in your pipeline: `ruff check --fix .` and `ruff format .` - - Once you push these changes the test should pass, and you can hide this comment :+1: - - We highly recommend setting up Ruff in your code editor so that this formatting is done automatically on save. Ask about it on Slack for help! - - Thanks again for your contribution! - repo-token: ${{ secrets.GITHUB_TOKEN }} - allow-repeats: false - - static-type-check: - runs-on: ["self-hosted"] + Pre-commit: + name: Pre-commit + runs-on: ["ubuntu-latest"] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v4 From f05b8643ca6304d721b393cf2d49ead4ba4974bf Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 5 Jan 2024 10:53:24 +0100 Subject: [PATCH 5/6] set python version in changelog job --- .github/workflows/changelog.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 11db7939d9..01d86fad98 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -35,6 +35,8 @@ jobs: gh pr checkout $PR_NUMBER - uses: actions/setup-python@v5 + with: + python-version: "3.11" - name: Install packages run: | From acfb4f7ac91217ffc0bc12bfac3916dffb9218c6 Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 5 Jan 2024 10:58:44 +0100 Subject: [PATCH 6/6] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a88a14265..2c8f522fe4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Rename `release-announcments.yml` to `release-announcements.yml` ([#2610](https://github.com/nf-core/tools/pull/2610)) - Fix `nextflow.config` `docker.runOptions` ([#2607](https://github.com/nf-core/tools/pull/2607)) +- Use `pre-commit` to lint files in GitHub CI ([#2635](https://github.com/nf-core/tools/pull/2635)) ### General