Skip to content

Commit 2b28f63

Browse files
authored
Test Release (#8)
* Authenticate/Authorise on resources (#5) * Added PyJWT * Resource API now requires authentication/authorisation * Greeting makes use of the new read fixture * Skipping tests when no OIDC configuration is available * More appropriate permissions * Tests should be running an install the first time they execute * Additional check whether the test configuration file exists * Fixed pylint complaint ... by ignoring the unnecessary lambda that needs to be there * Fixed flake8 complaints * Switching to 'compatible' requirements * 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 * Finetuning build mech
1 parent 53d0c66 commit 2b28f63

File tree

6 files changed

+96
-69
lines changed

6 files changed

+96
-69
lines changed

.github/workflows/build.yml

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,84 @@
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
16+
# What we want is that a release is made whenever we merge into master. Here is an example:
17+
# if: ${{ github.event_name == 'pull_request' && github.event.pull_request.merged == true && github.base_ref == 'refs/heads/main' }}
18+
# But really, we can also just say that a push into master causes a release. Whether that must come from a PR
19+
# can be controlled via branch protection
220

321
on:
4-
push:
5-
branches: [ main, develop ]
6-
pull_request:
7-
branches: [ main ]
22+
push: {}
23+
pull_request: {}
24+
25+
#
26+
# Workflow
827

928
jobs:
10-
build:
1129

30+
build:
1231
runs-on: ubuntu-latest
13-
strategy:
14-
matrix:
15-
python-version: [3.9]
16-
1732
steps:
18-
- uses: actions/checkout@v2
19-
- name: Set up Python ${{ matrix.python-version }}
33+
34+
- name: Determine whether this is a release build
35+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
36+
env:
37+
IS_RELEASE: "true"
38+
run: echo "We will be performing a release upon success"
39+
40+
- name: Checkout out our code
41+
uses: actions/checkout@v2
42+
43+
- name: Set up Python ${{ env.PYTHON_VERSION }}
2044
uses: actions/setup-python@v2
2145
with:
22-
python-version: ${{ matrix.python-version }}
46+
python-version: ${{ env.PYTHON_VERSION }}
47+
2348
- name: Install dependencies
2449
run: |
2550
python -m pip install --upgrade pip
51+
pip install wheel
2652
pip install -r requirements.txt
2753
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
54+
55+
- name: Lint
3556
run: |
57+
flake8 --statistics
3658
pylint mrmat_python_api_flask
37-
- name: Install locally
59+
60+
- name: Test
3861
run: |
3962
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
63+
python -m pytest
64+
65+
- name: Upload test results
4466
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
4967
if: ${{ always() }}
68+
with:
69+
name: tests
70+
path: build/junit.xml
71+
5072
- name: Upload coverage
5173
uses: actions/upload-artifact@v2
5274
with:
5375
name: coverage
5476
path: build/coverage.xml
77+
78+
- name: Conditionally perform a release
79+
if: ${{ env.IS_RELEASE == 'true' }}
80+
uses: elgohr/Github-Release-Action@master
81+
env:
82+
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
83+
with:
84+
args: Creating release

.github/workflows/sast.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

.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

requirements.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Runtime requirements
22

3-
flask==1.1.2 # BSD 3-Clause
4-
Flask-SQLAlchemy==2.5.1 # BSD 3-Clause
5-
Flask-Migrate==2.7.0 # MIT
6-
Flask-Marshmallow==0.14.0 # MIT
7-
marshmallow-sqlalchemy==0.25.0 # MIT
3+
flask~=1.1.2 # BSD 3-Clause
4+
Flask-SQLAlchemy~=2.5.1 # BSD 3-Clause
5+
Flask-Migrate~=2.7.0 # MIT
6+
Flask-Marshmallow~=0.14.0 # MIT
7+
marshmallow-sqlalchemy~=0.25.0 # MIT
88

9-
psycopg2==2.9.1 # LGPL with exceptions
9+
psycopg2~=2.9.1 # LGPL with exceptions
1010

11-
Flask-OIDC==1.4.0 # MIT
12-
requests_oauthlib==1.3.0 # ISC
11+
Flask-OIDC~=1.4.0 # MIT
12+
requests_oauthlib~=1.3.0 # ISC
1313

14-
cli-ui==0.12 # BSD 3-Clause
15-
halo==0.0.31 # MIT
14+
cli-ui~=0.12 # BSD 3-Clause
15+
halo~=0.0.31 # MIT

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)