Skip to content

Commit ef9865a

Browse files
authored
Merge pull request #179 from jooola/publish
ci: setup ci releases publishing
2 parents 8691ae0 + b141292 commit ef9865a

File tree

4 files changed

+116
-3
lines changed

4 files changed

+116
-3
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: CI
22

33
on:
44
push:
5+
tags: ["*.*.*"]
56
branches: [master]
67
pull_request:
78
branches: [master]
@@ -42,7 +43,6 @@ jobs:
4243
runs-on: ubuntu-latest
4344
strategy:
4445
matrix:
45-
os: [ubuntu-latest]
4646
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
4747

4848
steps:
@@ -89,3 +89,28 @@ jobs:
8989
- run: docker-compose images
9090
- run: make install
9191
- run: make e2e
92+
93+
publish:
94+
if: startsWith(github.ref, 'refs/tags')
95+
needs: [pre-commit, lint, test, e2e]
96+
runs-on: ubuntu-latest
97+
98+
steps:
99+
- uses: actions/checkout@v3
100+
101+
- uses: actions/setup-python@v4
102+
with:
103+
python-version: 3.x
104+
105+
- uses: actions/cache@v3
106+
with:
107+
path: ~/.cache/pip
108+
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
109+
restore-keys: |
110+
${{ runner.os }}-pip-
111+
112+
- run: make clean build
113+
114+
- uses: pypa/[email protected]
115+
with:
116+
password: ${{ secrets.PYPI_API_TOKEN }}

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $(VENV):
1414

1515
install: $(VENV)
1616
source $(VENV)/bin/activate
17-
pip install --upgrade pip setuptools wheel
17+
pip install --upgrade pip setuptools wheel build
1818
pip install --editable .[dev]
1919

2020
format: $(VENV)
@@ -48,5 +48,12 @@ e2e: $(VENV)
4848
source $(VENV)/bin/activate
4949
$(PYTEST_CMD) e2e
5050

51+
build: $(VENV)
52+
source $(VENV)/bin/activate
53+
python -m build .
54+
55+
release:
56+
./scripts/release.sh
57+
5158
clean:
52-
rm -Rf $(VENV)
59+
rm -Rf $(VENV) dist

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,31 @@ Response Body: {
113113
>>>
114114
```
115115

116+
## Development
117+
118+
To develop this project, start by reading the `Makefile` to have a basic understanding of the possible tasks.
119+
120+
Install the project and the dependencies in a virtual environment:
121+
122+
```sh
123+
make install
124+
source .venv/bin/activate
125+
```
126+
127+
### Releases
128+
129+
To release a new version, first bump the version number in `setup.py` by hand and run the release target:
130+
131+
```sh
132+
make release
133+
```
134+
135+
Finally, push the release commit and tag to publish them to Pypi:
136+
137+
```sh
138+
git push --follow-tags
139+
```
140+
116141
## License
117142

118143
LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html

scripts/release.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
3+
set -u
4+
5+
error() {
6+
echo >&2 "error: $*"
7+
exit 1
8+
}
9+
10+
# This scripts will:
11+
# - Expect the setup.py file to have new version
12+
# - Stash the setup.py file
13+
# - Check for clean state (no uncommitted changes), exit if failed
14+
# - Clean the project
15+
# - Install the project, lint and runt tests, exit if failed
16+
# - Unstash the pyproject version bump and commit a new Release
17+
# - Tag the new release
18+
# - Show instruction to push tags and changes to github
19+
20+
command -v make > /dev/null || error "make command not found!"
21+
command -v git > /dev/null || error "git command not found!"
22+
command -v python3 > /dev/null || error "python3 command not found!"
23+
24+
setup="setup.py"
25+
default_branch="master"
26+
27+
[[ "$(git rev-parse --show-toplevel)" == "$(pwd)" ]] || error "please go to the project root directory!"
28+
[[ "$(git rev-parse --abbrev-ref HEAD)" == "$default_branch" ]] || error "please change to the $default_branch git branch!"
29+
30+
pkg_version=$(python3 setup.py --version || error "could not determine package version in $setup!")
31+
git_version=$(git describe --abbrev=0 --tags || error "could not determine git version!")
32+
33+
# No version change
34+
if [[ "$pkg_version" == "$git_version" ]]; then
35+
echo "Latest git tag '$pkg_version' and package version '$git_version' match, edit your $setup to change the version before running this script!"
36+
exit
37+
fi
38+
39+
git stash push --quiet -- "$setup"
40+
trap 'e=$?; git stash pop --quiet; exit $e' EXIT
41+
42+
[[ -z "$(git status --porcelain)" ]] || error "please commit or clean the changes before running this script!"
43+
44+
git clean -xdf
45+
46+
make lint test || error "tests failed, please correct the errors"
47+
48+
new_tag="$pkg_version"
49+
release="chore: release $new_tag"
50+
51+
git stash pop --quiet
52+
git add "$setup" || error "could not stage $setup!"
53+
git commit -m "$release" --no-verify || error "could not commit the version bump!"
54+
git tag "$new_tag" -a -m "$release" || error "could not tag the version bump!"
55+
56+
echo "Run 'git push --follow-tags' in order to publish the release on Github!"

0 commit comments

Comments
 (0)