Skip to content

Commit 9c2e555

Browse files
committed
Adjusted with updated workflow
1 parent 4f59392 commit 9c2e555

File tree

4 files changed

+37
-75
lines changed

4 files changed

+37
-75
lines changed

.github/workflows/build.yml

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Main workflow to build
2+
# How to build this
33

44
name: Build
55

@@ -13,12 +13,18 @@ env:
1313

1414
#
1515
# Establish when the workflow is run
16+
# We do build on every push except when we push onto main (which we ought to be subject to branch protection)
17+
# We do build whenever a PR onto main is closed (see on) and the code is actually merged (see release job if)
18+
# Why is that okay?
19+
# Since we're making a PR, we know from the previous workflow run on push that the repo is okay and the PR
20+
# shows that to us. A PR itself doesn't cause a build, except when it is closed and the changes were merged.
1621

1722
on:
1823
push:
19-
branches-ignore:
20-
- main
21-
pull_request: {}
24+
branches-ignore: [main]
25+
pull_request_target:
26+
branches: [main]
27+
types: [closed]
2228

2329
#
2430
# Workflow
@@ -29,13 +35,22 @@ jobs:
2935
runs-on: ubuntu-latest
3036
steps:
3137

32-
- name: Pipeline Debugging
33-
run: |
34-
env
35-
3638
- name: Checkout out our code
3739
uses: actions/checkout@v2
3840

41+
- name: Calculate Build Context
42+
run: |
43+
MRMAT_VERSION="${MAJOR}.${MINOR}.${GITHUB_RUN_NUMBER}"
44+
if [ "$GITHUB_EVENT_NAME" == 'pull_request' ]; then
45+
MRMAT_IS_RELEASE=true
46+
echo "::warning ::Building release ${MRMAT_VERSION}"
47+
echo "MRMAT_IS_RELEASE=true" >> $GITHUB_ENV
48+
else
49+
MRMAT_VERSION="${MRMAT_VERSION}.dev0"
50+
echo "::warning ::Building version ${MRMAT_VERSION}"
51+
fi
52+
echo "MRMAT_VERSION=${MRMAT_VERSION}" >> $GITHUB_ENV
53+
3954
- name: Set up Python ${{ env.PYTHON_VERSION }}
4055
uses: actions/setup-python@v2
4156
with:
@@ -54,13 +69,10 @@ jobs:
5469
pip install --user -r requirements.txt
5570
pip install --user -r test-requirements.txt
5671
57-
- name: Lint
72+
- name: Test
5873
run: |
5974
flake8 --statistics
6075
pylint mrmat_python_api_flask
61-
62-
- name: Test
63-
run: |
6476
python ./setup.py install
6577
python -m pytest
6678
@@ -76,3 +88,12 @@ jobs:
7688
with:
7789
name: coverage
7890
path: build/coverage.xml
91+
92+
- name: Conditional Release
93+
uses: marvinpinto/action-automatic-releases@latest
94+
if: github.event.pull_request.merged == true
95+
with:
96+
repo_token: "${{ secrets.GITHUB_TOKEN }}"
97+
automatic_release_tag: "${{ env.MRMAT_VERSION }}"
98+
prerelease: false
99+
title: "Release ${{ env.MRMAT_VERSION }}"

.github/workflows/release.yml

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

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ This variant of a Python Flask API is code-first and using native Flask
1919

2020
## How to build this
2121

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 |
22+
Use the standard `python ./setup.py install` to build. By default, the version built will be `0.0.0.dev0`,
23+
unless the `MRMAT_VERSION` environment variable is set by the build orchestrator (e.g. GitHub Actions). The
24+
version and whether a release is built is consequently controlled exlusively by the build orchestrator.
2825

2926
## How to run this
3027

setup.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,9 @@
2323
import os
2424
from setuptools import setup, find_packages
2525

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 = os.environ['MAJOR'] if 'MAJOR' in os.environ else 0
32-
minor = os.environ['MINOR'] if 'MINOR' in os.environ else 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-
3626
setup(
3727
name='mrmat-python-api-flask',
38-
version=f'{major}.{minor}.{micro}{dev}',
28+
version=os.environ['MRMAT_VERSION'] if 'MRMAT_VERSION' in os.environ else '0.0.0.dev0',
3929
packages=find_packages(),
4030
license='MIT',
4131
author='MrMat',

0 commit comments

Comments
 (0)