-
Notifications
You must be signed in to change notification settings - Fork 9
131 lines (127 loc) · 4.4 KB
/
Copy pathpython-package.yml
File metadata and controls
131 lines (127 loc) · 4.4 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
121
122
123
124
125
126
127
128
129
130
131
# 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: build
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
id-token: write
contents: read
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
package: ${{ steps.pkg.outputs.package }}
pypi_url: ${{ steps.pkg.outputs.pypi_url }}
steps:
- name: Compute package name from the repository's
id: pkg
run: |
name="${GITHUB_REPOSITORY##*/}"
echo "package=${name#python-}" >> $GITHUB_OUTPUT
echo "pypi_url=https://pypi.org/p/${name#python-}" >> $GITHUB_OUTPUT
build:
needs: prepare
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
env:
package: ${{ needs.prepare.outputs.package }}
steps:
- uses: actions/checkout@v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install pandoc
run: sudo apt-get install -y pandoc
- name: Install ${{ env.package }}
run: |
python -m pip install --upgrade pip
python -m pip install pytest pytest-cov coverage
pip install -r requirements.txt
pip install .
- name: Test ${{ env.package }} with pytest
run: |
pytest --cov=$package
coverage:
needs: [prepare, build]
permissions:
contents: write
runs-on: ubuntu-latest
env:
cov_badge_path: docs/coverage.svg
package: ${{ needs.prepare.outputs.package }}
python_version: "3.13"
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
ref: ${{ (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.pull_request.head.sha || github.sha }}
- name: Set up Python ${{ env.python_version }}
uses: actions/setup-python@v6
with:
python-version: ${{ env.python_version }}
- name: Install pandoc
run: sudo apt-get install -y pandoc
- name: Install ${{ env.package }}
run: |
python -m pip install --upgrade pip
python -m pip install pytest pytest-cov
pip install -r requirements.txt
pip install .
- name: Make coverage badge for ${{ env.package }}
run: |
pip install genbadge[coverage]
pytest --cov=$package --cov-report=xml
genbadge coverage -i coverage.xml -o $cov_badge_path
- name: Verify Changed files
uses: tj-actions/verify-changed-files@v20
id: changed_files
with:
files: ${{ env.cov_badge_path }}
- name: Push coverage badge
if: steps.changed_files.outputs.files_changed == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git fetch origin
git checkout coverage-badge || git checkout -b coverage-badge
git add $cov_badge_path
git diff --cached --quiet && exit 0
git commit -m "Update coverage badge"
git push origin coverage-badge --force
deploy:
environment:
name: pypi
url: ${{ needs.prepare.outputs.pypi_url }}
runs-on: ubuntu-latest
needs: [prepare, coverage]
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Check for version change
uses: dorny/paths-filter@v4
id: filter
with:
filters: |
version:
- '**/VERSION.txt'
- if: steps.filter.outputs.version == 'true'
name: Cleanup README
run: |
sed -ri 's/^(##*)\s*:.*:\s*/\1 /g' README.md
awk '{if (match($0,"## Supporters")) exit; print}' README.md > README
mv -f README README.md
- if: steps.filter.outputs.version == 'true'
name: Build ${{ needs.prepare.outputs.package }} package
run: python3 -m pip install --upgrade build && python3 -m build
- if: steps.filter.outputs.version == 'true'
name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1