-
Notifications
You must be signed in to change notification settings - Fork 0
chore: add npm release automation #2
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,80 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| id-token: write | ||
|
|
||
| jobs: | ||
| release: | ||
| name: Version, changelog, and publish | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Create or finalize release | ||
| id: release | ||
| uses: googleapis/release-please-action@5c625bfb5d1ff62eadeeb3772007f7f66fdcf071 # v4 | ||
| with: | ||
| config-file: release-please-config.json | ||
| manifest-file: .release-please-manifest.json | ||
|
|
||
| - name: Check out repository | ||
| if: ${{ steps.release.outputs.release_created == 'true' }} | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| with: | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Node.js | ||
| if: ${{ steps.release.outputs.release_created == 'true' }} | ||
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | ||
| with: | ||
| node-version: 24 | ||
| registry-url: https://registry.npmjs.org | ||
| package-manager-cache: false | ||
|
|
||
| - name: Install dependencies | ||
| if: ${{ steps.release.outputs.release_created == 'true' }} | ||
| run: npm ci | ||
|
|
||
| - name: Test package | ||
| if: ${{ steps.release.outputs.release_created == 'true' }} | ||
| run: npm test | ||
|
|
||
| - name: Generate OpenCode release diff summary | ||
| if: ${{ steps.release.outputs.release_created == 'true' }} | ||
| continue-on-error: true | ||
| env: | ||
| OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }} | ||
| OPENCODE_MODEL: ${{ vars.OPENCODE_MODEL }} | ||
| RELEASE_TAG_NAME: ${{ steps.release.outputs.tag_name }} | ||
| run: node scripts/summarize-release-diff.mjs | ||
|
|
||
| - name: Append OpenCode summary to GitHub release | ||
| if: ${{ steps.release.outputs.release_created == 'true' }} | ||
| continue-on-error: true | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| RELEASE_TAG_NAME: ${{ steps.release.outputs.tag_name }} | ||
| run: | | ||
| if [ ! -s opencode-release-summary.md ]; then | ||
| echo "No OpenCode release summary was generated." | ||
| exit 0 | ||
| fi | ||
|
|
||
| gh release view "$RELEASE_TAG_NAME" --json body --jq '.body // ""' > release-notes.md | ||
| { | ||
| cat release-notes.md | ||
| printf '\n\n## OpenCode Diff Summary\n\n' | ||
| cat opencode-release-summary.md | ||
| } > release-notes-with-opencode.md | ||
| gh release edit "$RELEASE_TAG_NAME" --notes-file release-notes-with-opencode.md | ||
|
the-Drunken-coder marked this conversation as resolved.
|
||
|
|
||
| - name: Publish to npm | ||
| if: ${{ steps.release.outputs.release_created == 'true' }} | ||
| run: npm publish --access public | ||
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,3 @@ | ||
| { | ||
| ".": "0.0.0" | ||
| } |
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
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
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
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,9 @@ | ||
| { | ||
| "packages": { | ||
| ".": { | ||
| "release-type": "node", | ||
| "package-name": "sidc-kit", | ||
| "include-component-in-tag": false | ||
| } | ||
| } | ||
| } |
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,114 @@ | ||
| import { execFileSync, spawnSync } from "node:child_process"; | ||
| import { writeFileSync } from "node:fs"; | ||
|
|
||
| const tagName = process.env.RELEASE_TAG_NAME; | ||
| const openCodeApiKey = process.env.OPENCODE_API_KEY; | ||
| const model = process.env.OPENCODE_MODEL || "opencode/kimi-k2"; | ||
| const contextPath = ".release-diff-context.md"; | ||
| const outputPath = "opencode-release-summary.md"; | ||
| const maxPatchBytes = 120_000; | ||
|
|
||
| if (!tagName) { | ||
| console.log("No release tag was provided; skipping OpenCode release summary."); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| if (!openCodeApiKey) { | ||
| console.log("OPENCODE_API_KEY is not configured; skipping OpenCode release summary."); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| /** | ||
| * Runs a git command and returns trimmed stdout. | ||
| */ | ||
| function git(args) { | ||
| return execFileSync("git", args, { encoding: "utf8" }).trim(); | ||
| } | ||
|
|
||
| /** | ||
| * Runs a git command that may validly fail for first-release history. | ||
| */ | ||
| function optionalGit(args) { | ||
| try { | ||
| return git(args); | ||
| } catch { | ||
| return ""; | ||
| } | ||
| } | ||
|
|
||
| const previousTag = optionalGit(["describe", "--tags", "--abbrev=0", `${tagName}^`]); | ||
| const baseRef = previousTag || git(["rev-list", "--max-parents=0", tagName]); | ||
| const range = `${baseRef}..${tagName}`; | ||
| const diffStat = optionalGit(["diff", "--stat", range]); | ||
| const nameStatus = optionalGit(["diff", "--name-status", range]); | ||
| const commits = optionalGit(["log", "--oneline", "--no-decorate", range]); | ||
| const patch = optionalGit(["diff", "--no-ext-diff", "--unified=40", range, "--", ".", ":(exclude)package-lock.json"]); | ||
| const truncatedPatch = | ||
| Buffer.byteLength(patch, "utf8") > maxPatchBytes | ||
| ? `${Buffer.from(patch).subarray(0, maxPatchBytes).toString("utf8")}\n\n[Diff truncated at ${maxPatchBytes} bytes.]` | ||
| : patch; | ||
|
|
||
| writeFileSync( | ||
| contextPath, | ||
| [ | ||
| `# Release Diff Context`, | ||
| ``, | ||
| `Current tag: ${tagName}`, | ||
| `Previous tag: ${previousTag || "(none; comparing from initial commit)"}`, | ||
| `Compared range: ${range}`, | ||
| ``, | ||
| `## Commits`, | ||
| commits || "(none)", | ||
| ``, | ||
| `## Changed Files`, | ||
| nameStatus || "(none)", | ||
| ``, | ||
| `## Diff Stat`, | ||
| diffStat || "(none)", | ||
| ``, | ||
| `## Patch`, | ||
| "```diff", | ||
| truncatedPatch || "(none)", | ||
| "```", | ||
| "" | ||
| ].join("\n") | ||
| ); | ||
|
|
||
| const prompt = [ | ||
| "Summarize this release diff for maintainers and npm users.", | ||
| "Use concise Markdown.", | ||
| "Focus on user-visible changes, migration notes, packaging changes, and risks.", | ||
| "Do not invent changes that are not supported by the attached diff context.", | ||
| "Do not include secrets, token values, or operational speculation.", | ||
| "Return only the summary body." | ||
| ].join(" "); | ||
|
|
||
| const result = spawnSync( | ||
| "npx", | ||
| ["-y", "opencode-ai@1.17.9", "run", "--pure", "--model", model, "--file", contextPath, prompt], | ||
| { | ||
| encoding: "utf8", | ||
| env: process.env, | ||
| killSignal: "SIGTERM", | ||
| timeout: 120_000 | ||
| } | ||
| ); | ||
|
the-Drunken-coder marked this conversation as resolved.
|
||
|
|
||
| if (result.error?.code === "ETIMEDOUT") { | ||
| console.error("OpenCode summary generation timed out."); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| if (result.status !== 0) { | ||
| console.error(result.stderr || result.stdout || "OpenCode summary generation failed."); | ||
| process.exit(result.status ?? 1); | ||
| } | ||
|
|
||
| const summary = result.stdout.trim(); | ||
| if (!summary) { | ||
| console.log("OpenCode returned an empty summary."); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| writeFileSync(outputPath, `${summary}\n`); | ||
| console.log(`Wrote OpenCode release summary to ${outputPath}.`); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.