release-create-cli-release.yaml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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: Validate version consistency
  27. run: |
  28. TAG_VERSION="${{ steps.version.outputs.version }}"
  29. # Extract version from pyproject.toml
  30. PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
  31. # Extract version from cli/__init__.py
  32. CLI_VERSION=$(grep '^__version__ = ' cli/__init__.py | sed 's/__version__ = "\(.*\)"/\1/')
  33. echo "Tag version: $TAG_VERSION"
  34. echo "pyproject.toml: $PYPROJECT_VERSION"
  35. echo "cli/__init__.py: $CLI_VERSION"
  36. echo ""
  37. # Check if all versions match
  38. if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]; then
  39. echo "Error: Tag version ($TAG_VERSION) does not match pyproject.toml version ($PYPROJECT_VERSION)"
  40. echo "Please update pyproject.toml to version $TAG_VERSION before creating the release."
  41. exit 1
  42. fi
  43. if [ "$TAG_VERSION" != "$CLI_VERSION" ]; then
  44. echo "Error: Tag version ($TAG_VERSION) does not match cli/__init__.py version ($CLI_VERSION)"
  45. echo "Please update cli/__init__.py to version $TAG_VERSION before creating the release."
  46. exit 1
  47. fi
  48. echo "Version consistency check passed"
  49. echo "All version strings match: $TAG_VERSION"
  50. - name: Set up Python
  51. uses: actions/setup-python@v6
  52. with:
  53. python-version: '3.14'
  54. - name: Install build dependencies
  55. run: |
  56. python -m pip install --upgrade pip
  57. pip install build twine
  58. - name: Build package
  59. run: python -m build
  60. - name: Check distribution
  61. run: |
  62. echo "Built packages:"
  63. ls -lh dist/
  64. echo ""
  65. echo "Checking package integrity:"
  66. twine check dist/*
  67. # PyPI publishing disabled for now - install via GitHub releases
  68. # - name: Publish to PyPI
  69. # if: >
  70. # ${{ !contains(steps.version.outputs.version, 'alpha') &&
  71. # !contains(steps.version.outputs.version, 'beta') &&
  72. # !contains(steps.version.outputs.version, 'rc') }}
  73. # env:
  74. # TWINE_USERNAME: __token__
  75. # TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
  76. # run: |
  77. # echo "Publishing to PyPI..."
  78. # twine upload dist/*
  79. - name: Extract changelog for this version
  80. id: changelog
  81. run: |
  82. # Extract the changelog for this version from CHANGELOG.md
  83. VERSION="${{ steps.version.outputs.version }}"
  84. # First try to extract the section for this specific version
  85. CHANGELOG=$(awk -v ver="$VERSION" '/^## \[/{if($0 ~ "\\[" ver "\\]"){flag=1; next} else if(flag){exit}} flag' CHANGELOG.md)
  86. # If empty, fall back to [Unreleased] section
  87. if [ -z "$CHANGELOG" ]; then
  88. CHANGELOG=$(awk '/^## \[Unreleased\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md)
  89. fi
  90. if [ -z "$CHANGELOG" ]; then
  91. echo "No changelog entries found for this release"
  92. CHANGELOG="See commit history for details."
  93. fi
  94. # Save to output using heredoc to handle multiline
  95. {
  96. echo 'content<<EOF'
  97. echo "$CHANGELOG"
  98. echo EOF
  99. } >> $GITHUB_OUTPUT
  100. - name: Create GitHub Release
  101. uses: softprops/action-gh-release@v2
  102. with:
  103. tag_name: ${{ steps.version.outputs.tag }}
  104. name: Release ${{ steps.version.outputs.tag }}
  105. body: |
  106. ## Boilerplates CLI ${{ steps.version.outputs.tag }}
  107. ${{ steps.changelog.outputs.content }}
  108. ---
  109. ### Installation
  110. Install using the installation script:
  111. ```bash
  112. curl -fsSL https://raw.githubusercontent.com/christianlempa/boilerplates/main/scripts/install.sh | bash
  113. ```
  114. Or install a specific version:
  115. ```bash
  116. curl -fsSL https://raw.githubusercontent.com/christianlempa/boilerplates/main/scripts/install.sh |
  117. bash -s -- --version ${{ steps.version.outputs.tag }}
  118. ```
  119. draft: false
  120. prerelease: >
  121. ${{ contains(steps.version.outputs.version, 'alpha') ||
  122. contains(steps.version.outputs.version, 'beta') ||
  123. contains(steps.version.outputs.version, 'rc') }}
  124. files: |
  125. dist/*.whl
  126. dist/*.tar.gz
  127. env:
  128. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}