Skip to content

feat: add professional repository structure with auto-release workflow #1

feat: add professional repository structure with auto-release workflow

feat: add professional repository structure with auto-release workflow #1

Workflow file for this run

name: Create Release
on:
push:
branches:
- main
paths-ignore:
- '**.md'
- 'LICENSE'
- '.github/ISSUE_TEMPLATE/**'
- '.github/PULL_REQUEST_TEMPLATE.md'
permissions:
contents: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get latest tag
id: get_latest_tag
run: |
# Get the latest tag, or use v0.0.0 if no tags exist
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "Latest tag: $LATEST_TAG"
- name: Determine version bump
id: version_bump
run: |
# Get commit messages since last tag
if [ "${{ steps.get_latest_tag.outputs.latest_tag }}" = "v0.0.0" ]; then
COMMITS=$(git log --pretty=format:"%s" main)
else
COMMITS=$(git log ${{ steps.get_latest_tag.outputs.latest_tag }}..HEAD --pretty=format:"%s")
fi
echo "Commits since last tag:"
echo "$COMMITS"
# Determine bump type based on conventional commits
BUMP="patch"
if echo "$COMMITS" | grep -qiE "^(feat|feature)(\(.+\))?!:|^BREAKING CHANGE:|breaking:"; then
BUMP="major"
elif echo "$COMMITS" | grep -qiE "^(feat|feature)(\(.+\))?:"; then
BUMP="minor"
fi
echo "bump=$BUMP" >> $GITHUB_OUTPUT
echo "Version bump type: $BUMP"
- name: Calculate new version
id: new_version
run: |
LATEST_TAG="${{ steps.get_latest_tag.outputs.latest_tag }}"
BUMP="${{ steps.version_bump.outputs.bump }}"
# Remove 'v' prefix if present
VERSION=${LATEST_TAG#v}
# Split version into parts
IFS='.' read -r -a VERSION_PARTS <<< "$VERSION"
MAJOR="${VERSION_PARTS[0]:-0}"
MINOR="${VERSION_PARTS[1]:-0}"
PATCH="${VERSION_PARTS[2]:-0}"
# Bump version
if [ "$BUMP" = "major" ]; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif [ "$BUMP" = "minor" ]; then
MINOR=$((MINOR + 1))
PATCH=0
else
PATCH=$((PATCH + 1))
fi
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Generate changelog
id: changelog
run: |
LATEST_TAG="${{ steps.get_latest_tag.outputs.latest_tag }}"
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
echo "# Release $NEW_VERSION" > CHANGELOG.md
echo "" >> CHANGELOG.md
if [ "$LATEST_TAG" = "v0.0.0" ]; then
echo "## Initial Release" >> CHANGELOG.md
echo "" >> CHANGELOG.md
echo "First release of the GitHub Copilot Agent blueprint repository." >> CHANGELOG.md
else
# Get commits since last tag
git log $LATEST_TAG..HEAD --pretty=format:"%s" | while read -r line; do
# Categorize commits
if echo "$line" | grep -qiE "^(feat|feature)(\(.+\))?:"; then
echo "✨ $line" >> CHANGELOG.md
elif echo "$line" | grep -qiE "^fix(\(.+\))?:"; then
echo "🐛 $line" >> CHANGELOG.md
elif echo "$line" | grep -qiE "^docs(\(.+\))?:"; then
echo "📚 $line" >> CHANGELOG.md
elif echo "$line" | grep -qiE "^refactor(\(.+\))?:"; then
echo "♻️ $line" >> CHANGELOG.md
elif echo "$line" | grep -qiE "^test(\(.+\))?:"; then
echo "✅ $line" >> CHANGELOG.md
elif echo "$line" | grep -qiE "^chore(\(.+\))?:"; then
echo "🔧 $line" >> CHANGELOG.md
else
echo "• $line" >> CHANGELOG.md
fi
done
fi
# Read changelog into output
CHANGELOG=$(cat CHANGELOG.md)
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
cat CHANGELOG.md
- name: Check if release needed
id: check_release
run: |
LATEST_TAG="${{ steps.get_latest_tag.outputs.latest_tag }}"
# Count commits since last tag
if [ "$LATEST_TAG" = "v0.0.0" ]; then
COMMIT_COUNT=$(git rev-list --count HEAD)
else
COMMIT_COUNT=$(git rev-list --count $LATEST_TAG..HEAD)
fi
echo "Commits since last release: $COMMIT_COUNT"
if [ "$COMMIT_COUNT" -eq 0 ]; then
echo "needs_release=false" >> $GITHUB_OUTPUT
echo "No new commits, skipping release"
else
echo "needs_release=true" >> $GITHUB_OUTPUT
echo "New commits found, creating release"
fi
- name: Create Release
if: steps.check_release.outputs.needs_release == 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.new_version.outputs.new_version }}
release_name: Release ${{ steps.new_version.outputs.new_version }}
body: ${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: false
- name: Summary
if: steps.check_release.outputs.needs_release == 'true'
run: |
echo "## 🎉 Release Created!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version**: ${{ steps.new_version.outputs.new_version }}" >> $GITHUB_STEP_SUMMARY
echo "**Previous**: ${{ steps.get_latest_tag.outputs.latest_tag }}" >> $GITHUB_STEP_SUMMARY
echo "**Bump Type**: ${{ steps.version_bump.outputs.bump }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Changelog" >> $GITHUB_STEP_SUMMARY
cat CHANGELOG.md >> $GITHUB_STEP_SUMMARY
- name: No Release Summary
if: steps.check_release.outputs.needs_release == 'false'
run: |
echo "## ℹ️ No Release Needed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "No new commits since last release." >> $GITHUB_STEP_SUMMARY