From a366d45a8caeae271407dca287a46ee132040bff Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 27 Aug 2025 17:28:14 -0400 Subject: [PATCH] sync --- github/assistant/action.yml | 43 ++++++++++++++++++++++++ github/{ => assistant}/index.ts | 14 ++++---- github/{ => review}/action.yml | 2 +- github/{review.ts => review/index.ts} | 10 +++--- github/run/action.yml | 48 +++++++++++++++++++++++++++ github/run/index.ts | 31 +++++++++++++++++ 6 files changed, 135 insertions(+), 13 deletions(-) create mode 100644 github/assistant/action.yml rename github/{ => assistant}/index.ts (98%) rename github/{ => review}/action.yml (97%) rename github/{review.ts => review/index.ts} (98%) create mode 100644 github/run/action.yml create mode 100644 github/run/index.ts diff --git a/github/assistant/action.yml b/github/assistant/action.yml new file mode 100644 index 000000000..55646ee6d --- /dev/null +++ b/github/assistant/action.yml @@ -0,0 +1,43 @@ +name: "opencode GitHub Assistant" +description: "Run opencode in GitHub Actions workflows" +branding: + icon: "code" + color: "orange" + +inputs: + model: + description: "The model to use with opencode. Takes the format of `provider/model`." + required: true + + share: + description: "Whether to share the opencode session. Defaults to true for public repositories." + required: false + + token: + description: "Optional GitHub access token for performing operations such as creating comments, committing changes, and opening pull requests. Defaults to the installation access token from the opencode GitHub App." + required: false + +runs: + using: "composite" + steps: + - name: Install opencode + shell: bash + run: curl -fsSL https://opencode.ai/install | bash + + - name: Install bun + shell: bash + run: npm install -g bun + + - name: Install dependencies + shell: bash + run: | + cd ${GITHUB_ACTION_PATH} + bun install + + - name: Run opencode + shell: bash + run: bun ${GITHUB_ACTION_PATH}/index.ts + env: + MODEL: ${{ inputs.model }} + SHARE: ${{ inputs.share }} + TOKEN: ${{ inputs.token }} diff --git a/github/index.ts b/github/assistant/index.ts similarity index 98% rename from github/index.ts rename to github/assistant/index.ts index 0afd2662d..edae4bcea 100644 --- a/github/index.ts +++ b/github/assistant/index.ts @@ -4,13 +4,13 @@ import * as core from "@actions/core" import type { IssueCommentEvent, PullRequestReviewCommentCreatedEvent } from "@octokit/webhooks-types" import { createOpencodeClient } from "@opencode-ai/sdk" import { spawn } from "node:child_process" -import type { GitHubIssue, GitHubPullRequest, IssueQueryResponse, PullRequestQueryResponse } from "./src/types" -import { Context } from "./src/context" -import { Mock } from "./src/mock" -import { Auth } from "./src/auth" -import { Git } from "./src/git" -import { GitHub } from "./src/github" -import { Opencode } from "./src/opencode" +import type { GitHubIssue, GitHubPullRequest, IssueQueryResponse, PullRequestQueryResponse } from "../src/types" +import { Context } from "../src/context" +import { Mock } from "../src/mock" +import { Auth } from "../src/auth" +import { Git } from "../src/git" +import { GitHub } from "../src/github" +import { Opencode } from "../src/opencode" const { client, server } = createOpencode() const mode = Context.eventName() === "pull_request_review_comment" ? defineReviewCommentMode() : defineCommentMode() diff --git a/github/action.yml b/github/review/action.yml similarity index 97% rename from github/action.yml rename to github/review/action.yml index 9893bc808..4e37760a0 100644 --- a/github/action.yml +++ b/github/review/action.yml @@ -1,4 +1,4 @@ -name: "opencode GitHub Action" +name: "opencode GitHub Review" description: "Run opencode in GitHub Actions workflows" branding: icon: "code" diff --git a/github/review.ts b/github/review/index.ts similarity index 98% rename from github/review.ts rename to github/review/index.ts index fe5461073..e01fe23ce 100644 --- a/github/review.ts +++ b/github/review/index.ts @@ -2,11 +2,11 @@ import { $ } from "bun" import os from "node:os" import * as core from "@actions/core" import type { PullRequestReviewCommentEditedEvent } from "@octokit/webhooks-types" -import { Context } from "./src/context" -import { Auth } from "./src/auth" -import { Git } from "./src/git" -import { GitHub } from "./src/github" -import { Opencode } from "./src/opencode" +import { Context } from "../src/context" +import { Auth } from "../src/auth" +import { Git } from "../src/git" +import { GitHub } from "../src/github" +import { Opencode } from "../src/opencode" type Finding = { file: string diff --git a/github/run/action.yml b/github/run/action.yml new file mode 100644 index 000000000..732d67b3a --- /dev/null +++ b/github/run/action.yml @@ -0,0 +1,48 @@ +name: "opencode GitHub Run" +description: "Run opencode in GitHub Actions workflows" +branding: + icon: "code" + color: "orange" + +inputs: + model: + description: "The model to use with opencode. Takes the format of `provider/model`." + required: true + + prompt: + description: "The prompt to use with opencode." + required: true + + share: + description: "Whether to share the opencode session. Defaults to true for public repositories." + required: false + + token: + description: "Optional GitHub access token for performing operations such as creating comments, committing changes, and opening pull requests. Defaults to the installation access token from the opencode GitHub App." + required: false + +runs: + using: "composite" + steps: + - name: Install opencode + shell: bash + run: curl -fsSL https://opencode.ai/install | bash + + - name: Install bun + shell: bash + run: npm install -g bun + + - name: Install dependencies + shell: bash + run: | + cd ${GITHUB_ACTION_PATH} + bun install + + - name: Run opencode + shell: bash + run: bun ${GITHUB_ACTION_PATH}/index.ts + env: + MODEL: ${{ inputs.model }} + PROMPT: ${{ inputs.prompt }} + SHARE: ${{ inputs.share }} + TOKEN: ${{ inputs.token }} diff --git a/github/run/index.ts b/github/run/index.ts new file mode 100644 index 000000000..5c480472e --- /dev/null +++ b/github/run/index.ts @@ -0,0 +1,31 @@ +import { $ } from "bun" +import * as core from "@actions/core" +import { Auth } from "../src/auth" +import { Git } from "../src/git" +import { Opencode } from "../src/opencode" + +try { + await run() + process.exit(0) +} catch (e: any) { + console.error(e) + let msg = e + if (e instanceof $.ShellError) msg = e.stderr.toString() + else if (e instanceof Error) msg = e.message + core.setFailed(msg) + // Also output the clean error message for the action to capture + //core.setOutput("prepare_error", e.message); + process.exit(1) +} + +export async function run() { + try { + await Git.configure() + await Opencode.start() + await Opencode.chat(process.env.PROMPT!) + } finally { + Opencode.closeServer() + await Auth.revoke() + await Git.restore() + } +}