11#
2- # Main workflow to build
2+ # How to build this
33
44name : Build
55
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
1722on :
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,25 +69,27 @@ 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
6779 - name : Upload test results
6880 uses : actions/upload-artifact@v2
6981 if : ${{ always() }}
7082 with :
71- name : tests
72- path : build/junit.xml
73-
74- - name : Upload coverage
75- uses : actions/upload-artifact@v2
83+ name : Test and Coverage
84+ path : |
85+ build/junit.xml
86+ build/coverage.xml
87+
88+ - name : Conditional Release
89+ uses : marvinpinto/action-automatic-releases@latest
90+ if : github.event.pull_request.merged == true
7691 with :
77- name : coverage
78- path : build/coverage.xml
92+ repo_token : " ${{ secrets.GITHUB_TOKEN }}"
93+ automatic_release_tag : " ${{ env.MRMAT_VERSION }}"
94+ prerelease : false
95+ title : " Release ${{ env.MRMAT_VERSION }}"
0 commit comments