Skip to content

Commit

Permalink
Add enable-cache as an input argument
Browse files Browse the repository at this point in the history
Signed-off-by: Samet Akcay <samet.akcay@intel.com>
  • Loading branch information
samet-akcay committed Dec 12, 2024
1 parent 80007fe commit 4b9f6fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
40 changes: 14 additions & 26 deletions .github/actions/pytest/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# - codecov-token: Token for coverage upload
# - max-test-time: Maximum test duration
# - device: Device to run tests on (cpu/gpu)
# - enable-cache: Enable pip caching
#
# Outputs:
# - coverage-percentage: Total coverage
Expand Down Expand Up @@ -72,6 +73,10 @@ inputs:
description: "Device to run tests on (cpu/gpu)"
required: false
default: "gpu"
enable-cache:
description: "Enable pip caching"
required: false
default: "true"

outputs:
coverage-percentage:
Expand All @@ -87,45 +92,28 @@ outputs:
runs:
using: composite
steps:
# Set up Python with pip caching
- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
cache: ${{ inputs.enable-cache == 'true' }}
cache-dependency-path: pyproject.toml

- name: Configure pip cache
shell: bash
run: |
CACHE_DIR="/opt/github/cache/pip"
# Ensure cache directory exists and is writable
sudo mkdir -p $CACHE_DIR
sudo chmod 777 $CACHE_DIR
# Configure pip to use the persistent cache
pip config set global.cache-dir $CACHE_DIR
# Display cache info
echo "Using pip cache directory: $(pip cache dir)"
echo "Current cache size: $(du -sh $CACHE_DIR 2>/dev/null || echo 'Empty')"
# Create and configure virtual environment
- name: Configure virtual environment
id: setup-venv
shell: bash
run: |
# Create and activate venv
# Create isolated test environment
python -m venv .venv
source .venv/bin/activate
# Upgrade pip
# Install dependencies with dev extras
python -m pip install --upgrade pip
# Install dependencies using the persistent cache
pip install --prefer-binary ".[dev]"
pip install ".[dev]"
pip install codecov
# Show installed packages for debugging
pip list
# Determine which tests to run based on input
- name: Determine test scope
id: test-scope
shell: bash
Expand Down Expand Up @@ -155,7 +143,7 @@ runs:
if [ "${{ inputs.device }}" = "cpu" ]; then
marker="-m cpu" # Only run CPU tests
else
marker="-m gpu" # Run all tests
marker="" # Run all tests (both CPU and GPU marked tests)
fi
# Run pytest
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/_reusable-test-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# - test-type: Type of test to run (unit/integration/e2e)
# - runner: Runner to use for the tests
# - timeout: Test timeout in minutes
# - enable-cache: Enable pip caching
#
# Required Secrets:
# - codecov-token: Token for coverage reporting (optional)
Expand Down Expand Up @@ -80,6 +81,10 @@ on:
description: "Test timeout in minutes"
type: number
default: 10
enable-cache:
description: "Enable pip caching"
type: boolean
default: true
secrets:
codecov-token:
required: false
Expand Down Expand Up @@ -108,3 +113,4 @@ jobs:
test-type: ${{ inputs.test-type }}
codecov-token: ${{ secrets.codecov-token }}
device: ${{ contains(inputs.runner, 'self-hosted') && 'gpu' || 'cpu' }}
enable-cache: ${{ inputs.enable-cache }}
2 changes: 2 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
uses: ./.github/workflows/_reusable-test-suite.yaml
with:
test-type: "unit"
enable-cache: true
runner: "ubuntu-latest"
timeout: 10
secrets:
Expand All @@ -67,6 +68,7 @@ jobs:
uses: ./.github/workflows/_reusable-test-suite.yaml
with:
test-type: "integration"
enable-cache: false
runner: "self-hosted"
timeout: 30
secrets:
Expand Down

0 comments on commit 4b9f6fb

Please sign in to comment.