Skip to content

add Swarmauri QR Code Generator Tool #341

add Swarmauri QR Code Generator Tool

add Swarmauri QR Code Generator Tool #341

name: Test Changed Files
on:
pull_request:
paths:
- 'pkgs/**'
workflow_dispatch:
jobs:
detect-changed-files:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.detect.outputs.matrix }}
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch entire history for diffing
- name: Set up Git
run: |
git fetch --all
- name: Get Changed Files (Push)
if: github.event_name == 'push'
run: |
echo "Files changed in this push:"
git diff --name-only ${{ github.event.before }} ${{ github.sha }}
- name: Get Changed Files (Pull Request)
if: github.event_name == 'pull_request'
run: |
echo "Files changed in this pull request:"
git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}
- name: Save Changed Files List (Push)
if: github.event_name == 'push'
run: |
git diff --name-only ${{ github.event.before }} ${{ github.sha }} > changed_files.txt
- name: Save Changed Files List (Pull Request)
if: github.event_name == 'pull_request'
run: |
git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} > changed_files.txt
- name: Output Changed Files
run: |
echo "Changed files:"
cat changed_files.txt
- name: Detect changes and generate test matrix
id: detect
run: |
echo "Detecting changes..."
CHANGED_FILES=$(cat changed_files.txt | grep '^pkgs/')
if [ -z "$CHANGED_FILES" ]; then
echo "No changes detected."
echo "matrix=[]" >> $GITHUB_OUTPUT
exit 0
fi
echo "Changed files:"
echo "$CHANGED_FILES"
declare -A PACKAGE_TEST_MAP
for FILE in $CHANGED_FILES; do
PACKAGE=$(echo "$FILE" | grep -oE '^pkgs/[^/]+' | cut -d/ -f2)
COMPONENT_NAME=$(basename "$FILE" | sed 's/\.py$//')
if echo "$FILE" | grep -qE '/tests/.*_test\.py$'; then
RELATIVE_TEST_FILE=$(echo "$FILE" | sed "s|^pkgs/$PACKAGE/||")
PACKAGE_TEST_MAP[$PACKAGE]="${PACKAGE_TEST_MAP[$PACKAGE]} $RELATIVE_TEST_FILE"
else
TEST_DIR="pkgs/$PACKAGE/tests"
if [ -d "$TEST_DIR" ]; then
MATCHING_TEST_FILES=$(find $TEST_DIR -type f -iname "*${COMPONENT_NAME}*_test.py")
for TEST_FILE in $MATCHING_TEST_FILES; do
RELATIVE_TEST_FILE=$(echo "$TEST_FILE" | sed "s|^pkgs/$PACKAGE/||")
PACKAGE_TEST_MAP[$PACKAGE]="${PACKAGE_TEST_MAP[$PACKAGE]} $RELATIVE_TEST_FILE"
done
fi
fi
done
MATRIX="["
for PACKAGE in "${!PACKAGE_TEST_MAP[@]}"; do
UNIQUE_TEST_FILES=$(echo "${PACKAGE_TEST_MAP[$PACKAGE]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')
MATRIX="$MATRIX{\"package\":\"$PACKAGE\",\"tests\":\"${UNIQUE_TEST_FILES}\"},"
done
MATRIX="${MATRIX%,}]"
echo "Final test matrix: $MATRIX"
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
run-tests:
needs: detect-changed-files
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
if: ${{ needs.detect-changed-files.outputs.matrix != '[]' }}
strategy:
fail-fast: false
matrix:
package_tests: ${{ fromJSON(needs.detect-changed-files.outputs.matrix) }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Log matrix output
run: |
echo "Matrix: ${{ needs.detect-changed-files.outputs.matrix }}"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "PATH=$HOME/.local/bin:$PATH" >> $GITHUB_ENV
- name: Install swarmauri_core package dependency
run: |
cd pkgs/core
poetry install --no-cache --all-extras -vv
- name: Install package dependencies
if: matrix.package_tests.package != 'core'
run: |
cd pkgs/${{ matrix.package_tests.package }}
poetry install --no-cache --all-extras -vv
- name: Run tests and save results
run: |
echo "Running tests for package: ${{ matrix.package_tests.package }}"
echo "Test files: ${{ matrix.package_tests.tests }}"
cd pkgs/${{ matrix.package_tests.package }}
poetry run pytest -v ${{ matrix.package_tests.tests }} -n 4 --dist=loadfile --tb=short --json-report --json-report-file=pytest_results.json || true
- name: Classify test results
run: |
python scripts/classify_json_results.py pkgs/${{ matrix.package_tests.package }}/pytest_results.json --required-passed ge:50 --required-skipped lt:30
continue-on-error: false
- name: Process test results and manage issues
if: |
github.event.pull_request.head.repo.full_name == github.repository && always()
env:
DEEPINFRA_API_KEY: ${{ secrets.DEEPINFRA_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
run: |
cd pkgs/swarmauri # Change to the directory containing pyproject.toml
poetry run python ../../scripts/rag_issue_manager.py --results-file=pytest_results.json --package=${{ matrix.package_tests.package }}