Skip to content

Commit 0fa8e07

Browse files
authored
Merge pull request #43 from bitvavo/ci/automate-release
ci: automate release
2 parents f788acc + ddc4bbd commit 0fa8e07

File tree

5 files changed

+155
-29
lines changed

5 files changed

+155
-29
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: 'Build and Publish Python Package'
2+
description: 'Builds a Python package and uploads it to PyPI.'
3+
4+
inputs:
5+
repository:
6+
description: 'The repository to upload the package to.'
7+
required: true
8+
token:
9+
description: 'The token to authenticate with PyPI.'
10+
required: true
11+
12+
runs:
13+
using: composite
14+
steps:
15+
- name: Build and publish test package
16+
shell: bash
17+
env:
18+
TWINE_REPOSITORY: ${{ inputs.repository }}
19+
TWINE_USERNAME: __token__
20+
TWINE_PASSWORD: ${{ inputs.token }}
21+
run: |
22+
pip install setuptools wheel twine
23+
python setup.py sdist bdist_wheel
24+
twine upload dist/*

.github/workflows/publish.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
env:
9+
python_version: '3.x'
10+
11+
jobs:
12+
publish:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 10
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-python@v5
18+
with:
19+
python-version: ${{ env.python_version }}
20+
- uses: ./.github/actions/python-build-publish
21+
with:
22+
repository: pypi
23+
token: ${{ secrets.pypi_token }}

.github/workflows/release.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Next Version'
8+
required: true
9+
10+
env:
11+
python_version: '3.x'
12+
13+
permissions:
14+
contents: write
15+
16+
jobs:
17+
release:
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 10
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
token: ${{ secrets.release_token }}
24+
25+
- name: Set author in Git
26+
run: |
27+
git config user.name github-actions
28+
git config user.email [email protected]
29+
30+
- uses: actions/setup-python@v5
31+
with:
32+
python-version: ${{ env.python_version }}
33+
34+
- name: Bump version
35+
run: |
36+
python .scripts/bump.py ${{ github.event.inputs.version }}
37+
git commit --message ${{ github.event.inputs.version }} setup.py
38+
git tag v${{ github.event.inputs.version }}
39+
40+
- uses: ./.github/actions/python-build-publish
41+
with:
42+
repository: testpypi
43+
token: ${{ secrets.test_pypi_token }}
44+
45+
- name: Push release commit
46+
run: git push --tags origin ${{ github.ref_name }}
47+
48+
- uses: ncipollo/release-action@v1
49+
with:
50+
tag: v${{ github.event.inputs.version }}
51+
draft: true

.scripts/bump.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import re
2+
import sys
3+
from os import path
4+
5+
if len(sys.argv) < 2:
6+
raise Exception("Please provide a new version number:\n\tbump.py <VERSION>")
7+
8+
new_version = sys.argv[1]
9+
setup_file = path.realpath(path.join(path.dirname(__file__), "..", "setup.py"))
10+
11+
with open(setup_file, "r") as file:
12+
lines = file.readlines()
13+
14+
changed = False
15+
for i, line in enumerate(lines):
16+
if "version=" in line:
17+
line = re.sub(r'"[^"]+"', '"' + new_version + '"', line)
18+
if line != lines[i]:
19+
lines[i] = line
20+
changed = True
21+
22+
if changed:
23+
with open(setup_file, "w") as file:
24+
file.writelines(lines)
25+
print("setup.py changed to version: " + new_version)
26+
else:
27+
print("setup.py did not change")
28+
sys.exit(1)

setup.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
from setuptools import setup, find_packages
2-
from os import path
3-
4-
# read the contents of your README file
5-
this_directory = path.abspath(path.dirname(__file__))
6-
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
7-
long_description = f.read()
8-
9-
setup(
10-
name="python_bitvavo_api",
11-
long_description=long_description,
12-
long_description_content_type='text/markdown',
13-
version="1.2.3",
14-
author="Bitvavo",
15-
description="Use Bitvavo SDK for Python to buy, sell, and store over 200 digital assets on Bitvavo from inside your app.",
16-
url="https://github.com/bitvavo/python-bitvavo-api",
17-
packages=find_packages(),
18-
install_requires=[
19-
'websocket-client',
20-
'requests==2.31.0',
21-
'setuptools'
22-
],
23-
classifiers=[
24-
"Programming Language :: Python :: 3",
25-
"License :: OSI Approved :: ISC License (ISCL)",
26-
"Operating System :: OS Independent",
27-
],
28-
python_requires=">=3.6",
29-
)
1+
from setuptools import setup, find_packages
2+
from os import path
3+
4+
# read the contents of your README file
5+
this_directory = path.abspath(path.dirname(__file__))
6+
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
7+
long_description = f.read()
8+
9+
setup(
10+
name="python_bitvavo_api",
11+
long_description=long_description,
12+
long_description_content_type='text/markdown',
13+
version="1.2.3",
14+
author="Bitvavo",
15+
description="Use Bitvavo SDK for Python to buy, sell, and store over 200 digital assets on Bitvavo from inside your app.",
16+
url="https://github.com/bitvavo/python-bitvavo-api",
17+
packages=find_packages(),
18+
install_requires=[
19+
'websocket-client',
20+
'requests==2.31.0',
21+
'setuptools'
22+
],
23+
classifiers=[
24+
"Programming Language :: Python :: 3",
25+
"License :: OSI Approved :: ISC License (ISCL)",
26+
"Operating System :: OS Independent",
27+
],
28+
python_requires=">=3.6",
29+
)

0 commit comments

Comments
 (0)