diff --git a/.github/workflows/ensure-release-tagged.yaml b/.github/workflows/ensure-release-tagged.yaml deleted file mode 100644 index e58e31e..0000000 --- a/.github/workflows/ensure-release-tagged.yaml +++ /dev/null @@ -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." - diff --git a/.github/workflows/ensure-version-consistency.yaml b/.github/workflows/ensure-version-consistency.yaml new file mode 100644 index 0000000..1b02e6b --- /dev/null +++ b/.github/workflows/ensure-version-consistency.yaml @@ -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." + diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 1b5fa08..dc25bbc 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -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