-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (142 loc) · 5.11 KB
/
build-test-publish.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
name: Build, Test, and Publish Python Package
on: [push]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Lint with autopep8 and get statistics from flake8
run: |
# exit-zero treats all errors as warnings.
# show statistics for Python syntax errors or undefined names.
# the GitHub editor is 127 chars wide.
flake8 . --count --exit-zero --extend-ignore E402 --max-complexity=10 --max-line-length=127 --show-source --statistics
# stop the build if there are Python syntax errors.
autopep8 . --ignore E402 --recursive --diff --exit-code
- name: Install local package
run: |
python -m pip install --editable .
- name: Test with pytest
run: |
coverage run -m pytest
- name: Report coverage statistics on modules
run: |
coverage report --fail-under=80 --show-missing
- name: Type checking with mypy
run: |
mypy --strict --exclude='src' .
build:
needs: [test]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.11"]
env:
PACKAGE_NAME: bytecorecompiler
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- name: Setup Python
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -r requirements.txt
- name: Build package
run: python -m build
- name: Test self building package
run: |
pip install dist/${{ env.PACKAGE_NAME }}-*.tar.gz
python -c "import ${{ env.PACKAGE_NAME }}; print(${{ env.PACKAGE_NAME }})"
shell: bash
- name: Upload distribution archives
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874
with:
name: distribution-archives-${{ matrix.os }}-${{ matrix.python-version }}
path: dist
combine:
needs: [test, build]
runs-on: ubuntu-latest
steps:
- name: Download All Artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
path: distribution-archives
pattern: distribution-archives-*
merge-multiple: true
- name: List distribution archives
run: ls --recursive distribution-archives
- name: Upload combined distribution archives
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874
with:
name: combined-distribution-archives
path: distribution-archives
publish:
if: startsWith(github.ref, 'refs/tags/')
needs: [test, build, combine]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/bytecorecompiler
permissions:
id-token: write
env:
PACKAGE_NAME: bytecorecompiler
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- name: Download combined distribution archives
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
name: combined-distribution-archives
path: dist
- name: List dist folder
run: ls --recursive dist
- name: Extract and store tag
run: |
TAG=${GITHUB_REF#refs/tags/}
echo "Tag: $TAG"
echo "TAG=$TAG" >> $GITHUB_ENV
- name: Verify version in combined distribution archives
run: |
for file in dist/*; do
filename=$(basename "$file")
if [[ $filename != ${{ env.PACKAGE_NAME }}-$TAG* ]]; then
echo "File $filename does not start with ${{ env.PACKAGE_NAME }}-$TAG"
exit 1
fi
done
echo "All files in dist directory start with ${{ env.PACKAGE_NAME }}-$TAG"
- name: Verify existence of source distribution archive
run: |
if [[ ! -f dist/${{ env.PACKAGE_NAME }}-$TAG.tar.gz ]]; then
echo "Error: dist/${{ env.PACKAGE_NAME }}-$TAG.tar.gz does not exist."
exit 1
fi
echo "dist/${{ env.PACKAGE_NAME }}-$TAG.tar.gz exists."
- name: Verify version in pyproject.toml
run: |
VERSION=$(grep --perl-regexp --only-matching '(?<=^version = ")[^"]*' pyproject.toml)
if [[ "$VERSION" != "$TAG" ]]; then
echo "Version in pyproject.toml $VERSION does not match the tag $TAG"
exit 1
fi
echo "Version in pyproject.toml matches the tag: $VERSION"
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@0ab0b79471669eb3a4d647e625009c62f9f3b241
with:
verify-metadata: true
skip-existing: false
verbose: false
print-hash: true