-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (164 loc) · 6.81 KB
/
prch_test_matrix_json.yml
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
163
164
165
166
167
168
169
170
171
172
173
174
name: PR Check (Except Dependabot)
# ワークフローの処理の流れ:
# 1. トリガー条件:
# - mainブランチへのプルリクエスト時
# - Dependabotによる実行でないこと
# - コミットメッセージが"Bump version"で始まっていないこと
# 2. ジョブの条件判定: Dependabot によるPRでないことをチェック
# 3. OS毎の環境設定 (macos-latest, ubuntu-latest, windows-latest)
# 4. Python環境のセットアップ (3.11, 3.12)
# 5. タイムゾーンの設定 (Asia/Tokyo)
# 6. リポジトリのチェックアウト
# 7. Poetry のインストール
# 8. 依存関係のキャッシュ
# 9. プロジェクト依存関係のインストール
# 10. テストの実行とカバレッジの計算
# 11. カバレッジが90%以上であることのチェック
# 12. テスト結果とカバレッジレポートの生成
# 13. テスト結果の確認と警告の表示
# 14. ジョブサマリーの作成
# 15. 全テストの結果確認
# 16. LINE通知の送信
on:
pull_request:
branches: "main"
jobs:
set_variables:
if: github.actor != 'dependabot[bot]' && !startsWith(github.event.pull_request.title, 'Bump version')
runs-on: ubuntu-latest
outputs:
os: ${{ steps.json2vars.outputs.os }}
versions_python: ${{ steps.json2vars.outputs.versions_python }}
ghpages_branch: ${{ steps.json2vars.outputs.ghpages_branch }}
steps:
- name: Checkout repository
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Set variables from JSON
id: json2vars
uses: 7rikazhexde/json2vars-setter@main
with:
json-file: .github/workflows/matrix.json
- name: Debug output values
run: |
echo "os: ${{ steps.json2vars.outputs.os }}"
echo "versions_python: ${{ steps.json2vars.outputs.versions_python }}"
echo "ghpages_branch: ${{ steps.json2vars.outputs.ghpages_branch }}"
run_tests:
needs: set_variables
strategy:
matrix:
os: ${{ fromJson(needs.set_variables.outputs.os) }}
python-version: ${{ fromJson(needs.set_variables.outputs.versions_python) }}
runs-on: ${{ matrix.os }}
env:
TZ: 'Asia/Tokyo'
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/[email protected]
- name: Set up Python
uses: actions/[email protected]
with:
python-version: ${{matrix.python-version}}
- name: Set timezone
uses: szenius/[email protected]
with:
timezoneLinux: "Asia/Tokyo"
timezoneMacos: "Asia/Tokyo"
timezoneWindows: "Tokyo Standard Time"
- name: Check timezone
shell: bash
run: |
echo "System date: $(date)"
echo "TZ environment variable: $TZ"
python -c "import datetime, platform; print(f'Python timezone: {datetime.datetime.now().astimezone().tzinfo}'); print(f'OS: {platform.system()}')"
- name: Install poetry
run: pip install poetry
- name: Cache dependencies
uses: actions/[email protected]
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: poetry install
- name: Run test
id: pytest
shell: bash
# Mac / Linux
# run: poetry run pytest --durations=0 --junitxml=pytest.xml --cov-report xml:coverage.xml --cov=project_a tests/ | tee pytest-coverage.txt
# Windowss
# run: poetry run pytest --durations=0 --junitxml=pytest.xml --cov-report xml:coverage.xml --cov=project_a tests/ | Tee-Object -FilePath pytest-coverage.txt
run: |
poetry run task test_ci_xml
coverage_percentage=$(poetry run coverage report | grep TOTAL | awk '{print $NF}' | sed 's/%//')
echo "Current coverage: $coverage_percentage%"
echo "COVERAGE=$coverage_percentage" >> "$GITHUB_ENV"
- name: Check coverage
shell: bash
#if: ${{ env.COVERAGE < 90 }}
#run: |
# echo "Test coverage is below 90%. Current coverage: ${{ env.COVERAGE }}%"
# exit 1
run: |
if [ "$COVERAGE" -lt 90 ]; then
echo "Test coverage is below 90%. Current coverage: $COVERAGE%"
exit 1
else
echo "Test coverage is above or equal to 90%. Current coverage: $COVERAGE%"
fi
- name: Pytest coverage comment
id: coverageComment
uses: MishaKav/[email protected]
with:
pytest-coverage-path: ./pytest-coverage.txt
pytest-xml-coverage-path: ./coverage.xml
title: Coverage Report (${{ matrix.os }} / Python ${{ matrix.python-version }})
badge-title: coverage
hide-badge: false
hide-report: false
create-new-comment: true
hide-comment: false
report-only-changed-files: false
remove-link-from-badge: false
junitxml-path: ./pytest.xml
junitxml-title: "Pytest Result Summary (os: ${{ matrix.os }} / python-version: ${{ matrix.python-version }})"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Check test results
if: steps.pytest.outcome == 'failure'
run: |
echo "Tests failed. This will be reported in the workflow summary."
echo "::warning::Tests failed on ${{ matrix.os }} with Python ${{ matrix.python-version }}"
- name: Write job summary
id: check_status
shell: bash
run: |
echo -e ${{ steps.coverageComment.outputs.summaryReport }} >> "$GITHUB_STEP_SUMMARY"
check_all_tests:
needs: run_tests
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]' && !startsWith(github.event.pull_request.title, 'Bump version')
steps:
- name: Check test results
if: contains(needs.run_tests.result, 'failure')
run: |
echo "Some tests failed. Please check the test results and fix any issues before merging."
exit 1
send_notification:
needs: [run_tests, check_all_tests]
runs-on: ubuntu-latest
steps:
# https://docs.github.com/ja/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-an-environment
- name: Send LINE Notify
env:
LINE_NOTIFY_TOKEN: ${{ secrets.LINE_ACCESS_TOKEN }}
run: |
status="${{ contains(needs.run_tests.result, 'failure') && 'FAILED' || 'SUCCESS' }}"
message="'pullrequest_check.yml' workflow completed with status: $status
Check URL:
https://github.com/7rikazhexde/python-project-sandbox/actions/workflows/pullrequest_check.yml"
curl -X POST https://notify-api.line.me/api/notify \
-H "Authorization: Bearer $LINE_NOTIFY_TOKEN" \
-F "message=${message}"