-
Notifications
You must be signed in to change notification settings - Fork 0
177 lines (167 loc) · 6.95 KB
/
dependabot_prch.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
175
176
177
name: Dependabot PR Check
# Workflow Processing Flow:
# 1. trigger condition:
# - On pull request to main branch
# - Execution by Dependabot
# - Commit message does not start with “Bump version”.
# 2. job condition check: check for PR by Dependabot
# 3. Set variables using 7rikazhexde/json2vars-setter action
# 4. Set up your time zone (Asia/Tokyo)
# 5. Repository Checkout
# 6. Installing Poetry
# 7. Dependency cache
# 8. Install Project Dependencies
# 9. Test execution and coverage calculation
# 10. Check that coverage is at least 90%.
# 11. Generate test results and coverage reports
# 12. Check test results and display warnings
# 13. Creating Job Summaries
# 14. Confirmation of all test results
# 15. Sending LINE notifications
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/checkout@v4.2.2
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 "os[0]: ${{ fromJson(steps.json2vars.outputs.os)[0] }}"
echo "os[1]: ${{ fromJson(steps.json2vars.outputs.os)[1] }}"
echo "os[2]: ${{ fromJson(steps.json2vars.outputs.os)[2] }}"
echo "versions_python: ${{ steps.json2vars.outputs.versions_python }}"
echo "versions_python[0]: ${{ fromJson(steps.json2vars.outputs.versions_python)[0] }}"
echo "versions_python[1]: ${{ fromJson(steps.json2vars.outputs.versions_python)[1] }}"
echo "versions_python[2]: ${{ fromJson(steps.json2vars.outputs.versions_python)[2] }}"
echo "versions_python[3]: ${{ fromJson(steps.json2vars.outputs.versions_python)[3] }}"
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/checkout@v4.2.2
- name: Set up Python
uses: actions/setup-python@v5.3.0
with:
python-version: ${{matrix.python-version}}
- name: Set timezone
uses: szenius/set-timezone@v2.0
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/cache@v4.2.0
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: poetry install
- name: Run test
shell: bash
id: pytest
# 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
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/pytest-coverage-comment@v1.1.53
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
if: github.actor == 'dependabot[bot]' && !startsWith(github.event.pull_request.title, 'Bump version')
steps:
- name: Send LINE Notify
env:
LINE_NOTIFY_TOKEN: ${{ secrets.LINE_NOTIFY_TOKEN }}
run: |
status="${{ contains(needs.run_tests.result, 'failure') && 'FAILED' || 'SUCCESS' }}"
message="'dependabot_prch' workflow completed with status: ${status}
Check URL:
https://github.com/7rikazhexde/python-project-sandbox/actions/workflows/dependabot_prch.yml"
curl -X POST https://notify-api.line.me/api/notify \
-H "Authorization: Bearer ${LINE_NOTIFY_TOKEN}" \
-F "message=${message}"