|
| 1 | +name: Release Sourcebot |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + bump_type: |
| 7 | + description: "Type of version bump to apply" |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - patch |
| 12 | + - minor |
| 13 | + - major |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: release-sourcebot |
| 17 | + cancel-in-progress: false |
| 18 | + |
| 19 | +jobs: |
| 20 | + release: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + contents: write |
| 24 | + outputs: |
| 25 | + version: ${{ steps.calculate_version.outputs.version }} |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Generate GitHub App token |
| 29 | + id: generate_token |
| 30 | + uses: actions/create-github-app-token@v1 |
| 31 | + with: |
| 32 | + app-id: ${{ secrets.RELEASE_APP_ID }} |
| 33 | + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} |
| 34 | + |
| 35 | + - name: Checkout repository |
| 36 | + uses: actions/checkout@v4 |
| 37 | + with: |
| 38 | + ref: main |
| 39 | + fetch-depth: 0 |
| 40 | + token: ${{ steps.generate_token.outputs.token }} |
| 41 | + |
| 42 | + - name: Calculate new version |
| 43 | + id: calculate_version |
| 44 | + run: | |
| 45 | + # Extract current version from CHANGELOG.md |
| 46 | + CURRENT_VERSION=$(grep -oP '## \[\K[0-9]+\.[0-9]+\.[0-9]+' CHANGELOG.md | head -n 1) |
| 47 | + |
| 48 | + if [ -z "$CURRENT_VERSION" ]; then |
| 49 | + echo "Error: Could not extract current version from CHANGELOG.md" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + |
| 53 | + echo "Current version: $CURRENT_VERSION" |
| 54 | + |
| 55 | + # Parse version components |
| 56 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" |
| 57 | + |
| 58 | + # Apply bump based on input |
| 59 | + BUMP_TYPE="${{ inputs.bump_type }}" |
| 60 | + case "$BUMP_TYPE" in |
| 61 | + major) |
| 62 | + MAJOR=$((MAJOR + 1)) |
| 63 | + MINOR=0 |
| 64 | + PATCH=0 |
| 65 | + ;; |
| 66 | + minor) |
| 67 | + MINOR=$((MINOR + 1)) |
| 68 | + PATCH=0 |
| 69 | + ;; |
| 70 | + patch) |
| 71 | + PATCH=$((PATCH + 1)) |
| 72 | + ;; |
| 73 | + *) |
| 74 | + echo "Error: Invalid bump type: $BUMP_TYPE" |
| 75 | + exit 1 |
| 76 | + ;; |
| 77 | + esac |
| 78 | + |
| 79 | + NEW_VERSION="$MAJOR.$MINOR.$PATCH" |
| 80 | + echo "New version: $NEW_VERSION" |
| 81 | + |
| 82 | + # Export to GITHUB_ENV for use in subsequent steps within this job |
| 83 | + echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV |
| 84 | + |
| 85 | + # Export to GITHUB_OUTPUT for use in other jobs |
| 86 | + echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 87 | +
|
| 88 | + - name: Check if version already exists |
| 89 | + run: | |
| 90 | + if grep -q "## \[$VERSION\]" CHANGELOG.md; then |
| 91 | + echo "Error: Version $VERSION already exists in CHANGELOG.md" |
| 92 | + exit 1 |
| 93 | + fi |
| 94 | + if git tag | grep -q "^v$VERSION$"; then |
| 95 | + echo "Error: Tag v$VERSION already exists" |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | +
|
| 99 | + - name: Update CHANGELOG.md and version.ts |
| 100 | + run: | |
| 101 | + DATE=$(date +%Y-%m-%d) |
| 102 | +
|
| 103 | + # Insert the new version header after the [Unreleased] line |
| 104 | + sed -i "/## \[Unreleased\]/a\\ |
| 105 | + \\ |
| 106 | + ## [$VERSION] - $DATE" CHANGELOG.md |
| 107 | +
|
| 108 | + echo "Updated CHANGELOG.md with version $VERSION" |
| 109 | + cat CHANGELOG.md | head -n 15 |
| 110 | +
|
| 111 | + # Update version.ts |
| 112 | + cat > packages/shared/src/version.ts << EOF |
| 113 | + // This file is auto-generated by .github/workflows/release-sourcebot.yml |
| 114 | + export const SOURCEBOT_VERSION = "v$VERSION"; |
| 115 | + EOF |
| 116 | + echo "Updated version.ts with version v$VERSION" |
| 117 | + cat packages/shared/src/version.ts |
| 118 | +
|
| 119 | + - name: Configure git |
| 120 | + run: | |
| 121 | + git config user.name "github-actions[bot]" |
| 122 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 123 | +
|
| 124 | + - name: Commit changes |
| 125 | + run: | |
| 126 | + git add CHANGELOG.md packages/shared/src/version.ts |
| 127 | + git commit -m "Release v$VERSION" |
| 128 | +
|
| 129 | + - name: Create annotated tag |
| 130 | + run: | |
| 131 | + git tag -a "v$VERSION" -m "sourcebot v$VERSION" |
| 132 | +
|
| 133 | + - name: Push changes |
| 134 | + env: |
| 135 | + GH_TOKEN: ${{ steps.generate_token.outputs.token }} |
| 136 | + run: | |
| 137 | + git push origin main |
| 138 | + git push origin --tags |
| 139 | +
|
| 140 | + - name: Create GitHub release |
| 141 | + env: |
| 142 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 143 | + run: | |
| 144 | + gh release create "v$VERSION" \ |
| 145 | + --verify-tag \ |
| 146 | + --generate-notes \ |
| 147 | + --latest |
| 148 | +
|
| 149 | + publish: |
| 150 | + needs: release |
| 151 | + uses: ./.github/workflows/ghcr-publish.yml |
| 152 | + with: |
| 153 | + version: v${{ needs.release.outputs.version }} |
| 154 | + permissions: |
| 155 | + contents: read |
| 156 | + packages: write |
| 157 | + id-token: write |
0 commit comments