|
51 | 51 | password: ${{ secrets.PYPI_PUBLIC_AUTH }} |
52 | 52 | whl: $(find dist -name '*.tar.gz') |
53 | 53 |
|
| 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 | + |
54 | 110 | unit-tests: |
55 | 111 | runs-on: ubuntu-latest |
56 | 112 | strategy: |
|
0 commit comments