-
Notifications
You must be signed in to change notification settings - Fork 43
162 lines (133 loc) · 5.66 KB
/
test_changed_files.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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 }}