Skip to content

Check uniqueness of version number #107

Check uniqueness of version number

Check uniqueness of version number #107

Workflow file for this run

name: Versioning
run-name: "Check uniqueness of version number"
on: [ pull_request ]
jobs:
Version-Uniqueness-Check:
runs-on: ubuntu-latest
steps:
- name: 😎 Checkout
uses: actions/checkout@main
- name: 🐍 Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: πŸ‘©β€πŸŽ¨ Setup Poetry
run: pip install poetry
# The following steps will:
# - Fetch the current package version
# - Check if the version already exists in the repository and fail the workflow if it does
- name: πŸ¦‘ Fetch package version
run: |
echo "CURRENT_VERSION=v$(poetry version --short)" >> $GITHUB_ENV
echo "Version = v$(poetry version --short)"
# Should only run during a pull request event into the main branch.
# This will check if the version already exists in the registry.
- name: πŸ¦” Fail if release version exists
uses: actions/github-script@v7
if:
github.event_name == 'pull_request' &&
github.event.pull_request.base.ref == 'main'
with:
script: |
const tags = await github.rest.repos.listTags({
owner: context.repo.owner,
repo: context.repo.repo,
});
for (const tag of tags.data) {
if (tag.name === process.env.CURRENT_VERSION) {
const msg = `Version ${{ env.CURRENT_VERSION }} already exists as a release! Update the version number according to [SemVer](https://semver.org). For example: 'poetry version minor' or 'poetry version patch'.`
core.setFailed(msg);
}
}