Library Checks #5137
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Library Checks" | |
| on: | |
| push: | |
| paths: | |
| - "discord/**" | |
| - "examples/**" | |
| - "requirements/**" | |
| - "tests/**" | |
| - ".github/actions/**" | |
| - ".github/workflows/lib-checks.yml" | |
| - "LICENSE" | |
| - "MANIFEST.in" | |
| - "README.rst" | |
| - "*.toml" | |
| - "*.py" | |
| - ".*" | |
| branches: [ master ] | |
| pull_request: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 0 * * *" | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| jobs: | |
| changes: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| lib: ${{ steps.filter.outputs.lib }} | |
| steps: | |
| - name: "Check changed paths" | |
| id: filter | |
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 | |
| with: | |
| script: | | |
| if (context.eventName !== 'pull_request') { | |
| core.setOutput('lib', 'true'); | |
| return; | |
| } | |
| const files = await github.paginate(github.rest.pulls.listFiles, { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.payload.pull_request.number, | |
| }); | |
| const matches = (file) => ( | |
| file.startsWith('discord/') || | |
| file.startsWith('examples/') || | |
| file.startsWith('requirements/') || | |
| file.startsWith('tests/') || | |
| file.startsWith('.github/actions/') || | |
| file === '.github/workflows/lib-checks.yml' || | |
| file === 'LICENSE' || | |
| file === 'MANIFEST.in' || | |
| file === 'README.rst' || | |
| (!file.includes('/') && file.endsWith('.toml')) || | |
| (!file.includes('/') && file.endsWith('.py')) || | |
| /^\.[^/]+$/.test(file) | |
| ); | |
| const changed = files.some((file) => matches(file.filename)); | |
| core.setOutput('lib', changed ? 'true' : 'false'); | |
| if (!changed) { | |
| core.notice('Library checks skipped because no changed files matched the library check paths.'); | |
| await core.summary | |
| .addHeading('Library checks skipped', 2) | |
| .addRaw('No changed files matched the library check paths.') | |
| .write(); | |
| } | |
| codespell: | |
| needs: [ changes ] | |
| if: ${{ needs.changes.outputs.lib == 'true' && github.event_name != 'schedule' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: "Checkout Repository" | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: "Setup Python dev environment" | |
| uses: ./.github/actions/setup-python-dev | |
| with: | |
| python-version: "3.14" | |
| - name: "Run codespell" | |
| run: | |
| codespell --ignore-words-list="groupt,nd,ot,ro,falsy,BU" \ | |
| --exclude-file=".github/workflows/codespell.yml" | |
| bandit: | |
| needs: [ changes ] | |
| if: ${{ needs.changes.outputs.lib == 'true' && github.event_name != 'schedule' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: "Checkout Repository" | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: "Setup Python dev environment" | |
| uses: ./.github/actions/setup-python-dev | |
| with: | |
| python-version: "3.14" | |
| - name: "Run bandit" | |
| run: bandit --recursive --skip B101,B104,B105,B110,B307,B311,B404,B603,B607 . | |
| pylint: | |
| needs: [ changes ] | |
| if: ${{ needs.changes.outputs.lib == 'true' && github.event_name != 'schedule' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: "Checkout Repository" | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: "Setup Python dev environment" | |
| uses: ./.github/actions/setup-python-dev | |
| with: | |
| python-version: "3.14" | |
| - name: "Setup cache" | |
| id: cache-pylint | |
| uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: .pylint.d | |
| key: pylint-${{ runner.os }}-py3.14-${{ hashFiles('pyproject.toml', 'discord/**/*.py') }} | |
| restore-keys: | | |
| pylint-${{ runner.os }}-py3.14- | |
| - name: "Run pylint" | |
| run: pylint discord/ --exit-zero | |
| mypy: | |
| needs: [ changes ] | |
| if: ${{ needs.changes.outputs.lib == 'true' && github.event_name != 'schedule' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: "Checkout Repository" | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: "Setup Python dev environment" | |
| uses: ./.github/actions/setup-python-dev | |
| with: | |
| python-version: "3.14" | |
| - name: "Setup cache" | |
| id: cache-mypy | |
| uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: .mypy_cache | |
| key: mypy-${{ runner.os }}-py3.14-${{ hashFiles('pyproject.toml', 'discord/**/*.py') }} | |
| restore-keys: | | |
| mypy-${{ runner.os }}-py3.14- | |
| - name: "Make mypy cache directory" | |
| id: cache-dir-mypy | |
| run: mkdir -p -v .mypy_cache | |
| - name: "Run mypy" | |
| run: mypy --non-interactive discord/ | |
| flake8: | |
| needs: [ changes ] | |
| if: ${{ needs.changes.outputs.lib == 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: "Checkout Repository" | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: "Setup Python dev environment" | |
| uses: ./.github/actions/setup-python-dev | |
| with: | |
| python-version: "3.14" | |
| - name: "Lint with flake8" | |
| run: | | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics | |
| tests: | |
| needs: [ changes ] | |
| if: ${{ needs.changes.outputs.lib == 'true' && github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ ubuntu-latest, windows-latest, macos-latest ] | |
| python-version: [ "3.10", "3.14" ] | |
| steps: | |
| - name: "Checkout Repository" | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: "Setup Python dev environment" | |
| uses: ./.github/actions/setup-python-dev | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| install-voice: "true" | |
| - name: "Run tests" | |
| run: tox | |
| tests-full: | |
| needs: [ changes ] | |
| if: ${{ needs.changes.outputs.lib == 'true' && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ ubuntu-latest, windows-latest, macos-latest ] | |
| python-version: [ "3.10", "3.11", "3.12", "3.13", "3.14" ] | |
| steps: | |
| - name: "Checkout Repository" | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: "Setup Python dev environment" | |
| uses: ./.github/actions/setup-python-dev | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| install-voice: "true" | |
| - name: "Run tests" | |
| run: tox | |
| tests-pass: # ref: https://github.com/orgs/community/discussions/4324#discussioncomment-3477871 | |
| runs-on: ubuntu-latest | |
| needs: [ changes, tests, tests-full ] | |
| if: always() | |
| steps: | |
| - name: Tests succeeded | |
| if: ${{ !(contains(needs.*.result, 'failure')) && !(contains(needs.*.result, 'cancelled')) }} | |
| run: exit 0 | |
| - name: Tests failed | |
| if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} | |
| run: exit 1 |