forked from nf-core/modules
-
Notifications
You must be signed in to change notification settings - Fork 0
173 lines (156 loc) · 6.39 KB
/
Copy pathfix-linting.yml
File metadata and controls
173 lines (156 loc) · 6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: fix-linting
run-name: fix linting (automated)
on:
issue_comment:
types: [created]
permissions: {}
jobs:
prepare-fix:
# Only run if comment is on a PR with the main repo, and if it contains the magic keywords.
# The write token is used only before untrusted pull request code runs.
if: >
contains(github.event.comment.html_url, '/pull/') &&
contains(github.event.comment.body, '@nf-core-bot fix linting') &&
github.repository == 'nf-core/modules'
permissions:
contents: read
issues: write
pull-requests: read
runs-on: ubuntu-latest
outputs:
head_sha: ${{ steps.pr.outputs.head_sha }}
has_patch: ${{ steps.patch.outputs.has_patch }}
prek_outcome: ${{ steps.prek.outcome }}
steps:
# indication that the linting is being fixed
- name: React on comment
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
with:
comment-id: ${{ github.event.comment.id }}
reactions: eyes
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
# Action runs on the issue comment, so we don't get the PR by default.
# Use the gh cli to check out the PR.
- name: Checkout pull request
id: pr
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.issue.number }}
run: |
gh pr checkout "$PR_NUMBER"
echo "head_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Set up Nextflow
uses: nf-core/setup-nextflow@893c28b667aedeba26e37f296d260ccc5bc4d914 # v3
with:
version: "latest-stable"
- name: Run prek
id: prek
uses: j178/prek-action@4e14d07f9231acabce116ccfca13b13dd9755ece # v3.0.0
continue-on-error: true
- name: Create lint fix patch
id: patch
if: steps.prek.outcome == 'failure'
env:
PATCH_FILE: ${{ runner.temp }}/lint-fix.patch
run: |
git add --all
git diff --cached --binary --full-index --no-ext-diff > "$PATCH_FILE"
if [ ! -s "$PATCH_FILE" ]; then
echo "Prek failed without producing a fix."
exit 1
fi
echo "has_patch=true" >> "$GITHUB_OUTPUT"
- name: Upload lint fix patch
if: steps.patch.outputs.has_patch == 'true'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: lint-fix
path: ${{ runner.temp }}/lint-fix.patch
if-no-files-found: error
retention-days: 1
push-fix:
# This job runs on a fresh runner and never executes pull request code.
needs: prepare-fix
if: ${{ always() && needs.prepare-fix.result != 'skipped' }}
permissions:
actions: read
contents: read
issues: write
pull-requests: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
if: needs.prepare-fix.outputs.has_patch == 'true'
with:
persist-credentials: false
- name: Checkout exact pull request head
if: needs.prepare-fix.outputs.has_patch == 'true'
env:
EXPECTED_HEAD_SHA: ${{ needs.prepare-fix.outputs.head_sha }}
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.issue.number }}
run: |
gh pr checkout "$PR_NUMBER"
if [ "$(git rev-parse HEAD)" != "$EXPECTED_HEAD_SHA" ]; then
echo "The pull request head changed after prek ran."
exit 1
fi
- name: Download lint fix patch
if: needs.prepare-fix.outputs.has_patch == 'true'
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: lint-fix
path: ${{ runner.temp }}/lint-fix
- name: Apply lint fix patch
if: needs.prepare-fix.outputs.has_patch == 'true'
env:
PATCH_FILE: ${{ runner.temp }}/lint-fix/lint-fix.patch
run: |
if [ ! -f "$PATCH_FILE" ] || [ -L "$PATCH_FILE" ]; then
echo "The lint fix artifact does not contain a regular patch file."
exit 1
fi
git apply --check --index "$PATCH_FILE"
git apply --index "$PATCH_FILE"
- name: Commit and push changes
id: commit-and-push
if: needs.prepare-fix.outputs.has_patch == 'true'
env:
GH_TOKEN: ${{ secrets.nf_core_bot_auth_token }}
run: |
gh auth setup-git
git config user.email "core@nf-co.re"
git config user.name "nf-core-bot"
git config push.default upstream
git status
git -c core.hooksPath=/dev/null -c commit.gpgsign=false commit --no-verify -m "[automated] Fix code linting"
git -c core.hooksPath=/dev/null push --no-verify
# indication that the linting has finished
- name: React if linting finished successfully
if: needs.prepare-fix.outputs.prek_outcome == 'success'
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
with:
comment-id: ${{ github.event.comment.id }}
reactions: "+1"
- name: React if linting errors were fixed
if: steps.commit-and-push.outcome == 'success'
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
with:
comment-id: ${{ github.event.comment.id }}
reactions: hooray
- name: React if linting errors were not fixed
if: ${{ always() && (failure() || needs.prepare-fix.result != 'success') }}
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
with:
comment-id: ${{ github.event.comment.id }}
reactions: confused
- name: Comment if linting errors were not fixed
if: ${{ always() && (failure() || needs.prepare-fix.result != 'success') }}
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
with:
issue-number: ${{ github.event.issue.number }}
body: |
@${{ github.actor }} I tried to fix the linting errors, but it didn't work. Please fix them manually.
See [CI log](https://github.com/nf-core/modules/actions/runs/${{ github.run_id }}) for more details.