Skip to content

Commit ea829a5

Browse files
committed
Add logic to auto update release version in package after a release is cut
1 parent 61205f8 commit ea829a5

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

.github/workflows/release.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,62 @@ jobs:
5151
password: ${{ secrets.PYPI_PUBLIC_AUTH }}
5252
whl: $(find dist -name '*.tar.gz')
5353

54+
update-main-version:
55+
needs: build-and-publish
56+
permissions:
57+
contents: write
58+
runs-on: ubuntu-latest
59+
steps:
60+
- name: Checkout code
61+
uses: actions/checkout@v4
62+
with:
63+
fetch-depth: 0
64+
ref: main
65+
- name: Set up Python
66+
uses: actions/setup-python@v5
67+
with:
68+
python-version: "3.9"
69+
- name: Install dependencies
70+
run: pip install packaging
71+
- name: Set Tag Version
72+
id: set-tag-version
73+
run: echo "tag_version=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
74+
- name: Set setup.py version
75+
id: set-setup-version
76+
run: echo "setup_version=$(grep -oP 'LAST_RELEASE_VERSION = Version\("\K[^"]+' setup.py)" >> $GITHUB_OUTPUT
77+
- name: Check if version needs to be updated
78+
id: check-version
79+
run: |
80+
TAG_VERSION=${{ steps.set-tag-version.outputs.tag_version }}
81+
SETUP_VERSION=${{ steps.set-setup-version.outputs.setup_version }}
82+
if [ "$(python -c "from packaging.version import Version; print(Version('$TAG_VERSION') > Version('$SETUP_VERSION'))")" = "True" ]; then
83+
echo "Version needs to be updated."
84+
echo "update_needed=true" >> $GITHUB_OUTPUT
85+
else
86+
echo "No update needed."
87+
echo "update_needed=false" >> $GITHUB_OUTPUT
88+
fi
89+
- name: Generate GitHub App token
90+
id: app-token
91+
if: steps.check-version.outputs.update_needed == 'true'
92+
uses: actions/create-github-app-token@v1
93+
with:
94+
app-id: ${{ secrets.GH_NM_REDHAT_AUTOMATION_APP_ID }}
95+
private-key: ${{ secrets.GH_NM_REDHAT_AUTOMATION_APP_PRIVATE_KEY }}
96+
- name: Update LAST_RELEASE_VERSION in setup.py
97+
if: steps.check-version.outputs.update_needed == 'true'
98+
env:
99+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
100+
run:
101+
TAG_VERSION=${{ steps.set-tag-version.outputs.tag_version }}
102+
SETUP_VERSION=${{ steps.set-setup-version.outputs.setup_version }}
103+
sed -i "s/LAST_RELEASE_VERSION = Version(\"[^\"]*\")/LAST_RELEASE_VERSION = Version(\"$TAG_VERSION\")/" setup.py
104+
git config user.name "github-actions[bot]"
105+
git config user.email "github-actions[bot]@users.noreply.github.com"
106+
git add setup.py
107+
git commit -m "Update LAST_RELEASE_VERSION from $SETUP_VERSION to $TAG_VERSION"
108+
git push origin main
109+
54110
unit-tests:
55111
runs-on: ubuntu-latest
56112
strategy:

0 commit comments

Comments
 (0)