--- name: Release - Create CLI GitHub Release 'on': push: tags: - 'v*.*.*' # Trigger on version tags like v1.0.0, v2.1.3, etc. permissions: contents: write jobs: release: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v6 with: fetch-depth: 0 - name: Extract version from tag id: version run: | # Remove 'v' prefix if present (e.g., v1.0.0 -> 1.0.0) VERSION="${GITHUB_REF#refs/tags/}" VERSION="${VERSION#v}" echo "version=$VERSION" >> $GITHUB_OUTPUT echo "tag=$GITHUB_REF_NAME" >> $GITHUB_OUTPUT echo "Extracted version: $VERSION from tag $GITHUB_REF_NAME" - name: Validate version consistency run: | TAG_VERSION="${{ steps.version.outputs.version }}" # Extract version from pyproject.toml PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') # Extract version from cli/__init__.py CLI_VERSION=$(grep '^__version__ = ' cli/__init__.py | sed 's/__version__ = "\(.*\)"/\1/') echo "Tag version: $TAG_VERSION" echo "pyproject.toml: $PYPROJECT_VERSION" echo "cli/__init__.py: $CLI_VERSION" echo "" # Check if all versions match if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]; then echo "Error: Tag version ($TAG_VERSION) does not match pyproject.toml version ($PYPROJECT_VERSION)" echo "Please update pyproject.toml to version $TAG_VERSION before creating the release." exit 1 fi if [ "$TAG_VERSION" != "$CLI_VERSION" ]; then echo "Error: Tag version ($TAG_VERSION) does not match cli/__init__.py version ($CLI_VERSION)" echo "Please update cli/__init__.py to version $TAG_VERSION before creating the release." exit 1 fi echo "Version consistency check passed" echo "All version strings match: $TAG_VERSION" - name: Set up Python uses: actions/setup-python@v6 with: python-version: '3.14' - name: Install build dependencies run: | python -m pip install --upgrade pip pip install build twine - name: Build package run: python -m build - name: Check distribution run: | echo "Built packages:" ls -lh dist/ echo "" echo "Checking package integrity:" twine check dist/* # PyPI publishing disabled for now - install via GitHub releases # - name: Publish to PyPI # if: > # ${{ !contains(steps.version.outputs.version, 'alpha') && # !contains(steps.version.outputs.version, 'beta') && # !contains(steps.version.outputs.version, 'rc') }} # env: # TWINE_USERNAME: __token__ # TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} # run: | # echo "Publishing to PyPI..." # twine upload dist/* - name: Extract changelog for this version id: changelog run: | # Extract the changelog for this version from CHANGELOG.md VERSION="${{ steps.version.outputs.version }}" # First try to extract the section for this specific version CHANGELOG=$(awk -v ver="$VERSION" '/^## \[/{if($0 ~ "\\[" ver "\\]"){flag=1; next} else if(flag){exit}} flag' CHANGELOG.md) # If empty, fall back to [Unreleased] section if [ -z "$CHANGELOG" ]; then CHANGELOG=$(awk '/^## \[Unreleased\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md) fi if [ -z "$CHANGELOG" ]; then echo "No changelog entries found for this release" CHANGELOG="See commit history for details." fi # Save to output using heredoc to handle multiline { echo 'content<> $GITHUB_OUTPUT - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: tag_name: ${{ steps.version.outputs.tag }} name: Release ${{ steps.version.outputs.tag }} body: | ## Boilerplates CLI ${{ steps.version.outputs.tag }} ${{ steps.changelog.outputs.content }} --- ### Installation Install using the installation script: ```bash curl -fsSL https://raw.githubusercontent.com/christianlempa/boilerplates/main/scripts/install.sh | bash ``` Or install a specific version: ```bash curl -fsSL https://raw.githubusercontent.com/christianlempa/boilerplates/main/scripts/install.sh | bash -s -- --version ${{ steps.version.outputs.tag }} ``` draft: false prerelease: > ${{ contains(steps.version.outputs.version, 'alpha') || contains(steps.version.outputs.version, 'beta') || contains(steps.version.outputs.version, 'rc') }} files: | dist/*.whl dist/*.tar.gz env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}