Repository navigation
120 lines (104 loc) · 4.28 KB
/
Copy pathci.yml
File metadata and controls
120 lines (104 loc) · 4.28 KB
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
name: CI
on:
push:
branches:
- develop
- main
paths-ignore:
- "**.md"
- "docs/**"
pull_request:
paths-ignore:
- "**.md"
- "docs/**"
merge_group:
concurrency:
group: ci-buzz-${{ github.event.number || github.ref }}
cancel-in-progress: true
jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
name: Server
# pull-requests: write lets the job post the coverage comment.
permissions:
contents: read
pull-requests: write
env:
PYTHONWARNINGS: ignore
services:
redis-cache:
image: redis:alpine
ports:
- 13000:6379
redis-queue:
image: redis:alpine
ports:
- 11000:6379
mariadb:
image: mariadb:11.8
env:
MARIADB_ROOT_PASSWORD: root
ports:
- 3306:3306
options: >-
--health-cmd="healthcheck.sh --connect --innodb_initialized"
--health-interval=5s --health-timeout=2s --health-retries=3
--tmpfs=/var/lib/mysql:rw,noexec,nosuid,size=2g
steps:
- name: Clone
uses: actions/checkout@v4
- name: Find tests
run: |
echo "Finding tests"
grep -rn "def test" > /dev/null
- name: Setup Bench
uses: ./.github/actions/setup-bench
with:
# test_buzz_event imports zoom_integration.tests.zoom_fixtures.
extra-app-url: https://github.com/bwhtech/zoom_integration
- name: Run Tests
working-directory: /home/runner/frappe-bench
run: bench --site test_site run-tests --app buzz --coverage
env:
TYPE: server
# Frappe's --coverage omits test folders but not test_*.py files, so the report
# is rebuilt from the raw data with the test modules left out.
- name: Build coverage report
if: ${{ !cancelled() && github.event_name == 'pull_request' }}
continue-on-error: true
# Reported from the app folder so the table shows paths relative to it.
working-directory: /home/runner/frappe-bench/apps/buzz
run: |
../../env/bin/coverage combine --data-file=../../sites/.coverage ../../sites
../../env/bin/coverage report --data-file=../../sites/.coverage --format=markdown \
--skip-empty --omit='*/test_*.py,*/tests/*' > ../../sites/coverage.md
- name: Comment coverage on the pull request
# A fork's token cannot comment, so only same-repo pull requests get one.
if: ${{ !cancelled() && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
continue-on-error: true
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const REPORT = '/home/runner/frappe-bench/sites/coverage.md';
const MARKER = '<!-- backend-coverage -->';
const MAX_COMMENT_LENGTH = 65000;
if (!fs.existsSync(REPORT)) return core.info('No coverage report was built.');
const table = fs.readFileSync(REPORT, 'utf8').trim();
// --skip-empty appends a note after the table, so the last line is not the total.
const totalRow = table.split('\n').find((line) => line.includes('TOTAL')) || '';
const total = (totalRow.match(/([\d.]+%)/g) || ['unknown']).pop();
const summary = `${MARKER}\n### Backend test coverage: **${total}**\n\nCommit ${context.payload.pull_request.head.sha.slice(0, 7)}. Test modules are excluded.`;
const details = `\n\n<details><summary>Coverage by file</summary>\n\n${table}\n\n</details>`;
const body = summary.length + details.length < MAX_COMMENT_LENGTH ? summary + details : summary;
const issue_number = context.payload.pull_request.number;
const comments = await github.paginate(github.rest.issues.listComments,
{ ...context.repo, issue_number });
const existing = comments.find((comment) => (comment.body || '').includes(MARKER));
if (existing) {
await github.rest.issues.updateComment({ ...context.repo, comment_id: existing.id, body });
} else {
await github.rest.issues.createComment({ ...context.repo, issue_number, body });
}