Skip to content

Fix CI workflow caching failure when no dependency files are present - #5

Draft
Daniele-Cangi with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-d99b7322-103e-4967-872c-c24be78243ac
Draft

Fix CI workflow caching failure when no dependency files are present#5
Daniele-Cangi with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-d99b7322-103e-4967-872c-c24be78243ac

Conversation

Copilot AI commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

Problem

The CI workflow was failing with the error:

Error: No file in /home/runner/work/Reson-AI/Reson-AI matched to [requirements.txt,pyproject.toml,poetry.lock or **/pyproject.toml], make sure you have checked out the target repository

This occurred because actions/setup-python@v5 with cache: "pip" requires dependency files to exist when caching is enabled, but this repository currently has no dependency files (it's a standalone project).

Solution

Updated .github/workflows/ci.yml to implement conditional caching that automatically adapts to the presence or absence of dependency files:

Key Changes

  1. Conditional Python Setup: Split into two steps using hashFiles() to detect dependency files

    • With cache: Activates when requirements*.txt, pyproject.toml, or poetry.lock files exist anywhere in the repository
    • Without cache: Fallback for standalone projects (current state)
  2. Enhanced Dependency Detection: Expanded glob patterns to cover files in subdirectories:

    • **/requirements*.txt (catches requirements.txt, requirements-dev.txt, etc.)
    • **/pyproject.toml
    • **/poetry.lock
  3. Matrix Strategy: Added support for Python 3.10 and 3.11

  4. Robust Dependency Installation: Added conditional logic that safely handles missing dependency files

  5. Smart Test Execution: Implemented pytest with no-tests guard to handle repositories without test files

Benefits

  • Immediate fix: CI now runs successfully even with no dependency files
  • Future-proof: Automatically enables caching when dependency files are added later
  • Broader coverage: Detects dependency files in any subdirectory
  • Zero breaking changes: Maintains all existing functionality

The workflow now gracefully handles both standalone projects and projects with dependencies, eliminating the caching error while preserving performance benefits when applicable.

This pull request was created as a result of the following prompt from Copilot chat.

Context
CI is failing on Reson-AI with the error:

Error: No file in /home/runner/work/Reson-AI/Reson-AI matched to [requirements.txt,pyproject.toml,poetry.lock or **/pyproject.toml], make sure you have checked out the target repository

Root cause
The workflow .github/workflows/ci.yml uses actions/setup-python@v5 with cache: "pip" and a cache-dependency-path pointing to requirements.txt, pyproject.toml, and poetry.lock at the repository root. In this repo there are currently no dependency files (project is standalone), so setup-python v5 errors when caching is enabled without matching dependency files.

What to change

  • Keep actions/checkout first (already correct).
  • Replace the single setup-python step with two guarded steps:
    • One that enables caching only if dependency files exist anywhere in the repo.
    • One without caching when no dependency files are present.
  • Expand the cache-dependency-path to cover files in subfolders as well.
  • Leave the rest of the job (install deps, pytest with no-tests guard) as-is.

Acceptance criteria

  • CI runs successfully even when no dependency files are present.
  • If dependency files are added later (requirements*.txt, pyproject.toml, poetry.lock), the cache automatically activates.

Proposed file update
Below is the updated workflow file content with conditional caching and broader glob patterns for dependency files.

name: CI

on:
  push:
    branches: ["**"]
  pull_request:
    branches: ["main"]

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.10", "3.11"]
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      # Enable cache only if dependency files exist
      - name: Setup Python (with cache)
        if: ${{ hashFiles('**/requirements*.txt', '**/pyproject.toml', '**/poetry.lock') != '' }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: "pip"
          cache-dependency-path: |
            **/requirements*.txt
            **/pyproject.toml
            **/poetry.lock

      # Fallback when no dependency files are present (standalone)
      - name: Setup Python (no cache)
        if: ${{ hashFiles('**/requirements*.txt', '**/pyproject.toml', '**/poetry.lock') == '' }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
          if [ -f pyproject.toml ]; then pip install -e . || true; fi
          pip install pytest

      - name: Run tests
        run: |
          pytest -q || { ec=$?; if [ $ec -eq 5 ]; then echo "No tests collected"; exit 0; else exit $ec; fi; }

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits September 15, 2025 06:55
Co-authored-by: Daniele-Cangi <217463740+Daniele-Cangi@users.noreply.github.com>
Co-authored-by: Daniele-Cangi <217463740+Daniele-Cangi@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CI: make setup-python cache conditional when no dependency files are present Fix CI workflow caching failure when no dependency files are present Sep 15, 2025
Copilot AI requested a review from Daniele-Cangi September 15, 2025 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants