forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 6
227 lines (199 loc) · 7.76 KB
/
publish-ocv.yml
File metadata and controls
227 lines (199 loc) · 7.76 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
name: Release ocv
on:
workflow_dispatch:
inputs:
version:
description: "Version (e.g. 1.2.20)"
required: true
type: string
permissions:
contents: write
pull-requests: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
fetch-depth: 0
- name: Validate version
shell: bash
run: |
VERSION="${{ inputs.version }}"
TRACK=$(tr -d '[:space:]' < .github/ocv-track)
if ! printf '%s' "$TRACK" | grep -Eq '^[0-9]+\.[0-9]+$'; then
echo "Invalid ocv track: '$TRACK'"
exit 1
fi
if ! printf '%s' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+-ocv\.[0-9]+\.[0-9]+$'; then
echo "Invalid ocv version: '$VERSION'"
exit 1
fi
if [ "${VERSION##*-ocv.}" != "$TRACK" ]; then
echo "Version track '${VERSION##*-ocv.}' does not match pinned track '$TRACK'"
exit 1
fi
- uses: oven-sh/setup-bun@v2
- name: Install dependencies
run: bun install
- name: Build CLI
run: bun run packages/opencode/script/build.ts --single=false
env:
OPENCODE_VERSION: ${{ inputs.version }}
- name: Package binaries
shell: bash
run: |
DIST="packages/opencode/dist"
mkdir -p "$DIST/release"
for dir in $DIST/opencode-*/; do
[ -d "$dir" ] || continue
name=$(basename "$dir")
target="${name/opencode/ocv}"
bin="$dir/bin/opencode"
if [ ! -f "$bin" ]; then
bin="$dir/bin/opencode.exe"
fi
if [[ "$name" == *windows* ]]; then
cp "$bin" "$DIST/release/$target.exe"
else
cp "$bin" "$DIST/release/$target"
fi
if [[ "$name" == *linux* ]]; then
tar -czf "$DIST/release/$target.tar.gz" -C "$dir/bin" .
else
(cd "$dir/bin" && zip -r "../../release/$target.zip" .)
fi
done
ls -lh "$DIST/release/"
- name: Generate release notes
id: notes
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ inputs.version }}"
BASE="${VERSION%%-ocv.*}"
PATCH="${VERSION##*-ocv.}"
NOTES_FILE="$RUNNER_TEMP/ocv-release-notes.txt"
PRS_FILE="$RUNNER_TEMP/ocv-release-prs.txt"
PREV_TAG=$(git tag --list 'v*-ocv.*' --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-ocv\.[0-9]+\.[0-9]+$' | grep -vx "v$VERSION" | head -n 1)
PREV_PATCH=""
if [ -n "$PREV_TAG" ]; then
PREV_PATCH="${PREV_TAG##*-ocv.}"
git log --first-parent --reverse --format='%H' "$PREV_TAG"..HEAD | while read -r sha; do
gh api "repos/${{ github.repository }}/commits/$sha/pulls" -q '.[] | select(.base.ref == "ocv") | "\(.number)\t\(.title)\t\(.user.login // "")"' || true
done | awk -F '\t' '!seen[$1]++' | while IFS=$'\t' read -r num title author; do
[ -n "$num" ] || continue
if [ -n "$author" ]; then
echo "$title - #$num (@$author)"
continue
fi
echo "$title - #$num"
done > "$PRS_FILE"
else
: > "$PRS_FILE"
fi
echo "based on opencode v$BASE" > "$NOTES_FILE"
if [ -s "$PRS_FILE" ] || { [ -n "$PREV_PATCH" ] && [ "$PATCH" != "$PREV_PATCH" ]; }; then
{
echo
echo "ocv patch $PATCH"
cat "$PRS_FILE"
} >> "$NOTES_FILE"
fi
echo "file=$NOTES_FILE" >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
shell: bash
run: |
VERSION="${{ inputs.version }}"
DIST="packages/opencode/dist/release"
NOTES_FILE="${{ steps.notes.outputs.file }}"
if gh release view "v$VERSION" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
gh release upload "v$VERSION" --repo "$GITHUB_REPOSITORY" --clobber "$DIST"/*
gh release edit "v$VERSION" --repo "$GITHUB_REPOSITORY" --title "v$VERSION" --notes-file "$NOTES_FILE"
else
gh release create "v$VERSION" \
--title "v$VERSION" \
--notes-file "$NOTES_FILE" \
--repo "$GITHUB_REPOSITORY" \
--target "$GITHUB_SHA" \
"$DIST"/*
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v4
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Publish npm package
run: bun run packages/opencode/script/publish-ocv-npm.ts
env:
OPENCODE_VERSION: ${{ inputs.version }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Compute checksums
id: sum
shell: bash
run: |
DIST="packages/opencode/dist/release"
echo "darwin_arm64=$(shasum -a 256 "$DIST/ocv-darwin-arm64.zip" | cut -d ' ' -f 1)" >> "$GITHUB_OUTPUT"
echo "darwin_x64=$(shasum -a 256 "$DIST/ocv-darwin-x64.zip" | cut -d ' ' -f 1)" >> "$GITHUB_OUTPUT"
echo "linux_arm64=$(shasum -a 256 "$DIST/ocv-linux-arm64.tar.gz" | cut -d ' ' -f 1)" >> "$GITHUB_OUTPUT"
echo "linux_x64=$(shasum -a 256 "$DIST/ocv-linux-x64.tar.gz" | cut -d ' ' -f 1)" >> "$GITHUB_OUTPUT"
- name: Checkout tap
uses: actions/checkout@v4
with:
repository: leohenon/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: tap
- name: Update formula
shell: bash
run: |
VERSION="${{ inputs.version }}"
DARWIN_ARM64="${{ steps.sum.outputs.darwin_arm64 }}"
DARWIN_X64="${{ steps.sum.outputs.darwin_x64 }}"
LINUX_ARM64="${{ steps.sum.outputs.linux_arm64 }}"
LINUX_X64="${{ steps.sum.outputs.linux_x64 }}"
cat > tap/Formula/ocv.rb <<EOF
class Ocv < Formula
desc "OpenCode with Vim keybindings - AI coding assistant for the terminal"
homepage "https://github.com/leohenon/opencode-vim"
version "${VERSION}"
license "MIT"
on_macos do
if Hardware::CPU.arm?
url "https://github.com/leohenon/opencode-vim/releases/download/v${VERSION}/ocv-darwin-arm64.zip"
sha256 "${DARWIN_ARM64}"
else
url "https://github.com/leohenon/opencode-vim/releases/download/v${VERSION}/ocv-darwin-x64.zip"
sha256 "${DARWIN_X64}"
end
end
on_linux do
if Hardware::CPU.arm?
url "https://github.com/leohenon/opencode-vim/releases/download/v${VERSION}/ocv-linux-arm64.tar.gz"
sha256 "${LINUX_ARM64}"
else
url "https://github.com/leohenon/opencode-vim/releases/download/v${VERSION}/ocv-linux-x64.tar.gz"
sha256 "${LINUX_X64}"
end
end
def install
bin.install "opencode" => "ocv"
end
test do
assert_match version.to_s, shell_output("\#{bin}/ocv --version", 2)
end
end
EOF
- name: Push formula
shell: bash
run: |
cd tap
git add Formula/ocv.rb
if git diff --cached --quiet; then
echo "Formula unchanged, skipping push"
exit 0
fi
git -c user.name="github-actions[bot]" -c user.email="41898282+github-actions[bot]@users.noreply.github.com" commit -m "Update ocv formula v${{ inputs.version }}"
git push