Skip to content

Commit 25b8a05

Browse files
committed
add pre-commit + CI to flag file deletions
1 parent c645fe2 commit 25b8a05

4 files changed

Lines changed: 126 additions & 0 deletions

File tree

.github/renovate.json5

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
$schema: "https://docs.renovatebot.com/renovate-schema.json",
3+
extends: ["github>nf-core/ops//.github/renovate/default.json5"],
4+
baseBranchPatterns: ["master"],
5+
}

.github/workflows/fix-linting.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Fix linting from a comment
2+
on:
3+
issue_comment:
4+
types: [created]
5+
6+
jobs:
7+
fix-linting:
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/test-datasets'
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@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6
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@e8674b075228eee787fea43ef493e45ece1004c9 # v5
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 prek
35+
- name: Run prek
36+
id: prek
37+
uses: j178/prek-action@91fd7d7cf70ae1dee9f4f44e7dfa5d1073fe6623 # v1
38+
continue-on-error: true
39+
40+
# indication that the linting has finished
41+
- name: react if linting finished succesfully
42+
if: steps.prek.outcome == 'success'
43+
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
44+
with:
45+
comment-id: ${{ github.event.comment.id }}
46+
reactions: "+1"
47+
48+
- name: Commit & push changes
49+
id: commit-and-push
50+
if: steps.prek.outcome == 'failure'
51+
run: |
52+
git config user.email "core@nf-co.re"
53+
git config user.name "nf-core-bot"
54+
git config push.default upstream
55+
git add .
56+
git status
57+
git commit -m "[automated] Fix code linting"
58+
git push
59+
60+
- name: react if linting errors were fixed
61+
id: react-if-fixed
62+
if: steps.commit-and-push.outcome == 'success'
63+
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
64+
with:
65+
comment-id: ${{ github.event.comment.id }}
66+
reactions: hooray
67+
68+
- name: react if linting errors were not fixed
69+
if: steps.commit-and-push.outcome == 'failure'
70+
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
71+
with:
72+
comment-id: ${{ github.event.comment.id }}
73+
reactions: confused
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@e8674b075228eee787fea43ef493e45ece1004c9 # v5
78+
with:
79+
issue-number: ${{ github.event.issue.number }}
80+
body: |
81+
@${{ github.actor }} I tried to fix the linting errors, but it didn't work. Please fix them manually.
82+
See [CI log](https://github.com/nf-core/test-datasets/actions/runs/${{ github.run_id }}) for more details.

.github/workflows/lint-code.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Lint tools code formatting
2+
on:
3+
pull_request:
4+
5+
# Cancel if a newer run is started
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
8+
cancel-in-progress: true
9+
10+
jobs:
11+
pre-commit:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6
16+
17+
- name: Run prek
18+
uses: j178/prek-action@91fd7d7cf70ae1dee9f4f44e7dfa5d1073fe6623 # v1

.pre-commit-config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/mirrors-prettier
3+
rev: "v3.1.0"
4+
hooks:
5+
- id: prettier
6+
additional_dependencies:
7+
- prettier@3.7.1
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v6.0.0
10+
hooks:
11+
- id: trailing-whitespace
12+
args:
13+
- --markdown-linebreak-ext=md
14+
- id: end-of-file-fixer
15+
- repo: local
16+
hooks:
17+
- id: prevent-file-deletion
18+
name: Prevent file deletions
19+
language: system
20+
entry: bash -c 'git diff --cached --name-only --diff-filter=D | grep -q . && echo "❌ File deletions are not allowed. Ask on slack for exceptions" && exit 1 || exit 0'
21+
pass_filenames: false

0 commit comments

Comments
 (0)