Skip to content

Commit 4b9f6fb

Browse files
committed
Add enable-cache as an input argument
Signed-off-by: Samet Akcay <[email protected]>
1 parent 80007fe commit 4b9f6fb

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

.github/actions/pytest/action.yaml

+14-26
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
# - codecov-token: Token for coverage upload
3434
# - max-test-time: Maximum test duration
3535
# - device: Device to run tests on (cpu/gpu)
36+
# - enable-cache: Enable pip caching
3637
#
3738
# Outputs:
3839
# - coverage-percentage: Total coverage
@@ -72,6 +73,10 @@ inputs:
7273
description: "Device to run tests on (cpu/gpu)"
7374
required: false
7475
default: "gpu"
76+
enable-cache:
77+
description: "Enable pip caching"
78+
required: false
79+
default: "true"
7580

7681
outputs:
7782
coverage-percentage:
@@ -87,45 +92,28 @@ outputs:
8792
runs:
8893
using: composite
8994
steps:
95+
# Set up Python with pip caching
9096
- name: Set up Python environment
9197
uses: actions/setup-python@v5
9298
with:
9399
python-version: ${{ inputs.python-version }}
100+
cache: ${{ inputs.enable-cache == 'true' }}
101+
cache-dependency-path: pyproject.toml
94102

95-
- name: Configure pip cache
96-
shell: bash
97-
run: |
98-
CACHE_DIR="/opt/github/cache/pip"
99-
100-
# Ensure cache directory exists and is writable
101-
sudo mkdir -p $CACHE_DIR
102-
sudo chmod 777 $CACHE_DIR
103-
104-
# Configure pip to use the persistent cache
105-
pip config set global.cache-dir $CACHE_DIR
106-
107-
# Display cache info
108-
echo "Using pip cache directory: $(pip cache dir)"
109-
echo "Current cache size: $(du -sh $CACHE_DIR 2>/dev/null || echo 'Empty')"
110-
103+
# Create and configure virtual environment
111104
- name: Configure virtual environment
112105
id: setup-venv
113106
shell: bash
114107
run: |
115-
# Create and activate venv
108+
# Create isolated test environment
116109
python -m venv .venv
117110
source .venv/bin/activate
118-
119-
# Upgrade pip
111+
# Install dependencies with dev extras
120112
python -m pip install --upgrade pip
121-
122-
# Install dependencies using the persistent cache
123-
pip install --prefer-binary ".[dev]"
113+
pip install ".[dev]"
124114
pip install codecov
125115
126-
# Show installed packages for debugging
127-
pip list
128-
116+
# Determine which tests to run based on input
129117
- name: Determine test scope
130118
id: test-scope
131119
shell: bash
@@ -155,7 +143,7 @@ runs:
155143
if [ "${{ inputs.device }}" = "cpu" ]; then
156144
marker="-m cpu" # Only run CPU tests
157145
else
158-
marker="-m gpu" # Run all tests
146+
marker="" # Run all tests (both CPU and GPU marked tests)
159147
fi
160148
161149
# Run pytest

.github/workflows/_reusable-test-suite.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# - test-type: Type of test to run (unit/integration/e2e)
3232
# - runner: Runner to use for the tests
3333
# - timeout: Test timeout in minutes
34+
# - enable-cache: Enable pip caching
3435
#
3536
# Required Secrets:
3637
# - codecov-token: Token for coverage reporting (optional)
@@ -80,6 +81,10 @@ on:
8081
description: "Test timeout in minutes"
8182
type: number
8283
default: 10
84+
enable-cache:
85+
description: "Enable pip caching"
86+
type: boolean
87+
default: true
8388
secrets:
8489
codecov-token:
8590
required: false
@@ -108,3 +113,4 @@ jobs:
108113
test-type: ${{ inputs.test-type }}
109114
codecov-token: ${{ secrets.codecov-token }}
110115
device: ${{ contains(inputs.runner, 'self-hosted') && 'gpu' || 'cpu' }}
116+
enable-cache: ${{ inputs.enable-cache }}

.github/workflows/pr.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858
uses: ./.github/workflows/_reusable-test-suite.yaml
5959
with:
6060
test-type: "unit"
61+
enable-cache: true
6162
runner: "ubuntu-latest"
6263
timeout: 10
6364
secrets:
@@ -67,6 +68,7 @@ jobs:
6768
uses: ./.github/workflows/_reusable-test-suite.yaml
6869
with:
6970
test-type: "integration"
71+
enable-cache: false
7072
runner: "self-hosted"
7173
timeout: 30
7274
secrets:

0 commit comments

Comments
 (0)