Skip to content

Commit 299a7f3

Browse files
committed
Add 'fix-linting' workflow also from nf-core/website
1 parent 2610d68 commit 299a7f3

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

.github/workflows/fix-linting.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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
36+
with:
37+
python-version: 3.11
38+
39+
# install prettier plugins
40+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
41+
with:
42+
node-version: 20
43+
- run: npm install --only=dev
44+
45+
- name: Install pre-commit
46+
run: pip install pre-commit
47+
48+
- name: Run pre-commit
49+
id: pre-commit
50+
run: pre-commit run --all-files
51+
continue-on-error: true
52+
53+
# indication that the linting has finished
54+
- name: react if linting finished succesfully
55+
if: steps.pre-commit.outcome == 'success'
56+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
57+
with:
58+
comment-id: ${{ github.event.comment.id }}
59+
reactions: "+1"
60+
61+
- name: Commit & push changes
62+
id: commit-and-push
63+
if: steps.pre-commit.outcome == 'failure'
64+
run: |
65+
git config user.email "[email protected]"
66+
git config user.name "nf-core-bot"
67+
git config push.default upstream
68+
git add .
69+
git status
70+
git commit -m "[automated] Fix code linting"
71+
git push
72+
73+
- name: react if linting errors were fixed
74+
id: react-if-fixed
75+
if: steps.commit-and-push.outcome == 'success'
76+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
77+
with:
78+
comment-id: ${{ github.event.comment.id }}
79+
reactions: hooray
80+
81+
- name: react if linting errors were not fixed
82+
if: steps.commit-and-push.outcome == 'failure'
83+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
84+
with:
85+
comment-id: ${{ github.event.comment.id }}
86+
reactions: confused
87+
88+
- name: react if linting errors were not fixed
89+
if: steps.commit-and-push.outcome == 'failure'
90+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
91+
with:
92+
issue-number: ${{ github.event.issue.number }}
93+
body: |
94+
@${{ github.actor }} I tried to fix the linting errors, but it didn't work. Please fix them manually.
95+
See [CI log](https://github.com/nf-core/website/actions/runs/${{ github.run_id }}) for more details.

0 commit comments

Comments
 (0)