From ea829a573ae3709e6adc49a636626a8151947ee9 Mon Sep 17 00:00:00 2001 From: Mark Kurtz Date: Thu, 1 May 2025 14:17:49 +0000 Subject: [PATCH 1/2] Add logic to auto update release version in package after a release is cut --- .github/workflows/release.yml | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c3b6a639..41458274 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -51,6 +51,62 @@ jobs: password: ${{ secrets.PYPI_PUBLIC_AUTH }} whl: $(find dist -name '*.tar.gz') + update-main-version: + needs: build-and-publish + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: main + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.9" + - name: Install dependencies + run: pip install packaging + - name: Set Tag Version + id: set-tag-version + run: echo "tag_version=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT + - name: Set setup.py version + id: set-setup-version + run: echo "setup_version=$(grep -oP 'LAST_RELEASE_VERSION = Version\("\K[^"]+' setup.py)" >> $GITHUB_OUTPUT + - name: Check if version needs to be updated + id: check-version + run: | + TAG_VERSION=${{ steps.set-tag-version.outputs.tag_version }} + SETUP_VERSION=${{ steps.set-setup-version.outputs.setup_version }} + if [ "$(python -c "from packaging.version import Version; print(Version('$TAG_VERSION') > Version('$SETUP_VERSION'))")" = "True" ]; then + echo "Version needs to be updated." + echo "update_needed=true" >> $GITHUB_OUTPUT + else + echo "No update needed." + echo "update_needed=false" >> $GITHUB_OUTPUT + fi + - name: Generate GitHub App token + id: app-token + if: steps.check-version.outputs.update_needed == 'true' + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ secrets.GH_NM_REDHAT_AUTOMATION_APP_ID }} + private-key: ${{ secrets.GH_NM_REDHAT_AUTOMATION_APP_PRIVATE_KEY }} + - name: Update LAST_RELEASE_VERSION in setup.py + if: steps.check-version.outputs.update_needed == 'true' + env: + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} + run: + TAG_VERSION=${{ steps.set-tag-version.outputs.tag_version }} + SETUP_VERSION=${{ steps.set-setup-version.outputs.setup_version }} + sed -i "s/LAST_RELEASE_VERSION = Version(\"[^\"]*\")/LAST_RELEASE_VERSION = Version(\"$TAG_VERSION\")/" setup.py + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add setup.py + git commit -m "Update LAST_RELEASE_VERSION from $SETUP_VERSION to $TAG_VERSION" + git push origin main + unit-tests: runs-on: ubuntu-latest strategy: From d6ee32383a5cd893165d58cdc66b2ae20dcd3aae Mon Sep 17 00:00:00 2001 From: Mark Kurtz Date: Thu, 1 May 2025 14:19:05 +0000 Subject: [PATCH 2/2] update the last release version to catch main up --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 009cf362..8b7fc1ea 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ from setuptools import setup from setuptools_git_versioning import count_since, get_branch, get_sha, get_tags -LAST_RELEASE_VERSION = Version("0.0.0") +LAST_RELEASE_VERSION = Version("0.2.1") TAG_VERSION_PATTERN = re.compile(r"^v(\d+\.\d+\.\d+)$")