Skip to content

GitHub Actions: Simplify requirements cache #10288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 26 additions & 125 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ on:
- main
- "maintenance/**"

env:
CACHE_VERSION: 5
KEY_PREFIX: venv

permissions:
contents: read
# permissions:
# contents: read # Incompatible with astral-sh/setup-uv cache

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand All @@ -30,7 +26,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
include:
- os: macos-latest
Expand All @@ -42,56 +38,32 @@ jobs:
- os: ubuntu-latest
python-version: "pypy-3.11"
runs-on: ${{ matrix.os }}
outputs:
python-key: ${{ steps.generate-python-key.outputs.key }}
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ matrix.python-version }}
id: python
uses: actions/[email protected]
- name: Set up uv with Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
python-version: ${{ matrix.python-version }}
check-latest: true
- name: Generate partial Python venv restore key
id: generate-python-key
run: >-
echo "key=${{ env.KEY_PREFIX }}-${{ env.CACHE_VERSION }}-${{
hashFiles('pyproject.toml', 'requirements_test.txt',
'requirements_test_min.txt', 'requirements_test_pre_commit.txt') }}" >>
$GITHUB_OUTPUT
- name: Restore Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: >-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
steps.generate-python-key.outputs.key }}
- name: Create Python virtual environment
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
python -m venv venv
. venv/bin/activate
python -m pip install --upgrade pip setuptools wheel
pip install --upgrade --requirement requirements_test.txt
- name: Run pytest
run: |
. venv/bin/activate
pip list | grep 'astroid\|pylint'
python -m pytest --durations=10 --benchmark-disable --cov --cov-report= tests/
- name: Run functional tests with minimal messages config
run: |
. venv/bin/activate
pip list | grep 'astroid\|pylint'
python -m pytest -vv --minimal-messages-config tests/test_functional.py
- name: Upload coverage artifact
if: runner.os == 'Linux'
uses: actions/[email protected]
with:
name: coverage-${{ matrix.python-version }}
include-hidden-files: true
path: .coverage
#- run: |
# uv pip install --python=${{ matrix.python-version }} pip
# pip --version
# uv pip --version
#- run: uv pip install --editable ".[dev,testutils]"
#- run: pip list | grep 'astroid\|pylint'
#- name: Run pytest
# run: |
# python -m pytest --durations=10 --benchmark-disable --cov --cov-report= tests/
#- name: Run functional tests with minimal messages config
# run: python -m pytest -vv --minimal-messages-config tests/test_functional.py
#- name: Upload coverage artifact
# if: runner.os == 'Linux'
# uses: actions/[email protected]
# with:
# name: coverage-${{ matrix.python-version }}
# include-hidden-files: true
# path: .coverage

coverage:
name: process / coverage
Expand All @@ -101,26 +73,14 @@ jobs:
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python 3.13
id: python
- name: Set up Python 3.x
uses: actions/[email protected]
with:
python-version: "3.13"
check-latest: true
- name: Restore Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
fail-on-cache-miss: true
key:
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
needs.tests-linux.outputs.python-key }}
python-version: "3.x"
- name: Download all coverage artifacts
uses: actions/[email protected]
- name: Combine coverage results
run: |
. venv/bin/activate
coverage combine coverage*/.coverage
coverage xml
- uses: codecov/codecov-action@v5
Expand All @@ -147,18 +107,8 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
check-latest: true
- name: Restore Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
fail-on-cache-miss: true
key:
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
needs.tests-linux.outputs.python-key }}
- name: Run pytest
run: |
. venv/bin/activate
pip install pygal
pip install .
pip list | grep 'astroid\|pylint'
Expand All @@ -179,52 +129,3 @@ jobs:
steps.artifact-name-suffix.outputs.datetime }}
include-hidden-files: true
path: .benchmarks/

tests-windows:
name: run / ${{ matrix.python-version }} / Windows
runs-on: windows-latest
timeout-minutes: 25
needs: tests
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- name: Set temp directory
run: echo "TEMP=$env:USERPROFILE\AppData\Local\Temp" >> $env:GITHUB_ENV
# Workaround to set correct temp directory on Windows
# https://github.com/actions/virtual-environments/issues/712
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ matrix.python-version }}
id: python
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
check-latest: true
- name: Generate partial Python venv restore key
id: generate-python-key
run: >-
echo "key=venv-${{ env.CACHE_VERSION }}-${{
hashFiles('pyproject.toml', 'requirements_test_min.txt')
}}" >> $env:GITHUB_OUTPUT
- name: Restore Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: >-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
steps.generate-python-key.outputs.key }}
- name: Create Python virtual environment
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
python -m venv venv
. venv\\Scripts\\activate
python -m pip install --upgrade pip setuptools wheel
pip install --upgrade --requirement requirements_test_min.txt
- name: Run pytest
run: |
. venv\\Scripts\\activate
pip list | grep 'astroid\|pylint'
python -m pytest --durations=10 --benchmark-disable tests/
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ dependencies = [
"tomlkit>=0.10.1",
"typing-extensions>=3.10; python_version<'3.10'",
]
optional-dependencies.dev = [
# A combination of requirements_test.txt and requirements_test_min.txt
"astroid==4.0.0a0", # Pinned to a specific version for tests
"contributors-txt>=1",
"coverage~=7.7",
"py~=1.11.0",
"pytest~=8.3",
"pytest-benchmark~=5.1",
"pytest-cov~=6.0",
"pytest-timeout~=2.3",
"pytest-xdist~=3.6",
"requests",
# Voluntary for test purpose, not actually used in prod, see #8904
"setuptools; python_version>='3.12'",
"six",
"tbump~=6.11.0",
"towncrier~=24.8",
"tox>=3",
# Type packages for mypy
"types-setuptools==76.0.0.20250313",
"typing-extensions~=4.12",
]
optional-dependencies.spelling = [ "pyenchant~=3.2" ]
optional-dependencies.testutils = [ "gitpython>3" ]
urls."Bug Tracker" = "https://github.com/pylint-dev/pylint/issues"
Expand Down
Loading