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

Use pre commit for linting jobs #2635

Merged
merged 7 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@ indent_style = space

[*.{md,yml,yaml,html,css,scss,js,cff}]
indent_size = 2

# ignore python and markdown files
[*.py]
indent_style = unset

[**/{CONTRIBUTING,README}.md]
indent_style = unset

[**/Makefile]
indent_style = unset
2 changes: 2 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
gh pr checkout $PR_NUMBER
- uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install packages
run: |
Expand Down
25 changes: 3 additions & 22 deletions .github/workflows/create-lint-wf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: 3.11
cache: pip

- name: Install python dependencies
run: |
Expand All @@ -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: |
Expand All @@ -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
Expand Down
19 changes: 2 additions & 17 deletions .github/workflows/create-test-lint-wf-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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
Expand Down
24 changes: 6 additions & 18 deletions .github/workflows/fix-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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@v5
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: |
Expand Down
105 changes: 5 additions & 100 deletions .github/workflows/lint-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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@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:

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@v5
Expand All @@ -100,28 +28,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
11 changes: 9 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ help:
# 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)
8 changes: 8 additions & 0 deletions nf_core/pipeline-template/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 11 additions & 18 deletions nf_core/pipeline-template/.github/workflows/fix-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Loading
Loading