-
Notifications
You must be signed in to change notification settings - Fork 448
235 lines (198 loc) · 8.71 KB
/
cli-release-staging.yml
File metadata and controls
235 lines (198 loc) · 8.71 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: CLI Release Staging
on:
pull_request:
branches: ['main']
push:
branches: ['**']
concurrency:
group: cli-staging-release
cancel-in-progress: false
permissions:
contents: write
jobs:
prepare-and-commit-staging:
runs-on: ubuntu-latest
if: |
(github.event_name == 'pull_request' && contains(github.event.pull_request.title, '[codecane]')) ||
(github.event_name == 'push' && contains(github.event.head_commit.message, '[codecane]'))
outputs:
new_version: ${{ steps.bump_version.outputs.new_version }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- uses: ./.github/actions/setup-project
- name: Calculate staging version
id: bump_version
env:
GITHUB_TOKEN: ${{ secrets.CODEBUFF_GITHUB_TOKEN }}
GITHUB_API_URL: https://api.github.com/repos/CodebuffAI/codebuff-community
run: |
cd cli/release-staging
BASE_VERSION=$(bun -e "console.log(require('./package.json').version)")
echo "Base version: $BASE_VERSION"
echo "Fetching latest CLI prerelease from GitHub..."
RELEASES_JSON=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" \
"${GITHUB_API_URL}/releases?per_page=100")
LATEST_TAG=$(echo "$RELEASES_JSON" | jq -r '.[] | select(.prerelease == true and (.name // "" | test("Codebuff CLI v"))) | .tag_name' | sort -V | tail -n 1)
if [ "$LATEST_TAG" = "null" ] || [ -z "$LATEST_TAG" ]; then
echo "No existing CLI prerelease found via releases, falling back to tags..."
LATEST_TAG=$(git ls-remote --tags origin "v${BASE_VERSION}-beta.*" | awk '{print $2}' | sed 's@refs/tags/@@' | sort -V | tail -n 1)
fi
if [ -n "$LATEST_TAG" ] && [[ "$LATEST_TAG" != v* ]]; then
LATEST_TAG="v${LATEST_TAG}"
fi
if [ -n "$LATEST_TAG" ]; then
echo "Latest CLI beta tag: $LATEST_TAG"
LATEST_VERSION=${LATEST_TAG#v}
LATEST_BASE=$(echo "$LATEST_VERSION" | sed 's/-beta\..*$//')
LATEST_BETA_NUM=$(echo "$LATEST_VERSION" | sed 's/.*-beta\.//')
if [ "$LATEST_BASE" = "$BASE_VERSION" ]; then
NEXT=$((LATEST_BETA_NUM + 1))
NEW_VERSION="${BASE_VERSION}-beta.${NEXT}"
else
echo "Base version changed since last prerelease, resetting counter"
NEW_VERSION="${BASE_VERSION}-beta.1"
fi
else
echo "No existing CLI beta tags found, starting with beta.1"
NEW_VERSION="${BASE_VERSION}-beta.1"
fi
echo "New staging version: $NEW_VERSION"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
bun -e "
const fs = require('fs');
const path = require('path');
const version = '$NEW_VERSION';
const stagingPath = path.join(process.cwd(), 'package.json');
const stagingPkg = JSON.parse(fs.readFileSync(stagingPath, 'utf8'));
stagingPkg.version = version;
fs.writeFileSync(stagingPath, JSON.stringify(stagingPkg, null, 2) + '\n');
const rootPkgPath = path.join(process.cwd(), '..', 'package.json');
const rootPkg = JSON.parse(fs.readFileSync(rootPkgPath, 'utf8'));
rootPkg.version = version;
fs.writeFileSync(rootPkgPath, JSON.stringify(rootPkg, null, 2) + '\n');
"
- name: Configure git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit staging release snapshot
run: |
git add -A
git commit -m "Staging CLI Release v${{ steps.bump_version.outputs.new_version }} [codecane]
Captures the staged state for the CLI prerelease, including the version bump.
🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>"
- name: Create and push staging tag
run: |
git tag "v${{ steps.bump_version.outputs.new_version }}"
git push origin "v${{ steps.bump_version.outputs.new_version }}"
- name: Upload staging metadata
uses: actions/upload-artifact@v4
with:
name: cli-staging-metadata
path: cli/release-staging/
build-staging-binaries:
needs: prepare-and-commit-staging
uses: ./.github/workflows/cli-release-build.yml
with:
binary-name: codecane
new-version: ${{ needs.prepare-and-commit-staging.outputs.new_version }}
artifact-name: cli-staging-metadata
checkout-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
env-overrides: '{"NEXT_PUBLIC_CB_ENVIRONMENT":"prod"}'
secrets: inherit
create-staging-release:
needs: [prepare-and-commit-staging, build-staging-binaries]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Clean up old CLI prereleases
env:
GITHUB_API_URL: https://api.github.com/repos/CodebuffAI/codebuff-community
run: |
ONE_WEEK_AGO=$(date -d '7 days ago' -u +%Y-%m-%dT%H:%M:%SZ)
echo "Removing CLI prereleases older than: $ONE_WEEK_AGO"
RELEASES=$(curl -s -H "Authorization: token ${{ secrets.CODEBUFF_GITHUB_TOKEN }}" \
"${GITHUB_API_URL}/releases?per_page=100")
if echo "$RELEASES" | jq -e 'type == "array"' >/dev/null 2>&1; then
OLD=$(echo "$RELEASES" | jq -r --arg cutoff "$ONE_WEEK_AGO" '.[] | select(.prerelease == true and .created_at < $cutoff and (.tag_name | test("^v[0-9].*-beta\\.[0-9]+$"))) | "\(.id):\(.tag_name)"')
if [ -n "$OLD" ]; then
echo "Deleting old prereleases:"
echo "$OLD"
echo "$OLD" | while IFS=: read -r RELEASE_ID TAG_NAME; do
curl -s -X DELETE \
-H "Authorization: token ${{ secrets.CODEBUFF_GITHUB_TOKEN }}" \
"${GITHUB_API_URL}/releases/$RELEASE_ID"
done
else
echo "No stale prereleases found."
fi
else
echo "Failed to parse releases response:"
echo "$RELEASES" | head -20
fi
- name: Download all binary artifacts
uses: actions/download-artifact@v4
with:
path: binaries/
- name: Download staging metadata
uses: actions/download-artifact@v4
with:
name: cli-staging-metadata
path: cli/release-staging/
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.prepare-and-commit-staging.outputs.new_version }}
name: Codecane v${{ needs.prepare-and-commit-staging.outputs.new_version }} (Staging)
prerelease: true
body: |
## Codecane v${{ needs.prepare-and-commit-staging.outputs.new_version }} (Staging)
**⚠️ This is a staging build intended for internal testing.**
### Included Binaries
- `codecane-linux-x64.tar.gz`
- `codecane-linux-arm64.tar.gz`
- `codecane-darwin-x64.tar.gz`
- `codecane-darwin-arm64.tar.gz`
- `codecane-win32-x64.tar.gz`
After downloading, extract the tarball, add the binary to your PATH, and run `codecane --help` for usage.
files: |
binaries/*/codecane-*
repository: CodebuffAI/codebuff-community
token: ${{ secrets.CODEBUFF_GITHUB_TOKEN }}
publish-staging-npm:
needs:
[
prepare-and-commit-staging,
build-staging-binaries,
create-staging-release,
]
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Download CLI staging package
uses: actions/download-artifact@v4
with:
name: cli-staging-metadata
path: cli/release-staging/
- name: Set up Node.js with npm registry
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Publish codecane staging package to npm
run: |
cd cli/release-staging
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}