update-pyproject-version.yml 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. name: Update pyproject.toml Version and Tags
  2. on:
  3. release:
  4. types:
  5. - published
  6. jobs:
  7. update-pyproject-and-tags:
  8. runs-on: ubuntu-latest
  9. steps:
  10. - name: Checkout code
  11. uses: actions/checkout@v4
  12. with:
  13. fetch-depth: 0 # Fetch all history for all branches and tags
  14. - name: Set up Python
  15. uses: actions/setup-python@v5
  16. with:
  17. python-version: "3.11"
  18. - name: Install dependencies
  19. run: |
  20. python -m pip install --upgrade pip
  21. pip install toml
  22. - name: Get release tag
  23. id: get_release_tag
  24. run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
  25. - name: Update pyproject.toml with release tag
  26. run: |
  27. python -c "
  28. import toml
  29. with open('pyproject.toml', 'r') as f:
  30. data = toml.load(f)
  31. data['tool']['poetry']['version'] = '${{ env.RELEASE_TAG }}'
  32. with open('pyproject.toml', 'w') as f:
  33. toml.dump(data, f)
  34. "
  35. - name: Commit and push pyproject.toml changes
  36. uses: stefanzweifel/git-auto-commit-action@v4
  37. with:
  38. commit_message: "Update pyproject.toml version to ${{ env.RELEASE_TAG }}"
  39. branch: main
  40. file_pattern: pyproject.toml