Skip to content

Commit 3a7a2a8

Browse files
author
Frank
committed
wip: github actions
1 parent 10ae43a commit 3a7a2a8

File tree

17 files changed

+1333
-1146
lines changed

17 files changed

+1333
-1146
lines changed

.github/workflows/opencode.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ on:
66

77
jobs:
88
opencode:
9-
if: startsWith(github.event.comment.body, 'hey opencode')
9+
if: |
10+
startsWith(github.event.comment.body, 'opencode') ||
11+
startsWith(github.event.comment.body, 'hi opencode') ||
12+
startsWith(github.event.comment.body, 'hey opencode') ||
13+
contains(github.event.comment.body, '@opencode-agent')
1014
runs-on: ubuntu-latest
1115
permissions:
1216
id-token: write
@@ -17,7 +21,7 @@ jobs:
1721
fetch-depth: 1
1822

1923
- name: Run opencode
20-
uses: sst/opencode/sdks/github@github-v1
24+
uses: sst/opencode/github@latest
2125
env:
2226
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
2327
with:

bun.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# opencode GitHub Action
2+
3+
A GitHub Action that integrates [opencode](https://opencode.ai) directly into your GitHub workflow.
4+
5+
Start your comment with `hey opencode`, and opencode will take action via your GitHub Actions runner.
6+
7+
## Features
8+
9+
#### Triage and explain issues
10+
11+
```
12+
hey opencode, explain this issue
13+
```
14+
15+
#### Fix or implement issues - opencode will create a PR with the changes.
16+
17+
```
18+
hi opencode, fix this
19+
```
20+
21+
- Review PRs and make changes
22+
23+
```
24+
Delete the attachment from S3 when the note is removed @opencode-agent
25+
```
26+
27+
## Installation
28+
29+
Run the following command in the terminal from your GitHub repo:
30+
31+
```
32+
opencode github install
33+
```
34+
35+
This will walk you through installing the GitHub app, configuring the workflow, and setting up secrets.
36+
37+
### Manual Setup
38+
39+
1. Install the GitHub app https://github.com/apps/opencode-agent. Make sure it is installed on the target repository.
40+
2. Add the following workflow file to `.github/workflows/opencode.yml` in your repo. Set the appropriate `model` and required API keys in `env`.
41+
42+
```yml
43+
name: opencode
44+
45+
on:
46+
issue_comment:
47+
types: [created]
48+
49+
jobs:
50+
opencode:
51+
if: |
52+
startsWith(github.event.comment.body, 'opencode') ||
53+
startsWith(github.event.comment.body, 'hi opencode') ||
54+
startsWith(github.event.comment.body, 'hey opencode') ||
55+
contains(github.event.comment.body, '@opencode-agent')
56+
runs-on: ubuntu-latest
57+
permissions:
58+
id-token: write
59+
steps:
60+
- name: Checkout repository
61+
uses: actions/checkout@v4
62+
with:
63+
fetch-depth: 1
64+
65+
- name: Run opencode
66+
uses: sst/opencode/github@latest
67+
env:
68+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
69+
with:
70+
model: anthropic/claude-sonnet-4-20250514
71+
```
72+
73+
3. Store the API keys in secrets. In your organization or project **settings**, expand **Secrets and variables** on the left and select **Actions**. Add the required API keys.
74+
75+
## Support
76+
77+
This is an early release. If you encounter issues or have feedback, please create an issue at https://github.com/sst/opencode/issues.
78+
79+
## Development
80+
81+
To test locally:
82+
83+
1. Navigate to a test repo (e.g. `hello-world`):
84+
85+
```
86+
cd hello-world
87+
```
88+
89+
2. Run:
90+
91+
```
92+
MODEL=anthropic/claude-sonnet-4-20250514 \
93+
ANTHROPIC_API_KEY=sk-ant-api03-1234567890 \
94+
GITHUB_RUN_ID=dummy \
95+
bun /path/to/opencode/packages/opencode/src/index.ts github run \
96+
--token 'github_pat_1234567890' \
97+
--event '{"eventName":"issue_comment",...}'
98+
```
99+
100+
- `MODEL`: The model used by opencode. Same as the `MODEL` defined in the GitHub workflow.
101+
- `ANTHROPIC_API_KEY`: Your model provider API key. Same as the keys defined in the GitHub workflow.
102+
- `GITHUB_RUN_ID`: Dummy value to emulate GitHub action environment.
103+
- `/path/to/opencode`: Path to your cloned opencode repo. `bun /path/to/opencode/packages/opencode/src/index.ts` runs your local version of `opencode`.
104+
- `--token`: A GitHub persontal access token. This token is used to verify you have `admin` or `write` access to the test repo. Generate a token [here](https://github.com/settings/personal-access-tokens).
105+
- `--event`: Mock GitHub event payload (see templates below).
106+
107+
#### Issue comment event
108+
109+
```
110+
--event '{"eventName":"issue_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"issue":{"number":4},"comment":{"id":1,"body":"hey opencode, summarize thread"}}}'
111+
```
112+
113+
Replace:
114+
115+
- `"owner":"sst"` with repo owner
116+
- `"repo":"hello-world"` with repo name
117+
- `"actor":"fwang"` with the GitHub username of commentor
118+
- `"number":4` with the GitHub issue id
119+
- `"body":"hey opencode, summarize thread"` with comment body
120+
121+
#### Issue comment with image attachment.
122+
123+
```
124+
--event '{"eventName":"issue_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"issue":{"number":4},"comment":{"id":1,"body":"hey opencode, what is in my image ![Image](https://github.com/user-attachments/assets/xxxxxxxx)"}}}'
125+
```
126+
127+
Replace the image URL `https://github.com/user-attachments/assets/xxxxxxxx` with a valid GitHub attachment (you can generate one by commenting with an image in any issue).
128+
129+
#### PR comment event
130+
131+
```
132+
--event '{"eventName":"issue_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"issue":{"number":4,"pull_request":{}},"comment":{"id":1,"body":"hey opencode, summarize thread"}}}'
133+
```

github/action.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: "opencode GitHub Action"
2+
description: "Run opencode in GitHub Actions workflows"
3+
branding:
4+
icon: "code"
5+
color: "orange"
6+
7+
inputs:
8+
model:
9+
description: "Model to use"
10+
required: false
11+
12+
share:
13+
description: "Share the opencode session (defaults to true for public repos)"
14+
required: false
15+
16+
runs:
17+
using: "composite"
18+
steps:
19+
- name: Install opencode
20+
shell: bash
21+
run: curl -fsSL https://opencode.ai/install | bash
22+
23+
- name: Run opencode
24+
shell: bash
25+
id: run_opencode
26+
run: opencode github run
27+
env:
28+
MODEL: ${{ inputs.model }}
29+
SHARE: ${{ inputs.share }}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ if [ -z "$latest_tag" ]; then
88
fi
99
echo "Latest tag: $latest_tag"
1010

11-
# Update github-v1 to latest
12-
git tag -d github-v1
13-
git push origin :refs/tags/github-v1
14-
git tag -a github-v1 $latest_tag -m "Update github-v1 to $latest_tag"
15-
git push origin github-v1
11+
# Update latest tag
12+
git tag -d latest
13+
git push origin :refs/tags/latest
14+
git tag -a latest $latest_tag -m "Update latest to $latest_tag"
15+
git push origin latest

packages/opencode/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"devDependencies": {
1818
"@ai-sdk/amazon-bedrock": "2.2.10",
1919
"@ai-sdk/anthropic": "1.2.12",
20+
"@octokit/webhooks-types": "7.6.1",
2021
"@standard-schema/spec": "1.0.0",
2122
"@tsconfig/bun": "1.0.7",
2223
"@types/bun": "latest",
@@ -27,6 +28,8 @@
2728
"zod-to-json-schema": "3.24.5"
2829
},
2930
"dependencies": {
31+
"@actions/core": "1.11.1",
32+
"@actions/github": "6.0.1",
3033
"@clack/prompts": "0.11.0",
3134
"@hono/zod-validator": "0.4.2",
3235
"@modelcontextprotocol/sdk": "1.15.1",

0 commit comments

Comments
 (0)