release.yaml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. ---
  2. name: 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.9'
  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: Create GitHub Release
  94. uses: softprops/action-gh-release@v2
  95. with:
  96. tag_name: ${{ steps.version.outputs.tag }}
  97. name: Release ${{ steps.version.outputs.tag }}
  98. body: |
  99. ## Boilerplates CLI ${{ steps.version.outputs.tag }}
  100. Install using the installation script:
  101. ```bash
  102. curl -fsSL https://raw.githubusercontent.com/christianlempa/boilerplates/main/scripts/install.sh | bash
  103. ```
  104. Or install a specific version:
  105. ```bash
  106. curl -fsSL https://raw.githubusercontent.com/christianlempa/boilerplates/main/scripts/install.sh |
  107. bash -s -- --version ${{ steps.version.outputs.tag }}
  108. ```
  109. draft: false
  110. prerelease: >
  111. ${{ contains(steps.version.outputs.version, 'alpha') ||
  112. contains(steps.version.outputs.version, 'beta') ||
  113. contains(steps.version.outputs.version, 'rc') }}
  114. files: |
  115. dist/*.whl
  116. dist/*.tar.gz
  117. env:
  118. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}