1- name : Run tests and publish Python distribution to PyPI
1+ name : Publish version
22
3- on : [push, pull_request]
4-
5- env :
6- DATABASE_SCHEMA : 4.2.1 # released 2024-08-19
7- # Installs from GitHub
8- # Versions: https://github.com/DiamondLightSource/ispyb-database/tags
9- # Previous version(s):
10- # 4.1.0
3+ on :
4+ push :
5+ branches :
6+ - main
117
128permissions :
139 contents : read
1410
1511jobs :
16- static :
17- name : Static Analysis
12+ get-current-version :
13+ name : Get version
1814 runs-on : ubuntu-latest
15+ outputs :
16+ doTag : ${{ steps.checkTag.outputs.doTag }}
17+ newVersion : ${{ steps.checkTag.outputs.newVersion }}
1918 steps :
2019 - uses : actions/checkout@v4
21- - name : Set up Python 3.10
22- uses : actions/setup-python@v5
23- with :
24- python-version : " 3.10"
25- - name : Syntax validation
20+ - name : Check current tag
21+ id : checkTag
2622 run : |
27- python .github/workflows/scripts/syntax-validation.py
28- - name : Flake8 validation
23+ pip install --disable-pip-version-check -e "."[cicd,client,server,developer]
24+ VERSION=$(python -c "import murfey; print(murfey.__version__)")
25+ echo "newVersion=v$VERSION" >> $GITHUB_OUTPUT
26+
27+ if [ $(git tag -l v$VERSION) ]; then
28+ echo "Version is up to date at $VERSION"
29+ echo "doTag=false" >> $GITHUB_OUTPUT
30+ else
31+ echo "Version needs to be updated to $VERSION"
32+ echo "doTag=true" >> $GITHUB_OUTPUT
33+ fi
34+
35+ make-tag :
36+ name : Create a new tag
37+ runs-on : ubuntu-latest
38+ permissions :
39+ contents : write
40+ needs :
41+ - get-current-version
42+ if : ${{ needs.get-current-version.outputs.doTag == 'true' }}
43+ steps :
44+ - uses : actions/checkout@v4
45+ - name : Push the new tag
2946 run : |
30- pip install flake8
31- python .github/workflows/scripts/flake8-validation.py
47+ git config --global user.name "DiamondLightSource-build-server"
48+ git config --global user.email "[email protected] " 49+ git config credential.helper "store --file=.git/credentials"
50+ echo "https://${GITHUB_TOKEN}:@github.com" > .git/credentials
51+
52+ git tag ${{ needs.get-current-version.outputs.newVersion }}
53+ git push origin ${{ needs.get-current-version.outputs.newVersion }}
3254
3355 build :
3456 name : Build package
3557 runs-on : ubuntu-latest
58+ needs :
59+ - get-current-version
60+ if : ${{ needs.get-current-version.outputs.doTag == 'true' }}
3661 steps :
3762 - uses : actions/checkout@v4
3863 - name : Set up Python 3.10
@@ -47,36 +72,20 @@ jobs:
4772 --user
4873 - name : Build python package
4974 run : python3 -m build
50- - name : Download ISPyB DB schema v${{ env.DATABASE_SCHEMA }} for tests
51- run : |
52- mkdir database
53- wget -t 3 --waitretry=20 https://github.com/DiamondLightSource/ispyb-database/releases/download/v${{ env.DATABASE_SCHEMA }}/ispyb-database-${{ env.DATABASE_SCHEMA }}.tar.gz -O database/ispyb-database.tar.gz
5475 - name : Store built package artifact
5576 uses : actions/upload-artifact@v4
5677 with :
5778 name : package-distributions
5879 path : dist/
59- - name : Store database artifact
60- uses : actions/upload-artifact@v4
61- with :
62- name : database
63- path : database/
64-
65- tests :
66- name : Call ci unit tests workflow
67- uses : ./.github/workflows/ci.yml
68- needs :
69- - build
70- - static
71- secrets :
72- CODECOV_TOKEN : ${{ secrets.CODECOV_TOKEN }}
7380
7481 publish-to-pypi :
7582 name : >-
7683 Publish Python distribution to PyPI
77- if : startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
7884 needs :
79- - tests
85+ - get-current-version
86+ - build
87+ - make-tag
88+ if : ${{ needs.get-current-version.outputs.doTag == 'true' }}
8089 runs-on : ubuntu-latest
8190 environment :
8291 name : pypi
98107 Sign the Python distribution with Sigstore
99108 and upload them to GitHub Release
100109 needs :
110+ - get-current-version
101111 - publish-to-pypi
112+ if : ${{ needs.get-current-version.outputs.doTag == 'true' }}
102113 runs-on : ubuntu-latest
103114
104115 permissions :
@@ -122,7 +133,7 @@ jobs:
122133 GITHUB_TOKEN : ${{ github.token }}
123134 run : >-
124135 gh release create
125- '${{ github.ref_name }}'
136+ '${{ needs.get-current-version.outputs.newVersion }}'
126137 --repo '${{ github.repository }}'
127138 --notes ""
128139 - name : Upload artifact signatures to GitHub Release
@@ -133,5 +144,5 @@ jobs:
133144 # sigstore-produced signatures and certificates.
134145 run : >-
135146 gh release upload
136- '${{ github.ref_name }}' dist/**
147+ '${{ needs.get-current-version.outputs.newVersion }}' dist/**
137148 --repo '${{ github.repository }}'
0 commit comments