mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-24 10:15:23 +00:00
147 lines
4.1 KiB
YAML
147 lines
4.1 KiB
YAML
name: Release Sourcebot
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
bump_type:
|
|
description: "Type of version bump to apply"
|
|
required: true
|
|
type: choice
|
|
options:
|
|
- patch
|
|
- minor
|
|
- major
|
|
|
|
concurrency:
|
|
group: release-sourcebot
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
outputs:
|
|
version: ${{ steps.calculate_version.outputs.version }}
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: main
|
|
fetch-depth: 0
|
|
|
|
- name: Calculate new version
|
|
id: calculate_version
|
|
run: |
|
|
# Extract current version from CHANGELOG.md
|
|
CURRENT_VERSION=$(grep -oP '## \[\K[0-9]+\.[0-9]+\.[0-9]+' CHANGELOG.md | head -n 1)
|
|
|
|
if [ -z "$CURRENT_VERSION" ]; then
|
|
echo "Error: Could not extract current version from CHANGELOG.md"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Current version: $CURRENT_VERSION"
|
|
|
|
# Parse version components
|
|
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
|
|
|
|
# Apply bump based on input
|
|
BUMP_TYPE="${{ inputs.bump_type }}"
|
|
case "$BUMP_TYPE" in
|
|
major)
|
|
MAJOR=$((MAJOR + 1))
|
|
MINOR=0
|
|
PATCH=0
|
|
;;
|
|
minor)
|
|
MINOR=$((MINOR + 1))
|
|
PATCH=0
|
|
;;
|
|
patch)
|
|
PATCH=$((PATCH + 1))
|
|
;;
|
|
*)
|
|
echo "Error: Invalid bump type: $BUMP_TYPE"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
|
|
echo "New version: $NEW_VERSION"
|
|
|
|
# Export to GITHUB_ENV for use in subsequent steps within this job
|
|
echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV
|
|
|
|
# Export to GITHUB_OUTPUT for use in other jobs
|
|
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Check if version already exists
|
|
run: |
|
|
if grep -q "## \[$VERSION\]" CHANGELOG.md; then
|
|
echo "Error: Version $VERSION already exists in CHANGELOG.md"
|
|
exit 1
|
|
fi
|
|
if git tag | grep -q "^v$VERSION$"; then
|
|
echo "Error: Tag v$VERSION already exists"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Update CHANGELOG.md and version.ts
|
|
run: |
|
|
DATE=$(date +%Y-%m-%d)
|
|
|
|
# Insert the new version header after the [Unreleased] line
|
|
sed -i "/## \[Unreleased\]/a\\
|
|
\\
|
|
## [$VERSION] - $DATE" CHANGELOG.md
|
|
|
|
echo "Updated CHANGELOG.md with version $VERSION"
|
|
cat CHANGELOG.md | head -n 15
|
|
|
|
# Update version.ts
|
|
cat > packages/shared/src/version.ts << EOF
|
|
// This file is auto-generated by .github/workflows/release-sourcebot.yml
|
|
export const SOURCEBOT_VERSION = "v$VERSION";
|
|
EOF
|
|
echo "Updated version.ts with version v$VERSION"
|
|
cat packages/shared/src/version.ts
|
|
|
|
- name: Configure git
|
|
run: |
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
|
|
- name: Commit changes
|
|
run: |
|
|
git add CHANGELOG.md packages/shared/src/version.ts
|
|
git commit -m "Release v$VERSION"
|
|
|
|
- name: Create annotated tag
|
|
run: |
|
|
git tag -a "v$VERSION" -m "sourcebot v$VERSION"
|
|
|
|
- name: Push changes
|
|
run: |
|
|
git push origin main
|
|
git push origin --tags
|
|
|
|
- name: Create GitHub release
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
gh release create "v$VERSION" \
|
|
--verify-tag \
|
|
--generate-notes \
|
|
--latest
|
|
|
|
publish:
|
|
needs: release
|
|
uses: ./.github/workflows/ghcr-publish.yml
|
|
with:
|
|
version: v${{ needs.release.outputs.version }}
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
id-token: write
|