Skip to content

Commit dba2b85

Browse files
committed
ci: fix github action for test python
1 parent d91f3e9 commit dba2b85

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

.github/workflows/test_python.yaml

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ on:
44
push:
55
branches:
66
- main
7-
8-
env:
9-
DEFAULT_PYTHON_VERSION: 3.12
10-
PROGRAMMERS_PYTHON_VERSION: 3.8
11-
7+
128
jobs:
139
detect-changes:
1410
runs-on: ubuntu-latest
@@ -23,28 +19,27 @@ jobs:
2319
id: detect-changes
2420
run: |
2521
git config core.quotepath false
26-
22+
2723
if git rev-parse HEAD~1 >/dev/null 2>&1; then
2824
base_commit="HEAD~1"
2925
else
3026
base_commit="HEAD"
3127
fi
32-
33-
changed_dirs=$(git diff --name-only $base_commit HEAD | sed 's/^"//;s/"$//' | grep -E '.py$' | awk -F'/' '{OFS="/"; $NF=""; print $0}' | sed 's/\/$//' | sort -u || true)
28+
29+
# 파이썬 파일이 수정된 디렉토리만 추출
30+
changed_dirs=$(git diff --name-only $base_commit HEAD | grep -E '\.py$' | awk -F'/' '{OFS="/"; $NF=""; print $0}' | sed 's/\/$//' | sort -u || true)
3431
3532
json="["
3633
for dir in $changed_dirs; do
3734
if [ -d "$dir" ]; then
38-
json+="{\"dir\":\"$dir\","
39-
if [[ "$dir" == programmers* ]]; then
40-
json+="\"python_version\":\"${{ env.PROGRAMMERS_PYTHON_VERSION }}\"},"
41-
else
42-
json+="\"python_version\":\"${{ env.DEFAULT_PYTHON_VERSION }}\"},"
43-
fi
35+
root=$(echo "$dir" | awk -F'/' '{print $1"/"$2}')
36+
version_file="$root/.python-version"
37+
38+
json+="{\"dir\":\"$dir\",\"python_version\":\"$(cat "$version_file" | tr -d '\r\n')\"},"
4439
fi
4540
done
46-
json="${json%,}]"
4741
42+
json="${json%,}]"
4843
echo "matrix=$json" >> $GITHUB_OUTPUT
4944
shell: bash
5045

@@ -58,7 +53,7 @@ jobs:
5853
steps:
5954
- uses: actions/checkout@v4
6055

61-
- name: Set up Python
56+
- name: Set up Python ${{ matrix.python_version }}
6257
uses: actions/setup-python@v5
6358
with:
6459
python-version: ${{ matrix.python_version }}
@@ -68,6 +63,6 @@ jobs:
6863
python -m pip install --upgrade pip
6964
pip install pytest parameterized
7065
71-
- name: Run Tests
66+
- name: Run Tests in ${{ matrix.dir }}
7267
run: |
7368
pytest ${{ matrix.dir }}/test_main.py

baekjoon/python/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

programmers/python/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.8

0 commit comments

Comments
 (0)