Skip to content

Commit dab0cd3

Browse files
Create a new workflow to publish releases (#335)
1 parent e4a978a commit dab0cd3

File tree

4 files changed

+142
-47
lines changed

4 files changed

+142
-47
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Contains tasks to be repeated when testing for the different Python versions listed
2-
# in the "Run unit tests" stage in .github/workflows/test-and-publish.yml
2+
# in the "Run unit tests" stage in .github/workflows/test.yml
33
name: Run tests
44

55
on:
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,63 @@
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

128
permissions:
139
contents: read
1410

1511
jobs:
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
@@ -98,7 +107,9 @@ jobs:
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 }}'

.github/workflows/test.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Build and test
2+
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
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
static:
17+
name: Static Analysis
18+
runs-on: ubuntu-latest
19+
steps:
20+
- 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
26+
run: |
27+
python .github/workflows/scripts/syntax-validation.py
28+
- name: Flake8 validation
29+
run: |
30+
pip install flake8
31+
python .github/workflows/scripts/flake8-validation.py
32+
33+
build:
34+
name: Build package
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v4
38+
- name: Set up Python 3.10
39+
uses: actions/setup-python@v5
40+
with:
41+
python-version: "3.10"
42+
- name: Install pypa/build
43+
run: >-
44+
python3 -m
45+
pip install
46+
build
47+
--user
48+
- name: Build python package
49+
run: python3 -m build
50+
51+
get-database:
52+
name: Build package
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: actions/checkout@v4
56+
- name: Download ISPyB DB schema v${{ env.DATABASE_SCHEMA }} for tests
57+
run: |
58+
mkdir database
59+
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
60+
- name: Store database artifact
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: database
64+
path: database/
65+
66+
tests:
67+
name: Call ci unit tests workflow
68+
uses: ./.github/workflows/ci.yml
69+
needs:
70+
- build
71+
- get-database
72+
- static
73+
secrets:
74+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/version-bump.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,18 @@ jobs:
3838
git config --global user.email "[email protected]"
3939
git config credential.helper "store --file=.git/credentials"
4040
echo "https://${GITHUB_TOKEN}:@github.com" > .git/credentials
41+
4142
bump2version ${{ inputs.bumpLevel }}
42-
git push origin main
43-
pip install --disable-pip-version-check -e "."[cicd,client,server,developer]
44-
VERSION=$(python -c "import murfey; print(murfey.__version__)")
45-
git push origin v$VERSION
43+
44+
echo "##[section]Creating commit on branch 'version-bump'"
45+
git checkout -b version-bump
46+
bump2version ${{ inputs.bumpLevel }}
47+
48+
echo "##[section]Creating pull request"
49+
git push -f --set-upstream origin version-bump
50+
gh pr create -B main -H version-bump -t "Version update (${{ inputs.bumpLevel }})" -b "
51+
This is an automated pull request to update the version.
52+
53+
After merging this, the \`Publish version\` action will tag this release and publish to pypi.
54+
"
55+
echo

0 commit comments

Comments
 (0)