• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1name: Test and lint
2
3on:
4  schedule:
5    - cron: "0 2 * * *"  # 2am UTC
6  push:
7    branches:
8      - main
9  pull_request:
10  workflow_dispatch:
11
12permissions:
13  contents: read
14
15env:
16  FORCE_COLOR: 1
17  PIP_DISABLE_PIP_VERSION_CHECK: 1
18
19concurrency:
20  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
21  cancel-in-progress: true
22
23jobs:
24  tests:
25    name: Run tests
26
27    if: >-
28      # if 'schedule' was the trigger,
29      # don't run it on contributors' forks
30      ${{
31        github.event_name != 'schedule'
32        || (
33          github.repository == 'python/typing_extensions'
34          && github.event_name == 'schedule'
35        )
36      }}
37
38    strategy:
39      fail-fast: false
40      matrix:
41        # We try to test on the earliest available bugfix release of each
42        # Python version, because typing sometimes changed between bugfix releases.
43        # For available versions, see:
44        # https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json
45        python-version:
46          - "3.8"
47          - "3.8.0"
48          - "3.9"
49          - "3.9.0"
50          - "3.10"
51          - "3.10.0"
52          - "3.11"
53          - "3.11.0"
54          - "3.12"
55          - "3.13"
56          - "pypy3.8"
57          - "pypy3.9"
58          - "pypy3.10"
59
60    runs-on: ubuntu-20.04
61
62    steps:
63      - uses: actions/checkout@v4
64
65      - name: Set up Python
66        uses: actions/setup-python@v5
67        with:
68          python-version: ${{ matrix.python-version }}
69          allow-prereleases: true
70
71      - name: Test typing_extensions
72        run: |
73          # Be wary of running `pip install` here, since it becomes easy for us to
74          # accidentally pick up typing_extensions as installed by a dependency
75          cd src
76          python -m unittest test_typing_extensions.py
77
78      - name: Test CPython typing test suite
79        # Test suite fails on PyPy even without typing_extensions
80        if: ${{ !startsWith(matrix.python-version, 'pypy') }}
81        run: |
82          cd src
83          # Run the typing test suite from CPython with typing_extensions installed,
84          # because we monkeypatch typing under some circumstances.
85          python -c 'import typing_extensions; import test.__main__' test_typing -v
86
87  linting:
88    name: Lint
89
90    # no reason to run this as a cron job
91    if: github.event_name != 'schedule'
92
93    runs-on: ubuntu-latest
94
95    steps:
96      - uses: actions/checkout@v4
97      - name: Set up Python
98        uses: actions/setup-python@v5
99        with:
100          python-version: "3"
101          cache: "pip"
102          cache-dependency-path: "test-requirements.txt"
103      - name: Install dependencies
104        run: pip install -r test-requirements.txt
105      - name: Lint implementation
106        run: ruff check
107
108  create-issue-on-failure:
109    name: Create an issue if daily tests failed
110    runs-on: ubuntu-latest
111
112    needs: [tests]
113
114    if: >-
115        ${{
116          github.repository == 'python/typing_extensions'
117          && always()
118          && github.event_name == 'schedule'
119          && needs.tests.result == 'failure'
120        }}
121
122    permissions:
123      issues: write
124
125    steps:
126      - uses: actions/github-script@v7
127        with:
128          github-token: ${{ secrets.GITHUB_TOKEN }}
129          script: |
130            await github.rest.issues.create({
131              owner: "python",
132              repo: "typing_extensions",
133              title: `Daily tests failed on ${new Date().toDateString()}`,
134              body: "Runs listed here: https://github.com/python/typing_extensions/actions/workflows/ci.yml",
135            })
136