|
| 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/configs' |
| 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@b4ffde65f46336ab88eb53be808477a3936bae11 # 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@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5 |
| 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 "core@nf-co.re" |
| 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/configs/actions/runs/${{ github.run_id }}) for more details. |
0 commit comments