Skip to content

fix: enhance badge generation process with improved error handling an… #21

fix: enhance badge generation process with improved error handling an…

fix: enhance badge generation process with improved error handling an… #21

Workflow file for this run

name: Release and Marketplace
# This workflow handles automatic semantic versioning, tagging, and GitHub Marketplace submission
# It runs when changes are pushed to main and creates releases based on changelog entries
on:
push:
branches: [ main ]
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 1.2.3 or major/minor/patch)'
required: true
default: 'patch'
jobs:
check-changelog:
name: Check Changelog
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
has_unreleased: ${{ steps.check.outputs.has_unreleased }}
release_notes: ${{ steps.extract.outputs.release_notes }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Check for unreleased changes
id: check
run: |
if grep -q "## \[Unreleased\]" CHANGELOG.md; then
# Check if there's actual content under Unreleased
if grep -A 20 "## \[Unreleased\]" CHANGELOG.md | grep -qE "^### (Added|Changed|Deprecated|Removed|Fixed|Security)"; then
echo "has_unreleased=true" >> $GITHUB_OUTPUT
echo "✓ Found unreleased changes in CHANGELOG.md"
else
echo "has_unreleased=false" >> $GITHUB_OUTPUT
echo "No unreleased changes found in CHANGELOG.md"
fi
else
echo "has_unreleased=false" >> $GITHUB_OUTPUT
echo "No Unreleased section found in CHANGELOG.md"
fi
- name: Extract release notes
id: extract
if: steps.check.outputs.has_unreleased == 'true'
run: |
# Extract content between [Unreleased] and the next version heading
NOTES=$(awk '/## \[Unreleased\]/,/^## \[/' CHANGELOG.md | sed '1d;$d' | sed '/^$/d')
# Save to output (handle multiline)
echo "release_notes<<EOF" >> $GITHUB_OUTPUT
echo "$NOTES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "Extracted release notes:"
echo "$NOTES"
determine-version:
name: Determine Next Version
runs-on: ubuntu-latest
permissions:
contents: read
needs: check-changelog
if: needs.check-changelog.outputs.has_unreleased == 'true' || github.event_name == 'workflow_dispatch'
outputs:
new_version: ${{ steps.version.outputs.new_version }}
previous_version: ${{ steps.version.outputs.previous_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Get latest tag
id: get-latest-tag
run: |
# Get the latest semantic version tag
LATEST_TAG=$(git tag -l 'v*.*.*' | sort -V | tail -n 1)
if [ -z "$LATEST_TAG" ]; then
echo "No previous version tags found, starting with v1.0.0"
echo "latest_tag=v0.0.0" >> $GITHUB_OUTPUT
else
echo "Latest tag: $LATEST_TAG"
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
fi
- name: Determine version bump
id: version
run: |
LATEST_TAG="${{ steps.get-latest-tag.outputs.latest_tag }}"
# Remove 'v' prefix for version manipulation
CURRENT_VERSION=${LATEST_TAG#v}
# Parse version parts
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR="${VERSION_PARTS[0]:-0}"
MINOR="${VERSION_PARTS[1]:-0}"
PATCH="${VERSION_PARTS[2]:-0}"
# Determine bump type
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
BUMP_TYPE="${{ github.event.inputs.version }}"
else
# Auto-detect from changelog or default to patch
BUMP_TYPE="patch"
# Check changelog for breaking changes or new features
if grep -A 20 "## \[Unreleased\]" CHANGELOG.md | grep -q "^### Changed" || \
grep -A 20 "## \[Unreleased\]" CHANGELOG.md | grep -q "BREAKING"; then
BUMP_TYPE="minor"
fi
fi
echo "Bump type: $BUMP_TYPE"
# Apply version bump
case "$BUMP_TYPE" in
major|MAJOR)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor|MINOR)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch|PATCH|*)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
echo "Previous version: $LATEST_TAG"
echo "New version: $NEW_VERSION"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "previous_version=$LATEST_TAG" >> $GITHUB_OUTPUT
create-release:
name: Create Release
runs-on: ubuntu-latest
needs:
- check-changelog
- determine-version
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Update CHANGELOG with version
run: |
NEW_VERSION="${{ needs.determine-version.outputs.new_version }}"
TODAY=$(date +%Y-%m-%d)
# Replace [Unreleased] with the new version
sed -i "s/## \[Unreleased\]/## [${NEW_VERSION#v}] - $TODAY\n\n## [Unreleased]/" CHANGELOG.md
echo "Updated CHANGELOG.md with version $NEW_VERSION"
- name: Commit changelog update
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add CHANGELOG.md
git commit -m "Update CHANGELOG for ${{ needs.determine-version.outputs.new_version }}"
git push
- name: Create and push tag
run: |
NEW_VERSION="${{ needs.determine-version.outputs.new_version }}"
git tag -a "$NEW_VERSION" -m "Release $NEW_VERSION"
git push origin "$NEW_VERSION"
echo "✓ Created and pushed tag $NEW_VERSION"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.determine-version.outputs.new_version }}
name: Release ${{ needs.determine-version.outputs.new_version }}
body: |
${{ needs.check-changelog.outputs.release_notes }}
---
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ needs.determine-version.outputs.previous_version }}...${{ needs.determine-version.outputs.new_version }}
draft: false
prerelease: false
- name: Update major version tag
run: |
NEW_VERSION="${{ needs.determine-version.outputs.new_version }}"
MAJOR_VERSION=$(echo "$NEW_VERSION" | cut -d. -f1)
# Force update the major version tag (e.g., v1)
git tag -fa "$MAJOR_VERSION" -m "Update $MAJOR_VERSION to $NEW_VERSION"
git push origin "$MAJOR_VERSION" --force
echo "✓ Updated major version tag $MAJOR_VERSION"
marketplace-submission:
name: Marketplace Submission Info
runs-on: ubuntu-latest
permissions:
contents: read
needs: create-release
steps:
- name: Marketplace submission info
run: |
echo "🎉 Release created successfully!"
echo ""
echo "📦 GitHub Marketplace Submission:"
echo "This action is configured for GitHub Marketplace in action.yml"
echo ""
echo "To publish to the marketplace:"
echo "1. Go to: https://github.com/${{ github.repository }}/releases"
echo "2. Edit the latest release"
echo "3. Check 'Publish this Action to the GitHub Marketplace'"
echo "4. Review and accept the terms"
echo "5. Click 'Update release'"
echo ""
echo "The action.yml already includes marketplace metadata:"
echo " - Name: Python Linting"
echo " - Description: Run linting using pylint, black, and mypy"
echo " - Author: Jason Miller"
echo " - Branding: check-square icon, green color"
workflow-summary:
name: Release Summary
runs-on: ubuntu-latest
permissions:
contents: read
needs:
- create-release
- marketplace-submission
steps:
- name: Summary
run: |
echo "✅ Release workflow completed successfully!"
echo ""
echo "Release details:"
echo " Version: ${{ needs.determine-version.outputs.new_version }}"
echo " Previous: ${{ needs.determine-version.outputs.previous_version }}"
echo ""
echo "Next steps:"
echo " - Verify release at: https://github.com/${{ github.repository }}/releases"
echo " - Publish to GitHub Marketplace if desired"