Skip to content

Commit abc9a26

Browse files
committed
[patch] Introduce automatic versioning
1 parent 3d60611 commit abc9a26

File tree

5 files changed

+150
-87
lines changed

5 files changed

+150
-87
lines changed
Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,63 @@
1-
name: Python Package
2-
1+
name: Build Python Package
32
on:
43
push:
5-
branches: [ "*" ]
6-
4+
branches: [ "**" ]
5+
tags-ignore: [ "**" ]
76
jobs:
8-
build:
7+
build-package:
98
runs-on: ubuntu-latest
10-
strategy:
11-
fail-fast: false
12-
matrix:
13-
python-version: ["3.9", "3.10", "3.11"]
14-
primary-config: ["true", "false"]
15-
# There may be a better way to do this, but it was the first way I found to set a variable for specific matrix entry
16-
exclude:
17-
- python-version: "3.9"
18-
primary-config: "true"
19-
- python-version: "3.10"
20-
primary-config: "true"
21-
- python-version: "3.11"
22-
primary-config: "false"
239
steps:
24-
- uses: actions/checkout@v4
25-
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v3
27-
with:
28-
python-version: ${{ matrix.python-version }}
29-
- name: Install
30-
run: |
31-
python -m pip install --upgrade pip
32-
python -m pip install .[dev] flake8
33-
- name: Lint with flake8
34-
run: |
35-
# stop the build if there are Python syntax errors or undefined names
36-
flake8 src --count --select=E9,F63,F7,F82 --show-source --statistics
37-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
38-
flake8 src --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
39-
- name: Test with pytest (only on Python 3.11 to avoid concurrency issues)
40-
if: ${{ (github.ref == 'refs/heads/master') && (matrix.primary-config == 'true') }}
41-
env:
42-
ONE_JOB_ONLY_TESTS: ${{ matrix.primary-config }}
43-
WIOTP_API_KEY: ${{ secrets.WIOTP_API_KEY }}
44-
WIOTP_API_TOKEN: ${{ secrets.WIOTP_API_TOKEN }}
45-
WIOTP_ORG_ID: ${{ secrets.WIOTP_ORG_ID }}
46-
CLOUDANT_HOST: ${{ secrets.CLOUDANT_HOST }}
47-
CLOUDANT_PORT: ${{ secrets.CLOUDANT_PORT }}
48-
CLOUDANT_USERNAME: ${{ secrets.CLOUDANT_USERNAME }}
49-
CLOUDANT_PASSWORD: ${{ secrets.CLOUDANT_PASSWORD }}
50-
EVENTSTREAMS_API_KEY: ${{ secrets.EVENTSTREAMS_API_KEY }}
51-
EVENTSTREAMS_ADMIN_URL: ${{ secrets.EVENTSTREAMS_ADMIN_URL }}
52-
EVENTSTREAMS_BROKER1: ${{ secrets.EVENTSTREAMS_BROKER1 }}
53-
EVENTSTREAMS_BROKER2: ${{ secrets.EVENTSTREAMS_BROKER2 }}
54-
EVENTSTREAMS_BROKER3: ${{ secrets.EVENTSTREAMS_BROKER3 }}
55-
EVENTSTREAMS_BROKER4: ${{ secrets.EVENTSTREAMS_BROKER4 }}
56-
EVENTSTREAMS_BROKER5: ${{ secrets.EVENTSTREAMS_BROKER5 }}
57-
EVENTSTREAMS_BROKER6: ${{ secrets.EVENTSTREAMS_BROKER6 }}
58-
EVENTSTREAMS_USER: ${{ secrets.EVENTSTREAMS_USER }}
59-
EVENTSTREAMS_PASSWORD: ${{ secrets.EVENTSTREAMS_PASSWORD }}
60-
run: |
61-
pytest
10+
# 1. Initialize the build
11+
# -------------------------------------------------------------------------------------------
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
# Without this option, we don't get the tag information
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Initialise the build system
19+
run: |
20+
chmod u+x $GITHUB_WORKSPACE/build/bin/*.sh
21+
$GITHUB_WORKSPACE/build/bin/initbuild.sh
22+
source $GITHUB_WORKSPACE/build/bin/.functions.sh
23+
24+
# 2. Python Package Build
25+
# -------------------------------------------------------------------------------------------
26+
- name: Set up Python 3.11
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: 3.11
30+
31+
- name: Build the Python package
32+
run: |
33+
sed -i "s#__version__ = \"100.0.0\"#__version__ = \"${{ env.VERSION_NOPREREL }}\"#g" ${GITHUB_WORKSPACE}/src/wiotp/sdk/__init__.py
34+
cat ${GITHUB_WORKSPACE}/src/wiotp/sdk/__init__.py
35+
python -m pip install --upgrade pip
36+
pip install .[dev]
37+
python -m pytest
38+
env:
39+
ONE_JOB_ONLY_TESTS: "true"
40+
WIOTP_API_KEY: ${{ secrets.WIOTP_API_KEY }}
41+
WIOTP_API_TOKEN: ${{ secrets.WIOTP_API_TOKEN }}
42+
WIOTP_ORG_ID: ${{ secrets.WIOTP_ORG_ID }}
43+
CLOUDANT_HOST: ${{ secrets.CLOUDANT_HOST }}
44+
CLOUDANT_PORT: ${{ secrets.CLOUDANT_PORT }}
45+
CLOUDANT_USERNAME: ${{ secrets.CLOUDANT_USERNAME }}
46+
CLOUDANT_PASSWORD: ${{ secrets.CLOUDANT_PASSWORD }}
47+
EVENTSTREAMS_API_KEY: ${{ secrets.EVENTSTREAMS_API_KEY }}
48+
EVENTSTREAMS_ADMIN_URL: ${{ secrets.EVENTSTREAMS_ADMIN_URL }}
49+
EVENTSTREAMS_BROKER1: ${{ secrets.EVENTSTREAMS_BROKER1 }}
50+
EVENTSTREAMS_BROKER2: ${{ secrets.EVENTSTREAMS_BROKER2 }}
51+
EVENTSTREAMS_BROKER3: ${{ secrets.EVENTSTREAMS_BROKER3 }}
52+
EVENTSTREAMS_BROKER4: ${{ secrets.EVENTSTREAMS_BROKER4 }}
53+
EVENTSTREAMS_BROKER5: ${{ secrets.EVENTSTREAMS_BROKER5 }}
54+
EVENTSTREAMS_BROKER6: ${{ secrets.EVENTSTREAMS_BROKER6 }}
55+
EVENTSTREAMS_USER: ${{ secrets.EVENTSTREAMS_USER }}
56+
EVENTSTREAMS_PASSWORD: ${{ secrets.EVENTSTREAMS_PASSWORD }}
57+
58+
- name: Lint with flake8
59+
run: |
60+
# stop the build if there are Python syntax errors or undefined names
61+
flake8 src --count --select=E9,F63,F7,F82 --show-source --statistics
62+
# exit-zero treats all errors as warnings.
63+
flake8 src --count --exit-zero --max-complexity=10 --max-line-length=200 --statistics

.github/workflows/python-publish.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Build Python Package
2+
on:
3+
release:
4+
types: [ published ]
5+
jobs:
6+
release-package:
7+
runs-on: ubuntu-latest
8+
steps:
9+
# 1. Initialize the build
10+
# -------------------------------------------------------------------------------------------
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
# Without this option, we don't get the tag information
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Initialise the build system
18+
run: |
19+
chmod u+x $GITHUB_WORKSPACE/build/bin/*.sh
20+
$GITHUB_WORKSPACE/build/bin/initbuild.sh
21+
source $GITHUB_WORKSPACE/build/bin/.functions.sh
22+
23+
# 2. Python Package Build
24+
# -------------------------------------------------------------------------------------------
25+
- name: Set up Python 3.11
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: 3.11
29+
30+
- name: Build the Python package
31+
run: |
32+
sed -i "s#__version__ = \"100.0.0\"#__version__ = \"${{ env.VERSION_NOPREREL }}\"#g" ${GITHUB_WORKSPACE}/src/wiotp/sdk/__init__.py
33+
cat ${GITHUB_WORKSPACE}/src/wiotp/sdk/__init__.py
34+
python -m pip install --upgrade pip
35+
pip install .[dev]
36+
python -m pytest
37+
env:
38+
ONE_JOB_ONLY_TESTS: "true"
39+
WIOTP_API_KEY: ${{ secrets.WIOTP_API_KEY }}
40+
WIOTP_API_TOKEN: ${{ secrets.WIOTP_API_TOKEN }}
41+
WIOTP_ORG_ID: ${{ secrets.WIOTP_ORG_ID }}
42+
CLOUDANT_HOST: ${{ secrets.CLOUDANT_HOST }}
43+
CLOUDANT_PORT: ${{ secrets.CLOUDANT_PORT }}
44+
CLOUDANT_USERNAME: ${{ secrets.CLOUDANT_USERNAME }}
45+
CLOUDANT_PASSWORD: ${{ secrets.CLOUDANT_PASSWORD }}
46+
EVENTSTREAMS_API_KEY: ${{ secrets.EVENTSTREAMS_API_KEY }}
47+
EVENTSTREAMS_ADMIN_URL: ${{ secrets.EVENTSTREAMS_ADMIN_URL }}
48+
EVENTSTREAMS_BROKER1: ${{ secrets.EVENTSTREAMS_BROKER1 }}
49+
EVENTSTREAMS_BROKER2: ${{ secrets.EVENTSTREAMS_BROKER2 }}
50+
EVENTSTREAMS_BROKER3: ${{ secrets.EVENTSTREAMS_BROKER3 }}
51+
EVENTSTREAMS_BROKER4: ${{ secrets.EVENTSTREAMS_BROKER4 }}
52+
EVENTSTREAMS_BROKER5: ${{ secrets.EVENTSTREAMS_BROKER5 }}
53+
EVENTSTREAMS_BROKER6: ${{ secrets.EVENTSTREAMS_BROKER6 }}
54+
EVENTSTREAMS_USER: ${{ secrets.EVENTSTREAMS_USER }}
55+
EVENTSTREAMS_PASSWORD: ${{ secrets.EVENTSTREAMS_PASSWORD }}
56+
57+
# 3. Flake8 Linting
58+
# -------------------------------------------------------------------------------------------
59+
- name: Lint with flake8
60+
run: |
61+
# stop the build if there are Python syntax errors or undefined names
62+
flake8 src --count --select=E9,F63,F7,F82 --show-source --statistics
63+
# exit-zero treats all errors as warnings.
64+
flake8 src --count --exit-zero --max-complexity=10 --max-line-length=200 --statistics
65+
66+
# 4. Publish to PyPi
67+
# -------------------------------------------------------------------------------------------
68+
- name: Build package
69+
run: python -m build
70+
71+
- name: Publish package
72+
uses: pypa/gh-action-pypi-publish@release/v1
73+
with:
74+
user: __token__
75+
password: ${{ secrets.PYPI_API_TOKEN }}

setup.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,24 @@
2525
with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
2626
long_description = f.read()
2727

28+
# Maintain a single source of versioning
29+
# https://packaging.python.org/en/latest/guides/single-sourcing-package-version/
30+
def read(rel_path):
31+
here = os.path.abspath(os.path.dirname(__file__))
32+
with codecs.open(os.path.join(here, rel_path), 'r') as fp:
33+
return fp.read()
34+
35+
def get_version(rel_path):
36+
for line in read(rel_path).splitlines():
37+
if line.startswith('__version__'):
38+
delim = '"' if '"' in line else "'"
39+
return line.split(delim)[1]
40+
else:
41+
raise RuntimeError("Unable to find version string.")
42+
2843
setup(
2944
name='wiotp-sdk',
30-
version="1.0.0",
45+
version=get_version("src/wiotp/sdk/__init__.py"),
3146
author='David Parker',
3247
author_email='[email protected]',
3348
package_dir={'': 'src'},

src/wiotp/sdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99
# *****************************************************************************
1010

11-
__version__ = "0.11.0"
11+
__version__ = "100.0.0"
1212

1313
# Expose the public API for the entire SDK
1414
#

0 commit comments

Comments
 (0)