Check uniqueness of version number #107
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } | |
| } |