name: nf-core linting
# This workflow is triggered on pushes and PRs to the repository.
# It runs the `nf-core pipelines lint` and markdown lint tests to ensure
# that the code meets the nf-core guidelines. {%- raw %}
on:
  pull_request:
  release:
    types: [published]

jobs:
  pre-commit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

      - name: Set up Python 3.12
        uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
        with:
          python-version: "3.13"

      - name: Install pre-commit
        run: pip install pre-commit

      - name: Run pre-commit
        run: pre-commit run --all-files

  nf-core:
    runs-on: ubuntu-latest
    steps:
      - name: Check out pipeline code
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

      - name: Install Nextflow
        uses: nf-core/setup-nextflow@v2

      - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
        with:
          python-version: "3.13"
          architecture: "x64"

      - name: read .nf-core.yml
        uses: pietrobolcato/action-read-yaml@9f13718d61111b69f30ab4ac683e67a56d254e1d # 1.1.0
        id: read_yml
        with:
          config: ${{ github.workspace }}/.nf-core.yml

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install nf-core==${{ steps.read_yml.outputs['nf_core_version'] }}

      - name: Run nf-core pipelines lint
        if: ${{ github.base_ref != 'master' }}
        env:
          GITHUB_COMMENTS_URL: ${{ github.event.pull_request.comments_url }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_PR_COMMIT: ${{ github.event.pull_request.head.sha }}
        run: nf-core -l lint_log.txt pipelines lint --dir ${GITHUB_WORKSPACE} --markdown lint_results.md

      - name: Run nf-core pipelines lint --release
        if: ${{ github.base_ref == 'master' }}
        env:
          GITHUB_COMMENTS_URL: ${{ github.event.pull_request.comments_url }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_PR_COMMIT: ${{ github.event.pull_request.head.sha }}
        run: nf-core -l lint_log.txt pipelines lint --release --dir ${GITHUB_WORKSPACE} --markdown lint_results.md

      - name: Save PR number
        if: ${{ always() }}
        run: echo ${{ github.event.pull_request.number }} > PR_number.txt

      - name: Upload linting log file artifact
        if: ${{ always() }}
        uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
        with:
          name: linting-logs
          path: |
            lint_log.txt
            lint_results.md
            PR_number.txt {%- endraw %}
