-
Notifications
You must be signed in to change notification settings - Fork 0
docs: expand usage guide — architecture, GHA/K8s recipes, troubleshooting #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| name: Reusable — opencode run | ||
|
|
||
| # Consumers call this via: | ||
| # | ||
| # jobs: | ||
| # run: | ||
| # uses: vymalo/opencode-oauth2/.github/workflows/opencode-run.yml@v0.2.0 | ||
| # with: | ||
| # model: miaou/glm-5 | ||
| # prompt: "Summarize the changes" | ||
| # opencode-config-path: .opencode-ci/opencode.json | ||
| # | ||
| # Consumer must: | ||
| # - grant `permissions: { id-token: write, contents: read }` on the caller job | ||
| # - commit an opencode.json at `opencode-config-path` with | ||
| # `authFlow: "jwt_bearer"` + `subjectTokenSource: { type: "github_actions" }` | ||
| # - have an IdP that trusts GitHub Actions OIDC for the configured audience | ||
| # | ||
| # See docs/github-actions.md for end-to-end setup. | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| model: | ||
| description: 'Model id passed to `opencode run --model` (e.g. miaou/glm-5).' | ||
| required: true | ||
| type: string | ||
| prompt: | ||
| description: 'Prompt passed to `opencode run`.' | ||
| required: true | ||
| type: string | ||
| opencode-config-path: | ||
| description: 'Path (relative to the repo root) to the opencode.json the runner should use.' | ||
| required: false | ||
| type: string | ||
| default: '.opencode-ci/opencode.json' | ||
| node-version: | ||
| description: 'Node.js version installed on the runner.' | ||
| required: false | ||
| type: string | ||
| default: '22' | ||
| runs-on: | ||
| description: 'Runner image. Defaults to ubuntu-latest.' | ||
| required: false | ||
| type: string | ||
| default: 'ubuntu-latest' | ||
| opencode-version: | ||
| description: 'Pinned `opencode` version to install (npm dist-tag or semver). Empty == latest.' | ||
| required: false | ||
| type: string | ||
| default: '' | ||
| plugin-version: | ||
| description: 'Pinned `@vymalo/opencode-oauth2` version. Empty == latest.' | ||
| required: false | ||
| type: string | ||
| default: '' | ||
| outputs: | ||
| stdout-artifact: | ||
| description: 'Name of the uploaded artifact containing opencode stdout.' | ||
| value: ${{ jobs.run.outputs.stdout-artifact }} | ||
|
|
||
| jobs: | ||
| run: | ||
| name: opencode run | ||
| runs-on: ${{ inputs.runs-on }} | ||
| permissions: | ||
| # OIDC token minting for federated identity (jwt_bearer / token_exchange). | ||
| # The caller must also grant id-token: write — workflow_call inherits | ||
| # the caller's permissions, but the caller cannot grant more than it has. | ||
| id-token: write | ||
| contents: read | ||
| outputs: | ||
| stdout-artifact: opencode-stdout-${{ github.run_id }}-${{ github.run_attempt }} | ||
| steps: | ||
| - name: Checkout caller repo | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ inputs.node-version }} | ||
|
|
||
| - name: Install opencode + plugin | ||
| run: | | ||
| set -euo pipefail | ||
| opencode_spec="opencode" | ||
| if [ -n "${{ inputs.opencode-version }}" ]; then | ||
| opencode_spec="opencode@${{ inputs.opencode-version }}" | ||
| fi | ||
| plugin_spec="@vymalo/opencode-oauth2" | ||
| if [ -n "${{ inputs.plugin-version }}" ]; then | ||
| plugin_spec="@vymalo/opencode-oauth2@${{ inputs.plugin-version }}" | ||
| fi | ||
| npm install -g "$opencode_spec" "$plugin_spec" | ||
|
|
||
| - name: Verify opencode config exists | ||
| run: | | ||
| set -euo pipefail | ||
| cfg="${{ inputs.opencode-config-path }}" | ||
| if [ ! -f "$cfg" ]; then | ||
| echo "::error::opencode config not found at $cfg — commit one (see docs/github-actions.md)" >&2 | ||
| exit 1 | ||
| fi | ||
| # The config dir is what OPENCODE_CONFIG_DIR points to; opencode will | ||
| # read opencode.json from there. | ||
| echo "OPENCODE_CONFIG_DIR=$(dirname "$cfg")" >> "$GITHUB_ENV" | ||
|
|
||
| - name: opencode run | ||
| id: run | ||
| run: | | ||
| set -euo pipefail | ||
| mkdir -p /tmp/opencode-out | ||
| opencode run \ | ||
| --model "${{ inputs.model }}" \ | ||
| "${{ inputs.prompt }}" \ | ||
| | tee /tmp/opencode-out/stdout.txt | ||
|
|
||
| - name: Upload stdout as artifact | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: opencode-stdout-${{ github.run_id }}-${{ github.run_attempt }} | ||
| path: /tmp/opencode-out/stdout.txt | ||
| if-no-files-found: warn | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
.github/workflows/opencode-run.yml, the uploaded artifact name is derived only fromgithub.run_idandgithub.run_attempt, so every invocation of this reusable workflow within the same caller workflow run uses the same name. Withactions/upload-artifact@v4, artifact names must be unique per run; if a caller uses this reusable workflow in multiple jobs or a matrix, later uploads fail with a conflict error, breaking those jobs even thoughopencode runsucceeded.Useful? React with 👍 / 👎.