-
Notifications
You must be signed in to change notification settings - Fork 5
125 lines (107 loc) · 4.84 KB
/
Copy pathopencode-cli.yml
File metadata and controls
125 lines (107 loc) · 4.84 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
name: OpenCode
on:
issues:
types: [opened] # Triggers when a new issue is opened
permissions:
contents: write # Required to create new branches and push code
pull-requests: write # Required to create PRs
issues: write # Required to link/manage issues
jobs:
issue-agent-coding:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: true
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
# Automatically install dependencies to ensure test environments are fully prepared
- name: Install Project Dependencies
run: |
if [ -f "package-lock.json" ]; then
npm ci
elif [ -f "yarn.lock" ]; then
yarn install --frozen-lockfile
elif [ -f "pnpm-lock.yaml" ]; then
npm install -g pnpm && pnpm install --frozen-lockfile
else
npm install
fi
- name: Install OpenCode CLI
run: |
npm install -g opencode-ai
# Safely extract Issue details using env variables to prevent shell injection/escaping issues
- name: Prepare Prompt from Issue
env:
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_BODY: ${{ github.event.issue.body }}
run: |
echo "### Issue Title: $ISSUE_TITLE" > issue_prompt.txt
echo "### Issue Description:" >> issue_prompt.txt
echo "$ISSUE_BODY" >> issue_prompt.txt
echo "" >> issue_prompt.txt
# Strictly instructs the AI to generate a 'conclusion.md' in English
cat << 'EOF' >> issue_prompt.txt
【Mandatory Requirements】:
1. Please develop or fix the codebase according to the Issue description provided above.
2. After completing the changes, you MUST create a Markdown file named 'conclusion.md' in the root directory.
3. In 'conclusion.md', please describe in detail (strictly in English) which files you modified, what changes you made, what technical solutions you used, and your final implementation summary.
EOF
- name: Run OpenCode Coding Agent
run: |
PROMPT=$(cat issue_prompt.txt)
opencode run \
--model opencode/deepseek-v4-flash-free \
--variant high \
--dangerously-skip-permissions \
"$PROMPT"
- name: Create Branch and Pull Request with AI Conclusion
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
run: |
# Clean up the temporary prompt file
rm -f issue_prompt.txt
# Configure Git Bot credentials
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Check for changes in the workspace
if [ -n "$(git status --porcelain)" ]; then
echo "Changes detected, assembling Pull Request description..."
# 1. Build PR Body
echo "### AI: Resolves #$ISSUE_NUMBER" > pr_body.txt
echo "" >> pr_body.txt
echo "This Pull Request was automatically generated by OpenCode to address Issue #$ISSUE_NUMBER." >> pr_body.txt
echo "" >> pr_body.txt
# 2. Append the AI's conclusion.md and clean up the file
if [ -f "conclusion.md" ]; then
echo "### 📝 AI Modification Summary & Conclusion:" >> pr_body.txt
cat conclusion.md >> pr_body.txt
# Remove conclusion.md before committing to keep the git history clean
rm -f conclusion.md
else
echo "### ⚠️ Warning:" >> pr_body.txt
echo "AI Agent completed the coding task but failed to generate the required 'conclusion.md' file." >> pr_body.txt
fi
# 3. Create a unique branch and commit changes
BRANCH_NAME="opencode/issue-$ISSUE_NUMBER-${{ github.run_id }}"
git checkout -b "$BRANCH_NAME"
git add .
git commit -m "Auto-fix: Resolve Issue #$ISSUE_NUMBER"
git push origin "$BRANCH_NAME"
# 4. Create Pull Request via GitHub CLI
gh pr create \
--title "🤖 Fix: $ISSUE_TITLE (Resolves #$ISSUE_NUMBER)" \
--body-file pr_body.txt \
--head "$BRANCH_NAME" \
--base "${{ github.event.repository.default_branch }}"
# 5. Clean up the PR body cache
rm -f pr_body.txt
else
echo "No changes made by OpenCode."
fi