-
Notifications
You must be signed in to change notification settings - Fork 324
157 lines (133 loc) · 4.45 KB
/
Copy pathrelease-sourcebot.yml
File metadata and controls
157 lines (133 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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: Generate GitHub App token
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.RELEASE_APP_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
token: ${{ steps.generate_token.outputs.token }}
- 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
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
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