-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (135 loc) · 5.33 KB
/
Copy pathopencode.yml
File metadata and controls
147 lines (135 loc) · 5.33 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
name: opencode
on:
workflow_call:
inputs:
model:
description: OpenCode model to use.
type: string
default: openrouter/google/gemini-3.1-pro-preview-customtools
opencode_version:
description: OpenCode npm package version to run. Pinned to avoid the 1.15.1 InstanceRef regression.
type: string
default: 1.15.0
runner:
description: Runner label for the OpenCode job.
type: string
default: ubuntu-latest
agents_repository:
description: Repository containing the shared Darkmatter OpenCode preset and skills.
type: string
default: darkmatter/skills
agents_ref:
description: Git ref to checkout from the shared agents repository.
type: string
default: main
prompt:
description: Optional prompt override. Leave empty to use prompt_file from the shared agents repository.
type: string
default: ""
prompt_file:
description: Prompt file path inside the shared agents repository.
type: string
default: .github/prompts/opencode.md
secrets:
OPENROUTER_API_KEY:
required: false
ANTHROPIC_API_KEY:
required: false
AGENTS_REPO_TOKEN:
required: false
GH_ACCESS_TOKEN:
required: false
DARKMATTER_APP_ID:
required: false
DARKMATTER_APP_PRIVATE_KEY:
required: false
jobs:
opencode:
if: |
contains(github.event.comment.body, ' /oc') ||
startsWith(github.event.comment.body, '/oc') ||
contains(github.event.comment.body, ' /opencode') ||
startsWith(github.event.comment.body, '/opencode')
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
pull-requests: write
issues: write
env:
DARKMATTER_APP_AUTH_ENABLED: ${{ secrets.DARKMATTER_APP_ID != '' && secrets.DARKMATTER_APP_PRIVATE_KEY != '' }}
steps:
- name: Checkout caller repository
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Resolve shared agents repository
id: agents-repository
env:
AGENTS_REPOSITORY: ${{ inputs.agents_repository }}
run: |
echo "owner=${AGENTS_REPOSITORY%%/*}" >> "$GITHUB_OUTPUT"
echo "repo=${AGENTS_REPOSITORY#*/}" >> "$GITHUB_OUTPUT"
- name: Mint shared agents repository token
id: agents-token
if: env.DARKMATTER_APP_AUTH_ENABLED == 'true'
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.DARKMATTER_APP_ID }}
private-key: ${{ secrets.DARKMATTER_APP_PRIVATE_KEY }}
owner: ${{ steps.agents-repository.outputs.owner }}
repositories: ${{ steps.agents-repository.outputs.repo }}
- name: Mint caller repository token
id: caller-token
if: env.DARKMATTER_APP_AUTH_ENABLED == 'true'
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.DARKMATTER_APP_ID }}
private-key: ${{ secrets.DARKMATTER_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ github.event.repository.name }}
- name: Checkout shared Darkmatter agent presets
uses: actions/checkout@v6
with:
repository: ${{ inputs.agents_repository }}
ref: ${{ inputs.agents_ref }}
path: .darkmatter-agents
persist-credentials: false
token: ${{ steps.agents-token.outputs.token || secrets.AGENTS_REPO_TOKEN || secrets.GH_ACCESS_TOKEN || github.token }}
- name: Install shared OpenCode preset and skills
run: ./.darkmatter-agents/scripts/install-opencode.sh --copy --target "${XDG_CONFIG_HOME:-$HOME/.config}/opencode"
- name: Resolve OpenCode prompt
id: prompt
env:
PROMPT_INPUT: ${{ inputs.prompt }}
PROMPT_FILE: ${{ inputs.prompt_file }}
run: |
{
echo 'prompt<<__OPENCODE_PROMPT__'
if [ -n "$PROMPT_INPUT" ]; then
printf '%s\n' "$PROMPT_INPUT"
else
cat ".darkmatter-agents/$PROMPT_FILE"
fi
echo '__OPENCODE_PROMPT__'
} >> "$GITHUB_OUTPUT"
- name: Remove shared agents checkout from caller worktree
run: rm -rf .darkmatter-agents
- name: Configure caller repository git auth
env:
GITHUB_TOKEN: ${{ steps.caller-token.outputs.token || github.token }}
run: |
auth_header="$(python3 -c 'import base64, os; print(base64.b64encode(("x-access-token:" + os.environ["GITHUB_TOKEN"]).encode()).decode())')"
git config --local http.https://github.com/.extraheader "AUTHORIZATION: basic ${auth_header}"
git config --global user.name "opencode-agent[bot]"
git config --global user.email "opencode-agent[bot]@users.noreply.github.com"
- name: Run opencode
env:
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
GITHUB_TOKEN: ${{ steps.caller-token.outputs.token || github.token }}
MODEL: ${{ inputs.model }}
PROMPT: ${{ steps.prompt.outputs.prompt }}
USE_GITHUB_TOKEN: "true"
SHARE: "true"
run: npx -y opencode-ai@${{ inputs.opencode_version }} github run