Skip to content

Commit 78efd9a

Browse files
authored
Reorganised the build/release workflow (#7)
* Enabling coverage measurement again * My YAML style * Version calculation * Pipeline debugging * Pipeline debugging * Pipeline debugging * Pipeline debugging * Pipeline debugging
1 parent 3dd3950 commit 78efd9a

File tree

5 files changed

+82
-32
lines changed

5 files changed

+82
-32
lines changed

.github/workflows/build.yml

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,79 @@
1-
name: Build
1+
#
2+
# Main workflow to build and release
3+
4+
name: Main
5+
6+
#
7+
# Operational Variables
8+
9+
env:
10+
MAJOR: 0
11+
MINOR: 0
12+
PYTHON_VERSION: 3.9.6
13+
14+
#
15+
# Establish when the workflow is run
216

317
on:
4-
push:
5-
branches: [ main, develop ]
6-
pull_request:
7-
branches: [ main ]
18+
push: {}
19+
pull_request: {}
20+
21+
#
22+
# Workflow
823

924
jobs:
10-
build:
1125

26+
build:
1227
runs-on: ubuntu-latest
13-
strategy:
14-
matrix:
15-
python-version: [3.9]
16-
1728
steps:
18-
- uses: actions/checkout@v2
19-
- name: Set up Python ${{ matrix.python-version }}
29+
30+
- name: Determine whether this is a release build
31+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.merged == true && github.base_ref == 'refs/heads/main' }}
32+
env:
33+
IS_RELEASE: "true"
34+
run: echo "We will be performing a release upon success"
35+
36+
- name: Checkout out our code
37+
uses: actions/checkout@v2
38+
39+
- name: Set up Python ${{ env.PYTHON_VERSION }}
2040
uses: actions/setup-python@v2
2141
with:
22-
python-version: ${{ matrix.python-version }}
42+
python-version: ${{ env.PYTHON_VERSION }}
43+
2344
- name: Install dependencies
2445
run: |
2546
python -m pip install --upgrade pip
2647
pip install -r requirements.txt
2748
pip install -r test-requirements.txt
28-
- name: Lint with flake8
29-
run: |
30-
# stop the build if there are Python syntax errors or undefined names
31-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
32-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
33-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
34-
- name: Lint with pylint
49+
50+
- name: Lint
3551
run: |
52+
flake8 --statistics
3653
pylint mrmat_python_api_flask
37-
- name: Install locally
54+
55+
- name: Test
3856
run: |
3957
python ./setup.py install
40-
- name: Test with pytest
41-
run: |
42-
python -m pytest --junitxml=build/test-results-${{ matrix.python-version }}.xml
43-
- name: Upload pytest test results
58+
python -m pytest
59+
60+
- name: Upload test results
4461
uses: actions/upload-artifact@v2
45-
with:
46-
name: pytest-results-${{ matrix.python-version }}
47-
path: build/test-results-${{ matrix.python-version }}.xml
48-
# Use always() to always run this step to publish test results when there are test failures
4962
if: ${{ always() }}
63+
with:
64+
name: tests
65+
path: build/junit.xml
66+
5067
- name: Upload coverage
5168
uses: actions/upload-artifact@v2
5269
with:
5370
name: coverage
5471
path: build/coverage.xml
72+
73+
- name: Conditionally perform a release
74+
if: ${{ env.IS_RELEASE == 'true' }}
75+
uses: elgohr/Github-Release-Action@master
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
78+
with:
79+
args: Creating release

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Boilerplate code for a Python Flask API
77

88
This variant of a Python Flask API is code-first and using native Flask
99

10-
Features:
10+
## Features
1111

1212
* Code-first
1313
* Pluggable APIs and multiple API versions
@@ -17,6 +17,15 @@ Features:
1717
* No TLS, because this is intended to run behind a reverse proxy
1818
* Healthz
1919

20+
## How to build this
21+
22+
Use the standard `python ./setup.py install` to build. There are two environment variables that influence the build
23+
24+
| Environment Variable | Default | Description |
25+
|----------------------|---------|-------------|
26+
| IS_RELEASE | <unset> | If unset, `.dev0` is appended to the version being built, otherwise an empty string |
27+
| GITHUB_RUN_NUMBER | 0 | Determines the micro version. If unset, the micro number is 0 |
28+
2029
## How to run this
2130

2231
You have the choice of running this

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[pytest]
66
testpaths = tests
7-
#addopts = --cov=mrmat_python_api_flask --cov-report=term --cov-report=xml:build/coverage.xml --junit-xml=build/junit.xml
7+
addopts = --cov=mrmat_python_api_flask --cov-report=term --cov-report=xml:build/coverage.xml --junit-xml=build/junit.xml
88
junit_family = xunit2
99
log_cli = 1
1010
log_cli_level = INFO

setup.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,22 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23+
import os
2324
from setuptools import setup, find_packages
2425

26+
#
27+
# Construct the version
28+
# If we are running in the context of a GitHub action then we use the GITHUB_RUN_NUMBER
29+
# otherwise we will default to 0 for the micro version.
30+
31+
major = 0
32+
minor = 0
33+
micro = os.environ['GITHUB_RUN_NUMBER'] if 'GITHUB_RUN_NUMBER' in os.environ else 0
34+
dev = '.dev0' if 'IS_RELEASE' not in os.environ else ''
35+
2536
setup(
2637
name='mrmat-python-api-flask',
27-
version='0.0.3',
38+
version=f'{major}.{minor}.{micro}{dev}',
2839
packages=find_packages(),
2940
license='MIT',
3041
author='MrMat',

0 commit comments

Comments
 (0)