DecAgentAPI implementation #299
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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 all tests for the package | |
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 ${{ matrix.package_tests.tests }} |