name: lint-check

on:
  workflow_dispatch:
  push:
    branches:
    - dev
  pull_request:
    branches:
    - dev
    - main
  schedule:
  - cron: '0 0 1 * *' # first day of every month at midnight

permissions:
  contents: read
  issues: write

jobs:
  lint:
    if: github.actor != 'github-actions[bot]'
    name: Linting build
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python 3.10
        uses: actions/setup-python@v5
        with:
          python-version: "3.10"
      - name: Python info
        shell: bash -e {0}
        run: |
          which python
          python --version
      - name: Upgrade pip and install dependencies
        run: |
          python -m pip install --upgrade pip setuptools
          python -m pip install .[dev,publishing]
      - name: Check style against standards using ruff
        run: |
          ruff check
          ruff format --check

  linkChecker:
    if: github.actor != 'github-actions[bot]'
    runs-on: ubuntu-latest
    permissions:
      issues: write # required for peter-evans/create-issue-from-file
    steps:
      - uses: actions/checkout@v4

      - name: Link Checker
        id: lychee
        uses: lycheeverse/lychee-action@v2.0.2
        with:
          args: --timeout 40 .
          fail: false

      - name: Set Issue Title
        id: set_title
        run: |
          echo "Lychee outputs:"
          echo "${{ toJson(steps.lychee.outputs) }}"
          echo "ISSUE_TITLE=Link Checker Report - $(date '+%Y-%m-%d')" >> $GITHUB_ENV

      - name: Create Issue From File
        if: steps.lychee.outputs.exit_code != 0
        uses: peter-evans/create-issue-from-file@v5
        with:
          title: ${{ env.ISSUE_TITLE }}
          content-filepath: ./lychee/out.md
          labels: report, automated issue

  verify_cff:
    if: github.actor != 'github-actions[bot]'
    name: "cffconvert"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        name: Check out a copy of the repository

      - name: Check whether the citation metadata from CITATION.cff is valid
        uses: citation-file-format/cffconvert-github-action@2.0.0
        with:
          args: "--validate"
