release-create-cli-release.yaml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. ---
  2. name: Release - Create CLI GitHub Release
  3. 'on':
  4. push:
  5. tags:
  6. - 'v*.*.*' # Trigger on version tags like v1.0.0, v2.1.3, etc.
  7. permissions:
  8. contents: write
  9. jobs:
  10. release:
  11. runs-on: ubuntu-latest
  12. steps:
  13. - name: Checkout code
  14. uses: actions/checkout@v5
  15. with:
  16. fetch-depth: 0
  17. - name: Extract version from tag
  18. id: version
  19. run: |
  20. # Remove 'v' prefix if present (e.g., v1.0.0 -> 1.0.0)
  21. VERSION="${GITHUB_REF#refs/tags/}"
  22. VERSION="${VERSION#v}"
  23. echo "version=$VERSION" >> $GITHUB_OUTPUT
  24. echo "tag=$GITHUB_REF_NAME" >> $GITHUB_OUTPUT
  25. echo "Extracted version: $VERSION from tag $GITHUB_REF_NAME"
  26. - name: Update version in pyproject.toml
  27. run: |
  28. VERSION="${{ steps.version.outputs.version }}"
  29. sed -i "s/^version = .*/version = \"$VERSION\"/" pyproject.toml
  30. echo "✓ Updated pyproject.toml with version $VERSION"
  31. - name: Update version in cli/__main__.py
  32. run: |
  33. VERSION="${{ steps.version.outputs.version }}"
  34. sed -i "s/^__version__ = .*/__version__ = \"$VERSION\"/" cli/__main__.py
  35. echo "✓ Updated cli/__main__.py with version $VERSION"
  36. - name: Verify changes
  37. run: |
  38. echo "=== pyproject.toml ==="
  39. grep "^version" pyproject.toml
  40. echo ""
  41. echo "=== cli/__main__.py ==="
  42. grep "^__version__" cli/__main__.py
  43. - name: Commit and update tag
  44. run: |
  45. git config --local user.email "github-actions[bot]@users.noreply.github.com"
  46. git config --local user.name "github-actions[bot]"
  47. # Add changes
  48. git add pyproject.toml cli/__main__.py
  49. # Check if there are changes to commit
  50. if git diff --staged --quiet; then
  51. echo "No version changes needed"
  52. else
  53. # Commit the version updates
  54. git commit -m "chore: bump version to ${{ steps.version.outputs.version }}"
  55. # Delete the tag locally and remotely
  56. git tag -d ${{ steps.version.outputs.tag }}
  57. git push origin :refs/tags/${{ steps.version.outputs.tag }}
  58. # Recreate the tag pointing to the new commit
  59. git tag -a ${{ steps.version.outputs.tag }} -m "Release ${{ steps.version.outputs.tag }}"
  60. # Push the new tag
  61. git push origin ${{ steps.version.outputs.tag }}
  62. echo "✓ Tag ${{ steps.version.outputs.tag }} updated to point to version bump commit"
  63. fi
  64. - name: Set up Python
  65. uses: actions/setup-python@v6
  66. with:
  67. python-version: '3.14'
  68. - name: Install build dependencies
  69. run: |
  70. python -m pip install --upgrade pip
  71. pip install build twine
  72. - name: Build package
  73. run: python -m build
  74. - name: Check distribution
  75. run: |
  76. echo "Built packages:"
  77. ls -lh dist/
  78. echo ""
  79. echo "Checking package integrity:"
  80. twine check dist/*
  81. # PyPI publishing disabled for now - install via GitHub releases
  82. # - name: Publish to PyPI
  83. # if: >
  84. # ${{ !contains(steps.version.outputs.version, 'alpha') &&
  85. # !contains(steps.version.outputs.version, 'beta') &&
  86. # !contains(steps.version.outputs.version, 'rc') }}
  87. # env:
  88. # TWINE_USERNAME: __token__
  89. # TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
  90. # run: |
  91. # echo "Publishing to PyPI..."
  92. # twine upload dist/*
  93. - name: Extract changelog for this version
  94. id: changelog
  95. run: |
  96. # Extract the [Unreleased] section from CHANGELOG.md
  97. CHANGELOG=$(awk '/^## \[Unreleased\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md)
  98. if [ -z "$CHANGELOG" ]; then
  99. echo "No changelog entries found for this release"
  100. CHANGELOG="See commit history for details."
  101. fi
  102. # Save to output using heredoc to handle multiline
  103. {
  104. echo 'content<<EOF'
  105. echo "$CHANGELOG"
  106. echo EOF
  107. } >> $GITHUB_OUTPUT
  108. - name: Create GitHub Release
  109. uses: softprops/action-gh-release@v2
  110. with:
  111. tag_name: ${{ steps.version.outputs.tag }}
  112. name: Release ${{ steps.version.outputs.tag }}
  113. body: |
  114. ## Boilerplates CLI ${{ steps.version.outputs.tag }}
  115. ${{ steps.changelog.outputs.content }}
  116. ---
  117. ### Installation
  118. Install using the installation script:
  119. ```bash
  120. curl -fsSL https://raw.githubusercontent.com/christianlempa/boilerplates/main/scripts/install.sh | bash
  121. ```
  122. Or install a specific version:
  123. ```bash
  124. curl -fsSL https://raw.githubusercontent.com/christianlempa/boilerplates/main/scripts/install.sh |
  125. bash -s -- --version ${{ steps.version.outputs.tag }}
  126. ```
  127. draft: false
  128. prerelease: >
  129. ${{ contains(steps.version.outputs.version, 'alpha') ||
  130. contains(steps.version.outputs.version, 'beta') ||
  131. contains(steps.version.outputs.version, 'rc') }}
  132. files: |
  133. dist/*.whl
  134. dist/*.tar.gz
  135. env:
  136. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}