Skip to content

Commit

Permalink
Version number action (#340)
Browse files Browse the repository at this point in the history
Create a workflow that
- validates a proposed version number tag
- creates a new tagged commit with updated version.py and CITATION.cff files
- pushes to the target branch

This is intended to solve the problem of synchronising version number updates (and of forgetting to update the CITATION.cff date...)

It will likely be rolled into a more integrated release pipeline in future. CHANGELOG updates are still manual for now.
  • Loading branch information
ajjackson authored Dec 12, 2024
1 parent f261a9d commit 93bde7b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 15 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/build_upload_pypi_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ jobs:
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout project (for test files)
- name: Checkout project
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
Expand Down Expand Up @@ -106,7 +109,9 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensure tags are fetched for versioning
fetch-depth: 0
fetch-tags: true


- name: Create source distribution
shell: bash -l {0}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensure tags are fetched for versioning
fetch-tags: true
- uses: actions/setup-python@v5
with:
python-version: |
Expand Down
66 changes: 56 additions & 10 deletions .github/workflows/set_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
ref:
description: "Target branch, tag or SHA"
description: "Target branch"
required: true
type: string
version:
Expand All @@ -13,28 +13,74 @@ on:
type: string

jobs:
show-branch:
set-version:
runs-on: ubuntu-latest

steps:
- name: Show input parameters
shell: bash -l {0}
run: |
echo "${{ inputs.ref }}"
echo "${{ inputs.version }}"
- name: Validate and normalise version number
shell: python
run : |
import os
from packaging.version import Version
version_string = 'v' + str(Version("${{ inputs.version }}"))
print(f"Normalised version string: {version_string}")
with open(os.environ["GITHUB_ENV"], "a") as github_env:
print(f"VERSION_STRING={version_string}", file=github_env)
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
fetch-tags: true
fetch-depth: 0

- name: "Tag locally"
- name: "Update version.py"
shell: bash -l {0}
run: |
git tag ${{ inputs.version }}
echo "__version__ = \"${VERSION_STRING}\"" > euphonic/version.py
cat euphonic/version.py
- name: "Update CITATION.cff"
shell: bash -l {0}
run: |
sed -i "s/^version:\ .*/version: ${VERSION_STRING}/" CITATION.cff
sed -i "s/^date-released:\ .*/date-released: $(date -I)/" CITATION.cff
- name: "Create commit"
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add euphonic/version.py CITATION.cff
if git diff --cached --quiet
then
echo "No files were changed, skipping commit"
else
git commit -m "Set version number"
fi
- name: "Tag commit"
shell: bash -l {0}
run: |
if test $(git describe --tags --exact-match) = $VERSION_STRING
then
echo "The correct tag is already on this commit"
else
git tag $VERSION_STRING
fi
- name: "Show updated log"
run: |
git log --pretty=oneline --abbrev-commit --decorate | head -n 5
git diff HEAD^
- name: "Push commit to branch"
shell: bash -l {0}
run: |
git log --pretty=oneline --abbrev-commit --decorate | head
# Verify that ref is a branch (as opposed to a tag or hash)
git show-ref --verify "refs/heads/${{ inputs.ref }}"
git push origin ${{ inputs.ref }}
git push origin tag $VERSION_STRING
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ authors:
given-names: "Jacob S."
title: "Euphonic"
doi: 10.5286/SOFTWARE/EUPHONIC
version: 1.4.0
date-released: 2024-01-30
version: v1.4.0.post1
date-released: 2024-12-12
license: GPL-3.0-only
repository-code: https://github.com/pace-neutrons/Euphonic
url: https://euphonic.readthedocs.io
Expand Down
2 changes: 1 addition & 1 deletion euphonic/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "v1.4.0"
__version__ = "v1.4.0.post1"

0 comments on commit 93bde7b

Please sign in to comment.