Skip to content

Commit 4935e88

Browse files
committed
ci: fix github action for test baekjoon python
1 parent 4350d83 commit 4935e88

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

.github/workflows/test_baekjoon_python.yml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,44 @@ on:
66
- main
77

88
jobs:
9-
generate-matrix:
9+
detect-changes:
1010
runs-on: ubuntu-latest
1111
outputs:
12-
matrix: ${{ steps.generate-matrix.outputs.matrix }}
12+
matrix: ${{ steps.detect-changes.outputs.matrix }}
1313
steps:
1414
- uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 2
1517

16-
- name: Generate matrix
17-
id: generate-matrix
18+
- name: Detect changed files
19+
id: detect-changes
1820
run: |
19-
dirs=$(find baekjoon/python -mindepth 1 -maxdepth 1 -type d)
21+
if git rev-parse HEAD~1 >/dev/null 2>&1; then
22+
base_commit="HEAD~1"
23+
else
24+
base_commit="HEAD"
25+
fi
26+
27+
changed_dirs=$(git diff --name-only $base_commit HEAD | grep '^baekjoon/python' | awk -F'/' '{print $1"/"$2"/"$3}' | sort -u || true)
28+
2029
json="["
21-
for dir in $dirs; do
22-
json+="\"$dir\","
30+
for dir in $changed_dirs; do
31+
if [ -d "$dir" ]; then
32+
json+="\"$dir\","
33+
fi
2334
done
2435
json="${json%,}]"
36+
2537
echo "matrix=$json" >> $GITHUB_OUTPUT
2638
shell: bash
2739

2840
run-tests:
29-
needs: generate-matrix
41+
needs: detect-changes
3042
runs-on: ubuntu-latest
43+
if: needs.detect-changes.outputs.matrix != '[]'
3144
strategy:
3245
matrix:
33-
dir: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
46+
dir: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
3447
steps:
3548
- uses: actions/checkout@v4
3649

@@ -46,4 +59,4 @@ jobs:
4659
4760
- name: Run Tests
4861
run: |
49-
pytest ${{ matrix.dir }}/test_main.py
62+
pytest ${{ matrix.dir }}/test_main.py

0 commit comments

Comments
 (0)