Skip to content

Commit 755ceae

Browse files
authored
chore: add release automation (#1105)
1 parent e620f2a commit 755ceae

63 files changed

Lines changed: 2293 additions & 1578 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[report]
2-
exclude_lines =
2+
exclude_lines =
33
pragma: no cover
44
if TYPE_CHECKING:
55
if sys.version_info

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
exclude = docs
3+
max-line-length = 180
4+
extend-ignore = E203

.github/workflows/ci.yml

Lines changed: 160 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,174 @@ on:
55
branches:
66
- master
77
pull_request:
8-
branches:
9-
- "**"
8+
9+
concurrency:
10+
group: ${{ github.head_ref || github.run_id }}
11+
cancel-in-progress: true
1012

1113
jobs:
12-
build:
13-
runs-on: ${{ matrix.os }}
14+
lint:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-python@v3
19+
with:
20+
python-version: "3.9"
21+
- uses: pre-commit/action@v2.0.3
22+
23+
# Make sure commit messages follow the conventional commits convention:
24+
# https://www.conventionalcommits.org
25+
commitlint:
26+
name: Lint Commit Messages
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v3
30+
with:
31+
fetch-depth: 0
32+
- uses: wagoid/commitlint-github-action@v4.1.11
33+
34+
test:
1435
strategy:
36+
fail-fast: false
1537
matrix:
16-
os: [ubuntu-latest, macos-latest, windows-latest]
17-
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "pypy-3.7"]
18-
include:
19-
- os: ubuntu-latest
20-
venvcmd: . env/bin/activate
38+
python-version:
39+
- "3.7"
40+
- "3.8"
41+
- "3.9"
42+
- "3.10"
43+
- "3.11"
44+
- "pypy-3.7"
45+
os:
46+
- ubuntu-latest
47+
- macos-latest
48+
- windows-latest
49+
extension:
50+
- "skip_cython"
51+
- "use_cython"
52+
exclude:
2153
- os: macos-latest
22-
venvcmd: . env/bin/activate
54+
extension: use_cython
2355
- os: windows-latest
24-
venvcmd: env\Scripts\Activate.ps1
56+
extension: use_cython
57+
- os: windows-latest
58+
python-version: "pypy-3.7"
59+
runs-on: ${{ matrix.os }}
2560
steps:
26-
- uses: actions/checkout@v2
27-
- name: Set up Python ${{ matrix.python-version }}
28-
uses: actions/setup-python@v2
61+
- uses: actions/checkout@v3
62+
- name: Install poetry
63+
run: pipx install poetry
64+
- name: Set up Python
65+
uses: actions/setup-python@v4
2966
with:
3067
python-version: ${{ matrix.python-version }}
31-
architecture: 'x64'
32-
- uses: actions/cache@v2
33-
id: cache
68+
cache: "poetry"
69+
- name: Install Dependencies no cython
70+
if: ${{ matrix.extension == 'skip_cython' }}
71+
env:
72+
SKIP_CYTHON: 1
73+
run: poetry install --only=main,dev
74+
- name: Install Dependencies with cython
75+
if: ${{ matrix.extension != 'skip_cython' }}
76+
run: poetry install --only=main,dev
77+
- name: Test with Pytest
78+
run: poetry run pytest --durations=20 --timeout=60 -v --cov=zeroconf --cov-branch --cov-report xml --cov-report html --cov-report term-missing tests
79+
- name: Upload coverage to Codecov
80+
uses: codecov/codecov-action@v3
3481
with:
35-
path: env
36-
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/Makefile') }}-${{ hashFiles('**/requirements-dev.txt') }}
37-
restore-keys: |
38-
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/Makefile') }}
39-
- name: Install dependencies
40-
if: steps.cache.outputs.cache-hit != 'true'
41-
run: |
42-
python -m venv env
43-
${{ matrix.venvcmd }}
44-
pip install --upgrade -r requirements-dev.txt pytest-github-actions-annotate-failures
45-
- name: Validate readme
46-
if: ${{ runner.os == 'Linux' && matrix.python-version != 'pypy-3.7' }}
47-
run: |
48-
${{ matrix.venvcmd }}
49-
python -m readme_renderer README.rst -o -
50-
- name: Run flake8
51-
if: ${{ runner.os == 'Linux' && matrix.python-version != 'pypy-3.7' }}
52-
run: |
53-
${{ matrix.venvcmd }}
54-
make flake8
55-
- name: Run mypy
56-
if: ${{ runner.os == 'Linux' && matrix.python-version != 'pypy-3.7' }}
57-
run: |
58-
${{ matrix.venvcmd }}
59-
make mypy
60-
- name: Run black_check
61-
if: ${{ runner.os == 'Linux' && matrix.python-version != 'pypy-3.7' }}
62-
run: |
63-
${{ matrix.venvcmd }}
64-
make black_check
65-
- name: Run tests
82+
token: ${{ secrets.CODECOV_TOKEN }}
83+
84+
release:
85+
runs-on: ubuntu-latest
86+
environment: release
87+
if: github.ref == 'refs/heads/master'
88+
needs:
89+
- test
90+
- lint
91+
- commitlint
92+
93+
steps:
94+
- uses: actions/checkout@v3
95+
with:
96+
fetch-depth: 0
97+
98+
# Run semantic release:
99+
# - Update CHANGELOG.md
100+
# - Update version in code
101+
# - Create git tag
102+
# - Create GitHub release
103+
# - Publish to PyPI
104+
- name: Python Semantic Release
105+
uses: relekang/python-semantic-release@v7.32.2
106+
with:
107+
github_token: ${{ secrets.GITHUB_TOKEN }}
108+
pypi_token: ${{ secrets.PYPI_TOKEN }}
109+
110+
build_wheels:
111+
needs: [release]
112+
113+
name: Build wheels on ${{ matrix.os }}
114+
runs-on: ${{ matrix.os }}
115+
strategy:
116+
matrix:
117+
os: [ubuntu-20.04, windows-2019, macOS-11]
118+
119+
steps:
120+
- uses: actions/checkout@v3
121+
with:
122+
fetch-depth: 0
123+
ref: "master"
124+
125+
# Used to host cibuildwheel
126+
- name: Set up Python
127+
uses: actions/setup-python@v4
128+
129+
- name: Install python-semantic-release
130+
run: python -m pip install python-semantic-release
131+
132+
- name: Get Release Tag
133+
id: release_tag
134+
shell: bash
66135
run: |
67-
${{ matrix.venvcmd }}
68-
make test_coverage
69-
- name: Report coverage to Codecov
70-
uses: codecov/codecov-action@v1
136+
echo "::set-output name=newest_release_tag::$(semantic-release print-version --current)"
137+
138+
- uses: actions/checkout@v3
139+
with:
140+
ref: "v${{ steps.release_tag.outputs.newest_release_tag }}"
141+
fetch-depth: 0
142+
143+
- name: Install cibuildwheel
144+
run: python -m pip install cibuildwheel==2.11.3
145+
146+
- name: Build wheels
147+
run: python -m cibuildwheel --output-dir wheelhouse
148+
# to supply options, put them in 'env', like:
149+
env:
150+
CIBW_SKIP: cp36-*
151+
CIBW_BEFORE_ALL_LINUX: apt-get install -y gcc || yum install -y gcc || apk add gcc
152+
CIBW_BUILD_VERBOSITY: 3
153+
REQUIRE_CYTHON: 1
154+
155+
- uses: actions/upload-artifact@v3
156+
with:
157+
path: ./wheelhouse/*.whl
158+
159+
upload_pypi:
160+
needs: [build_wheels]
161+
runs-on: ubuntu-latest
162+
environment: release
163+
164+
steps:
165+
- uses: actions/download-artifact@v3
166+
with:
167+
# unpacks default artifact into dist/
168+
# if `name: artifact` is omitted, the action will create extra parent dir
169+
name: artifact
170+
path: dist
171+
172+
- uses: pypa/gh-action-pypi-publish@v1.5.0
173+
with:
174+
user: __token__
175+
password: ${{ secrets.PYPI_TOKEN }}
176+
repository_url: https://test.pypi.org/legacy/
177+
178+
# To test: repository_url: https://test.pypi.org/legacy/

.pre-commit-config.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
exclude: "CHANGELOG.md"
4+
default_stages: [commit]
5+
6+
ci:
7+
autofix_commit_msg: "chore(pre-commit.ci): auto fixes"
8+
autoupdate_commit_msg: "chore(pre-commit.ci): pre-commit autoupdate"
9+
10+
repos:
11+
- repo: https://github.com/commitizen-tools/commitizen
12+
rev: v2.32.4
13+
hooks:
14+
- id: commitizen
15+
stages: [commit-msg]
16+
- repo: https://github.com/pre-commit/pre-commit-hooks
17+
rev: v4.3.0
18+
hooks:
19+
- id: debug-statements
20+
- id: check-builtin-literals
21+
- id: check-case-conflict
22+
- id: check-docstring-first
23+
- id: check-json
24+
- id: check-toml
25+
- id: check-xml
26+
- id: check-yaml
27+
- id: detect-private-key
28+
- id: end-of-file-fixer
29+
- id: trailing-whitespace
30+
- id: debug-statements
31+
- repo: https://github.com/pre-commit/mirrors-prettier
32+
rev: v2.7.1
33+
hooks:
34+
- id: prettier
35+
args: ["--tab-width", "2"]
36+
- repo: https://github.com/asottile/pyupgrade
37+
rev: v2.37.3
38+
hooks:
39+
- id: pyupgrade
40+
args: [--py37-plus]
41+
- repo: https://github.com/PyCQA/isort
42+
rev: 5.10.1
43+
hooks:
44+
- id: isort
45+
- repo: https://github.com/psf/black
46+
rev: 22.8.0
47+
hooks:
48+
- id: black
49+
# - repo: https://github.com/codespell-project/codespell
50+
# rev: v2.2.1
51+
# hooks:
52+
# - id: codespell
53+
- repo: https://github.com/PyCQA/flake8
54+
rev: 5.0.4
55+
hooks:
56+
- id: flake8
57+
- repo: https://github.com/pre-commit/mirrors-mypy
58+
rev: v0.931
59+
hooks:
60+
- id: mypy
61+
additional_dependencies: []

0 commit comments

Comments
 (0)