From 4b9f6fb0fe4fe062a7e7d9658ad97cda97fb51ee Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Thu, 12 Dec 2024 13:33:24 +0000 Subject: [PATCH] Add enable-cache as an input argument Signed-off-by: Samet Akcay --- .github/actions/pytest/action.yaml | 40 ++++++++------------- .github/workflows/_reusable-test-suite.yaml | 6 ++++ .github/workflows/pr.yaml | 2 ++ 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/.github/actions/pytest/action.yaml b/.github/actions/pytest/action.yaml index 3288a70ed3..87b9e70ece 100644 --- a/.github/actions/pytest/action.yaml +++ b/.github/actions/pytest/action.yaml @@ -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 @@ -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: @@ -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 @@ -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 diff --git a/.github/workflows/_reusable-test-suite.yaml b/.github/workflows/_reusable-test-suite.yaml index ef0cadd68b..14edcd1244 100644 --- a/.github/workflows/_reusable-test-suite.yaml +++ b/.github/workflows/_reusable-test-suite.yaml @@ -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) @@ -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 @@ -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 }} diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index fa2cb8e0f8..33fac4a327 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -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: @@ -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: