๐Ÿ“ฆ astral-sh / docstring-adder

๐Ÿ“„ check.yaml ยท 161 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161name: tests

on:
  push:
    branches:
      - main
  pull_request:
  workflow_dispatch:
  schedule:
    - cron: "0 12 * * *"

permissions: {}

env:
  FORCE_COLOR: 1 # Request colored output from CLI tools supporting it
  CLICOLOR_FORCE: 1 # recognized by uv
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  DEFAULT_PYTHON_VERSION: "3.13" # Default Python version for uvx

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  stdlib:
    name: Check typeshed stdlib
    runs-on: ${{ matrix.platform }}
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
        platform: ["ubuntu-latest", "macos-latest", "windows-latest"]
    steps:
      - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
        with:
          path: docstring-adder
          persist-credentials: false
      - name: Checkout typeshed
        run: git clone --depth=1 https://github.com/python/typeshed.git || git clone --depth=1 https://github.com/python/typeshed.git
      - uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
      - name: Check a basic run doesn't fail
        run: uvx --python=${{ matrix.python-version }} --force-reinstall --from=./docstring-adder add-docstrings --stdlib-path ./typeshed/stdlib
      - name: Check typeshed's mypy_test.py passes
        run: uv run --directory=typeshed --no-project --python="${DEFAULT_PYTHON_VERSION}" --with-requirements=requirements-tests.txt python tests/mypy_test.py stdlib -p "${{ matrix.python-version }}"
      - name: Check running it again doesn't produce any changes
        # Some weird thing with distutils means that it does actually add docstrings
        # when run the second time that it didn't add when run the first time.
        # I have no appetite to figure out what cursed thing in distutils is causing this,
        # and it doesn't seem to be a major issue in general.
        if: ${{ (matrix.python-version != '3.9') && (matrix.python-version != '3.10') && (matrix.python-version != '3.11') }}
        shell: bash
        run: |
          cd typeshed
          git config --global user.email "you@example.com"
          git config --global user.name "Your Name"
          test -n "$(git status --porcelain)"
          git commit -am "."
          uvx --python=${{ matrix.python-version }} --force-reinstall --from=../docstring-adder add-docstrings --stdlib-path ./stdlib
          test -z "$(git status --porcelain)"

  typeshed-third-party:
    name: Check typeshed third-party stubs
    runs-on: ubuntu-latest
    # Too slow to run on every PR
    if: ${{ github.event_name != 'pull_request' }}
    steps:
      - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
        with:
          path: docstring-adder
          persist-credentials: false
      - name: Checkout typeshed
        run: git clone --depth=1 https://github.com/python/typeshed.git || git clone --depth=1 https://github.com/python/typeshed.git
      - uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
      - name: Check a basic run doesn't fail
        run: uvx --python="${DEFAULT_PYTHON_VERSION}" python ./docstring-adder/.github/scripts/typeshed_third_party.py --typeshed-dir ./typeshed --docstring-adder-dir ./docstring-adder
      - name: Check typeshed's mypy_test.py passes
        run: uv run --directory=typeshed --no-project --python="${DEFAULT_PYTHON_VERSION}" --with-requirements=requirements-tests.txt python tests/mypy_test.py stubs -p "${DEFAULT_PYTHON_VERSION}"
      # Ideally we'd now check that running it again doesn't produce any changes, but it fails for some third-party packages.
      # I believe this is because some badly-behaved packages make persistent changes to the Python environment when they're imported.
      # Stubs packages for which this fails are: `Authlib`, `aws-xray-sdk`, `beautifulsoup4`, `html5lib`, `python-jose`, `qrcode`

  # A fairly arbitrary check, but it's good to enforce that it works on a non-typeshed stubs package.
  pandas-stubs:
    name: Check running on pandas-stubs
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
        with:
          path: docstring-adder
          persist-credentials: false
      - name: Checkout typeshed
        run: git clone --depth=1 https://github.com/pandas-dev/pandas-stubs.git || git clone --depth=1 https://github.com/pandas-dev/pandas-stubs.git
      - uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
      - name: Check a basic run doesn't fail
        run: uvx --python="${DEFAULT_PYTHON_VERSION}" --force-reinstall --with=pandas --from=./docstring-adder add-docstrings --packages ./pandas-stubs
      - name: Check running it again doesn't produce any changes
        shell: bash
        run: |
          git config --global user.email "you@example.com"
          git config --global user.name "Your Name"
          cd pandas-stubs
          test -n "$(git status --porcelain)"
          git commit -am "."
          uvx --python="${DEFAULT_PYTHON_VERSION}" --force-reinstall --with=pandas --from=../docstring-adder add-docstrings --packages .
          test -z "$(git status --porcelain)"

  mypy:
    name: Run mypy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
        with:
          persist-credentials: false
      - uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
      - run: uv run mypy

  ty:
    name: Run ty
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
        with:
          persist-credentials: false
      - uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
      - run: uv run ty check

  pre-commit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
        with:
          persist-credentials: false
      - uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
      - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1

  create-issue-on-failure:
    name: Create an issue if the daily test run failed
    runs-on: ubuntu-latest
    needs:
      - stdlib
      - typeshed-third-party
      - mypy
      - ty
      - pre-commit
      - pandas-stubs
    if: ${{ github.repository == 'astral-sh/docstring-adder' && always() && github.event_name == 'schedule' && ((needs.stdlib.result == 'failure') || (needs.typeshed-third-party.result == 'failure') || (needs.mypy.result == 'failure') || (needs.ty.result == 'failure') || (needs.pre-commit.result == 'failure') || (needs.pandas-stubs.result == 'failure')) }}
    permissions:
      issues: write # to create issues through actions/github-script
    steps:
      - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            await github.rest.issues.create({
              owner: "astral-sh",
              repo: "docstring-adder",
              title: `Daily test run failed on ${new Date().toDateString()}`,
              body: "Run listed here: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
              labels: ["bug"],
            })