Update workflows to also validate version number consistency

This commit is contained in:
Dominik Moritz Roth 2024-02-10 10:13:37 +01:00
parent 259b13baa1
commit 3c7fdc8d5b
3 changed files with 58 additions and 36 deletions

View File

@ -1,26 +0,0 @@
name: Ensure Tagged Commits on Release
on:
pull_request:
branches:
- release
jobs:
check_tag:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if base commit of PR is tagged
run: |
BASE_COMMIT=$(jq -r .pull_request.base.sha < "$GITHUB_EVENT_PATH")
TAG=$(git tag --contains $BASE_COMMIT)
if [ -z "$TAG" ]; then
echo "Base commit of PR is not tagged. PRs onto release must be tagged with the version number."
exit 1
fi
echo "Base commit of PR is tagged. Check passed."

View File

@ -0,0 +1,46 @@
name: Ensure Version Consistency on PR to Release
on:
pull_request:
branches:
- release
jobs:
check_version_and_tag:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Necessary to fetch all tags for comparison
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Extract version from pyproject.toml
run: |
echo "Extracting version from pyproject.toml"
VERSION=$(python -c 'import toml; print(toml.load("pyproject.toml")["project"]["version"])')
echo "Version in pyproject.toml is $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Get tag for the PR's head commit
run: |
PR_HEAD_SHA=$(jq -r .pull_request.head.sha < "$GITHUB_EVENT_PATH")
TAG=$(git tag --contains $PR_HEAD_SHA)
echo "Tag on PR's head commit is $TAG"
echo "TAG=$TAG" >> $GITHUB_ENV
- name: Compare version and tag
run: |
if [ -z "$TAG" ]; then
echo "Head commit of PR is not tagged. Ensure the head commit of PRs onto release is tagged with the version number."
exit 1
elif [ "$VERSION" != "$TAG" ]; then
echo "Version in pyproject.toml ($VERSION) does not match the git tag ($TAG)."
exit 1
else
echo "Version and git tag match. Check passed."

View File

@ -15,19 +15,24 @@ jobs:
with:
fetch-depth: 0 # This fetches all history for all branches and tags
- name: Check if commit is tagged
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Validate version against tag
run: |
VERSION=$(python -c 'import toml; print(toml.load("pyproject.toml")["project"]["version"])')
TAG=$(git tag --contains HEAD)
if [ -z "$TAG" ]; then
echo "Commit is not tagged. Failing the workflow."
exit 1
fi
echo "Commit is tagged. Proceeding with the workflow."
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
if [ "$VERSION" != "$TAG" ]; then
echo "Version in pyproject.toml ($VERSION) does not match the git tag ($TAG). Failing the workflow."
exit 1
fi
echo "Version and commit tag match. Proceeding with the workflow."
- name: Install pypa/build/setuptools/twine
run: >-
@ -36,9 +41,6 @@ jobs:
build setuptools twine
--user
- name: Prevent fallback onto setup.py
run: rm setup.py
- name: Build a binary wheel and a source tarball
run: python3 -m build