-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (157 loc) · 5.63 KB
/
python-package.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
# This workflow will install Python dependencies, run tests, and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python package
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
lint:
runs-on:
- self-hosted
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: 3.12
- name: Install Poetry
uses: abatilo/actions-poetry@v2
- name: Install dependencies
run: poetry install --with dev
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
type-check:
runs-on:
- self-hosted
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: 3.12
- name: Install Poetry
uses: abatilo/actions-poetry@v2
- name: Install dependencies
run: poetry install --with dev
- name: Type check with mypy
run: poetry run mypy mallm/
test:
runs-on:
- self-hosted
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: abatilo/actions-poetry@v2
- name: Install dependencies
run: poetry install --with dev
- name: Test with pytest
run: poetry run pytest
coverage:
runs-on:
- self-hosted
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: 3.12
- name: Install Poetry
uses: abatilo/actions-poetry@v2
- name: Install dependencies
run: poetry install --with dev
- name: Test with pytest and generate coverage report
run: |
poetry run coverage run -m pytest
poetry run coverage report
poetry run coverage xml
poetry run coverage-badge -o coverage.svg
- name: Commit and push coverage badge
if: github.event_name == 'push'
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git checkout -b gh-pages
mkdir -p docs
mv coverage.svg docs/coverage.svg
git add docs/coverage.svg
git commit -m 'Update coverage badge'
git push origin gh-pages --force
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Post coverage result as PR comment
if: github.event_name == 'pull_request'
run: |
poetry run coverage report > coverage_report.txt
echo '### Coverage Report' > coverage_comment.md
echo '```' >> coverage_comment.md
cat coverage_report.txt >> coverage_comment.md
echo '```' >> coverage_comment.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update or Create Pull Request Comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const commentBody = fs.readFileSync('coverage_comment.md', 'utf8');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
});
const botComment = comments.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('### Coverage Report'));
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody,
});
} else {
await github.rest.issues.createComment({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody,
});
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update-readme:
if: github.event.pull_request
runs-on:
- self-hosted
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: 3.12
- name: Install Poetry
uses: abatilo/actions-poetry@v2
- name: Install dependencies
run: poetry install --with dev
- name: Replace Text in README
run: poetry run python update_readme.py
- name: Commit Changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git diff --quiet || (git add README.md && git commit -m "Updated README")
git push