Skip to content

Commit d26a453

Browse files
authored
Merge pull request #34 from ewels/alt-pre-commit
Pre-commit setup from nf-core/website instead of tools
2 parents 8c511be + 39a8734 commit d26a453

File tree

2 files changed

+95
-15
lines changed

2 files changed

+95
-15
lines changed

.github/workflows/fix-linting.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Fix linting from a comment
2+
on:
3+
issue_comment:
4+
types: [created]
5+
6+
jobs:
7+
deploy:
8+
# Only run if comment is on a PR with the main repo, and if it contains the magic keywords
9+
if: >
10+
contains(github.event.comment.html_url, '/pull/') &&
11+
contains(github.event.comment.body, '@nf-core-bot fix linting') &&
12+
github.repository == 'nf-core/proposals'
13+
runs-on: ubuntu-latest
14+
steps:
15+
# Use the @nf-core-bot token to check out so we can push later
16+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
17+
with:
18+
token: ${{ secrets.nf_core_bot_auth_token }}
19+
20+
# indication that the linting is being fixed
21+
- name: React on comment
22+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
23+
with:
24+
comment-id: ${{ github.event.comment.id }}
25+
reactions: eyes
26+
27+
# Action runs on the issue comment, so we don't get the PR by default
28+
# Use the gh cli to check out the PR
29+
- name: Checkout Pull Request
30+
run: gh pr checkout ${{ github.event.issue.number }}
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.nf_core_bot_auth_token }}
33+
34+
# Install and run pre-commit
35+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6
36+
with:
37+
python-version: 3.11
38+
39+
- name: Install pre-commit
40+
run: pip install pre-commit
41+
42+
- name: Run pre-commit
43+
id: pre-commit
44+
run: pre-commit run --all-files
45+
continue-on-error: true
46+
47+
# indication that the linting has finished
48+
- name: react if linting finished succesfully
49+
if: steps.pre-commit.outcome == 'success'
50+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
51+
with:
52+
comment-id: ${{ github.event.comment.id }}
53+
reactions: "+1"
54+
55+
- name: Commit & push changes
56+
id: commit-and-push
57+
if: steps.pre-commit.outcome == 'failure'
58+
run: |
59+
git config user.email "[email protected]"
60+
git config user.name "nf-core-bot"
61+
git config push.default upstream
62+
git add .
63+
git status
64+
git commit -m "[automated] Fix code linting"
65+
git push
66+
67+
- name: react if linting errors were fixed
68+
id: react-if-fixed
69+
if: steps.commit-and-push.outcome == 'success'
70+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
71+
with:
72+
comment-id: ${{ github.event.comment.id }}
73+
reactions: hooray
74+
75+
- name: react if linting errors were not fixed
76+
if: steps.commit-and-push.outcome == 'failure'
77+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
78+
with:
79+
comment-id: ${{ github.event.comment.id }}
80+
reactions: confused
81+
82+
- name: react if linting errors were not fixed
83+
if: steps.commit-and-push.outcome == 'failure'
84+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
85+
with:
86+
issue-number: ${{ github.event.issue.number }}
87+
body: |
88+
@${{ github.actor }} I tried to fix the linting errors, but it didn't work. Please fix them manually.
89+
See [CI log](https://github.com/nf-core/website/actions/runs/${{ github.run_id }}) for more details.

.github/workflows/pre-commit.yml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
name: Lint tools code formatting
1+
name: Lint code
22
on:
33
push:
4+
branches:
5+
- main
46
pull_request:
57

6-
# Cancel if a newer run is started
7-
concurrency:
8-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
9-
cancel-in-progress: true
10-
118
jobs:
12-
Pre-commit:
9+
pre-commit:
1310
runs-on: ubuntu-latest
14-
env:
15-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1611
steps:
1712
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
18-
19-
- name: Set up Python 3.12
20-
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5
13+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6
2114
with:
22-
python-version: "3.12"
23-
cache: "pip"
24-
15+
python-version: 3.11
2516
- name: Install pre-commit
2617
run: pip install pre-commit
2718

0 commit comments

Comments
 (0)