Skip to content

hackathon lnu hub #5251

hackathon lnu hub

hackathon lnu hub #5251

Workflow file for this run

name: Fix linting from a comment
on:
issue_comment:
types: [created]
jobs:
deploy:
# Only run if comment is on a PR with the main repo, and if it contains the magic keywords
if: >
contains(github.event.comment.html_url, '/pull/') &&
contains(github.event.comment.body, '@nf-core-bot fix linting') &&
github.repository == 'nf-core/website'
runs-on: ubuntu-latest
steps:
# Get PR details first
- name: Get PR details
id: pr
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
return {
head_ref: pr.data.head.ref,
head_repo: pr.data.head.repo.full_name
};
# Checkout using default GITHUB_TOKEN (read-only for untrusted code)
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
repository: ${{ fromJSON(steps.pr.outputs.result).head_repo }}
ref: ${{ fromJSON(steps.pr.outputs.result).head_ref }}
# Don't use bot token here - only default GITHUB_TOKEN
# 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
# Install and run prek
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
with:
node-version: 24
cache: npm
# Use npm ci with --ignore-scripts to prevent arbitrary code execution
- run: npm ci --ignore-scripts
- name: Run prek
id: prek
uses: j178/prek-action@0bb87d7f00b0c99306c8bcb8b8beba1eb581c037 # v1
continue-on-error: true
# indication that the linting has finished
- name: react if linting finished successfully
if: steps.prek.outcome == 'success'
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
with:
comment-id: ${{ github.event.comment.id }}
reactions: "+1"
# Re-checkout with bot token to push changes
- name: Checkout with bot token
if: steps.prek.outcome == 'failure'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
repository: ${{ fromJSON(steps.pr.outputs.result).head_repo }}
ref: ${{ fromJSON(steps.pr.outputs.result).head_ref }}
token: ${{ secrets.nf_core_bot_auth_token }}
# Re-run prek to apply fixes (idempotent operation)
- run: npm ci --ignore-scripts
- name: Re-run prek to apply fixes
if: steps.prek.outcome == 'failure'
uses: j178/prek-action@0bb87d7f00b0c99306c8bcb8b8beba1eb581c037 # v1
continue-on-error: true
- name: Commit & push changes
id: commit-and-push
if: steps.prek.outcome == 'failure'
run: |
git config user.email "core@nf-co.re"
git config user.name "nf-core-bot"
git add .
git status
git diff --cached --exit-code || git commit -m "[automated] Fix code linting"
git push
- name: react if linting errors were fixed
id: react-if-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: steps.commit-and-push.outcome == 'failure'
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
with:
comment-id: ${{ github.event.comment.id }}
reactions: confused
- name: Comment if push failed
if: steps.commit-and-push.outcome == 'failure'
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/website/actions/runs/${{ github.run_id }}) for more details.