Skip to content

Commit 94cced9

Browse files
authored
Merge pull request #2 from sun-praise/chore/add-opencode-pr-review
Add OpenCode PR review workflow
2 parents c4e85fc + 9b0ca82 commit 94cced9

2 files changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
OPENCODE_BIN_DIR="${OPENCODE_INSTALL_DIR:-${RUNNER_TOOL_CACHE:-$HOME/.cache}/opencode/bin}"
6+
OPENCODE_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}"
7+
INSTALL_URL="${OPENCODE_INSTALL_URL:-https://opencode.ai/install}"
8+
MAX_ATTEMPTS="${OPENCODE_INSTALL_ATTEMPTS:-3}"
9+
10+
mkdir -p "$OPENCODE_BIN_DIR"
11+
mkdir -p "$OPENCODE_CACHE_DIR"
12+
13+
export OPENCODE_INSTALL_DIR="$OPENCODE_BIN_DIR"
14+
export XDG_CACHE_HOME="$OPENCODE_CACHE_DIR"
15+
export PATH="$OPENCODE_BIN_DIR:$PATH"
16+
17+
link_opencode_bin() {
18+
local source_bin="$1"
19+
20+
if [ -x "$source_bin" ] && [ "$source_bin" != "$OPENCODE_BIN_DIR/opencode" ]; then
21+
ln -sf "$source_bin" "$OPENCODE_BIN_DIR/opencode"
22+
fi
23+
}
24+
25+
if command -v opencode >/dev/null 2>&1; then
26+
echo "OpenCode already installed at: $(command -v opencode)"
27+
opencode --version || true
28+
exit 0
29+
fi
30+
31+
attempt=1
32+
while [ "$attempt" -le "$MAX_ATTEMPTS" ]; do
33+
echo "Installing OpenCode (attempt ${attempt}/${MAX_ATTEMPTS})"
34+
35+
if curl \
36+
--fail \
37+
--silent \
38+
--show-error \
39+
--location \
40+
--retry 5 \
41+
--retry-all-errors \
42+
--retry-delay 2 \
43+
"$INSTALL_URL" | bash; then
44+
break
45+
fi
46+
47+
if [ "$attempt" -eq "$MAX_ATTEMPTS" ]; then
48+
echo "OpenCode installation failed after ${MAX_ATTEMPTS} attempts" >&2
49+
exit 1
50+
fi
51+
52+
sleep $((attempt * 5))
53+
attempt=$((attempt + 1))
54+
done
55+
56+
if [ ! -x "$OPENCODE_BIN_DIR/opencode" ] && [ -x "$HOME/.opencode/bin/opencode" ]; then
57+
link_opencode_bin "$HOME/.opencode/bin/opencode"
58+
fi
59+
60+
if ! command -v opencode >/dev/null 2>&1; then
61+
echo "OpenCode install script finished, but 'opencode' is still unavailable" >&2
62+
exit 1
63+
fi
64+
65+
echo "OpenCode installed at: $(command -v opencode)"
66+
opencode --version || true
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: OpenCode PR Review
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
7+
jobs:
8+
review:
9+
name: AI Code Review
10+
if: github.event.pull_request.draft == false
11+
runs-on: [self-hosted, builder]
12+
permissions:
13+
id-token: write
14+
contents: read
15+
pull-requests: write
16+
issues: write
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v6
20+
with:
21+
persist-credentials: true
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Prepare OpenCode cache paths
25+
run: |
26+
echo "OPENCODE_INSTALL_DIR=${RUNNER_TOOL_CACHE:-$HOME/.cache}/opencode/bin" >> "$GITHUB_ENV"
27+
echo "XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}" >> "$GITHUB_ENV"
28+
echo "${RUNNER_TOOL_CACHE:-$HOME/.cache}/opencode/bin" >> "$GITHUB_PATH"
29+
30+
- name: Install OpenCode if needed
31+
shell: bash
32+
run: bash ./.github/scripts/install-opencode.sh
33+
34+
- name: Run OpenCode Review
35+
env:
36+
MODEL: zhipuai-coding-plan/glm-5
37+
PROMPT: |
38+
Review this pull request (read-only mode, DO NOT modify any code):
39+
40+
Please check:
41+
- Code quality issues
42+
- Potential bugs or logic errors
43+
- Code style consistency
44+
- Security concerns
45+
- Performance issues
46+
- Suggest improvements
47+
48+
Please respond in Chinese. DO NOT modify any code, only provide review comments.
49+
USE_GITHUB_TOKEN: "true"
50+
ZHIPU_API_KEY: ${{ secrets.ZHIPU_API_KEY }}
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
run: opencode github run

0 commit comments

Comments
 (0)