diff --git a/.github/workflows/rhiza_deptry.yml b/.github/workflows/rhiza_deptry.yml index 30220daa..a81dff67 100644 --- a/.github/workflows/rhiza_deptry.yml +++ b/.github/workflows/rhiza_deptry.yml @@ -37,9 +37,45 @@ jobs: with: token: ${{ secrets.GH_PAT }} - - name: Run deptry - run: make deptry - # NOTE: make deptry is good style because it encapsulates the folders to check - # (e.g. src and book/marimo) and keeps CI in sync with local development. - # Since we use a 'uv' container, the Makefile is optimised to use the - # pre-installed 'uv' and 'uvx' from the system PATH. + - name: Extract folder variables + id: folders + run: | + # Extract SOURCE_FOLDER from the project configuration (via Makefile) + # shellcheck disable=SC2016 # Single quotes intentional - Make syntax, not shell expansion + SOURCE_FOLDER=$(make -s -f Makefile -f - <<< 'print: ; @echo $(or $(SOURCE_FOLDER),src)' print) + echo "source=$SOURCE_FOLDER" >> "$GITHUB_OUTPUT" + + # Extract MARIMO_FOLDER from the project configuration (via Makefile) + # shellcheck disable=SC2016 # Single quotes intentional - Make syntax, not shell expansion + MARIMO_FOLDER=$(make -s -f Makefile -f - <<< 'print: ; @echo $(or $(MARIMO_FOLDER),marimo)' print) + echo "marimo=$MARIMO_FOLDER" >> "$GITHUB_OUTPUT" + + # Extract Python version + PYTHON_VERSION=$(cat .python-version 2>/dev/null || echo "3.13") + echo "python_version=$PYTHON_VERSION" >> "$GITHUB_OUTPUT" + + echo "Detected SOURCE_FOLDER: $SOURCE_FOLDER" + echo "Detected MARIMO_FOLDER: $MARIMO_FOLDER" + echo "Using Python version: $PYTHON_VERSION" + + - name: Run deptry on source folder + if: steps.folders.outputs.source != '' + run: | + if [ -d "${{ steps.folders.outputs.source }}" ]; then + uvx -p "${{ steps.folders.outputs.python_version }}" deptry "${{ steps.folders.outputs.source }}" + else + echo "Source folder ${{ steps.folders.outputs.source }} does not exist, skipping" + fi + + - name: Run deptry on marimo folder + if: steps.folders.outputs.marimo != '' + run: | + if [ -d "${{ steps.folders.outputs.marimo }}" ]; then + if [ -d "${{ steps.folders.outputs.source }}" ]; then + uvx -p "${{ steps.folders.outputs.python_version }}" deptry "${{ steps.folders.outputs.marimo }}" "${{ steps.folders.outputs.source }}" --ignore DEP004 + else + uvx -p "${{ steps.folders.outputs.python_version }}" deptry "${{ steps.folders.outputs.marimo }}" --ignore DEP004 + fi + else + echo "Marimo folder ${{ steps.folders.outputs.marimo }} does not exist, skipping" + fi diff --git a/.gitlab/README.md b/.gitlab/README.md index b0523a79..47d3d008 100644 --- a/.gitlab/README.md +++ b/.gitlab/README.md @@ -63,7 +63,8 @@ This directory contains GitLab CI/CD workflow configurations that mirror the fun - On merge requests to main/master **Key Features:** -- Automatic source folder detection +- Extracts SOURCE_FOLDER and MARIMO_FOLDER from Makefile configuration +- Automatically detects and checks all configured source folders - Identifies unused dependencies **Equivalent GitHub Action:** `.github/workflows/rhiza_deptry.yml` diff --git a/.gitlab/TESTING.md b/.gitlab/TESTING.md index 8bbcd93e..32deb7c3 100644 --- a/.gitlab/TESTING.md +++ b/.gitlab/TESTING.md @@ -98,12 +98,16 @@ This workflow is designed for repositories that use rhiza as a template, not for **Expected behavior:** - Checks for missing/obsolete dependencies -- Automatically detects source folder (`src/` or `.`) +- Automatically extracts SOURCE_FOLDER and MARIMO_FOLDER from Makefile configuration +- Runs deptry on detected folders if they exist - Reports unused dependencies **Manual test:** ```bash -# Run deptry locally +# Run deptry locally using make (recommended) +make deptry + +# Or run deptry directly uvx deptry src/ ``` diff --git a/.gitlab/workflows/rhiza_deptry.yml b/.gitlab/workflows/rhiza_deptry.yml index e2f15f18..b0c3456b 100644 --- a/.gitlab/workflows/rhiza_deptry.yml +++ b/.gitlab/workflows/rhiza_deptry.yml @@ -15,7 +15,34 @@ deptry:check: needs: [] image: ghcr.io/astral-sh/uv:0.9.30-bookworm script: - - make deptry + # Extract SOURCE_FOLDER and MARIMO_FOLDER from the project configuration + # and run deptry on detected folders + - | + SOURCE_FOLDER=$(make -s -f Makefile -f - <<< 'print: ; @echo $(or $(SOURCE_FOLDER),src)' print) + MARIMO_FOLDER=$(make -s -f Makefile -f - <<< 'print: ; @echo $(or $(MARIMO_FOLDER),marimo)' print) + PYTHON_VERSION=$(cat .python-version 2>/dev/null || echo "3.13") + + echo "Detected SOURCE_FOLDER: $SOURCE_FOLDER" + echo "Detected MARIMO_FOLDER: $MARIMO_FOLDER" + echo "Using Python version: $PYTHON_VERSION" + + # Run deptry on source folder if it exists + if [ -n "$SOURCE_FOLDER" ] && [ -d "$SOURCE_FOLDER" ]; then + uvx -p "$PYTHON_VERSION" deptry "$SOURCE_FOLDER" + else + echo "Source folder $SOURCE_FOLDER does not exist, skipping" + fi + + # Run deptry on marimo folder if it exists + if [ -n "$MARIMO_FOLDER" ] && [ -d "$MARIMO_FOLDER" ]; then + if [ -d "$SOURCE_FOLDER" ]; then + uvx -p "$PYTHON_VERSION" deptry "$MARIMO_FOLDER" "$SOURCE_FOLDER" --ignore DEP004 + else + uvx -p "$PYTHON_VERSION" deptry "$MARIMO_FOLDER" --ignore DEP004 + fi + else + echo "Marimo folder $MARIMO_FOLDER does not exist, skipping" + fi rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" - if: $CI_COMMIT_BRANCH