-
Notifications
You must be signed in to change notification settings - Fork 432
ci: add pkg.pr.new PR preview workflow #152
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
liangshuo-1
merged 12 commits into
larksuite:main
from
kongenpei:codex/pkg-pr-new-workflow
Mar 31, 2026
+186
−0
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
60a0f93
ci: publish PR preview builds to pkg.pr.new
kongenpei 9398f8f
chore: limit pkg-pr-new build targets to 3 platforms
kongenpei 3720833
ci: use node lts in pkg-pr-new workflow
kongenpei 5a7ca52
chore: trim pkg-pr-new to single target to fit size limit
kongenpei 55562a7
ci: publish pkg-pr-new package path without --bin
kongenpei af43a1c
ci: disable compact pkg-pr-new urls for fork previews
kongenpei e2ebc09
ci: post minimal npm -g pkg-pr-new install comment
kongenpei e2a5c40
chore: enable windows amd64 build for pkg-pr-new
kongenpei f68d595
ci: format pkg-pr-new install comment as markdown code block
kongenpei 0cbdf5b
ci: tweak pkg-pr-new comment wording
kongenpei 5e578e7
ci: pin github-script and paginate PR comments
kongenpei ab28665
chore: enable pkg PR build targets
kongenpei 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,81 @@ | ||
| name: PR Preview Package | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened, ready_for_review] | ||
| branches: [main] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| publish: | ||
| if: github.event.pull_request.draft == false | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
|
|
||
| - uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5 | ||
| with: | ||
| go-version-file: go.mod | ||
|
|
||
| - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4 | ||
| with: | ||
| node-version: lts/* | ||
|
|
||
| - name: Build preview package | ||
| run: ./scripts/build-pkg-pr-new.sh | ||
|
|
||
| - name: Publish to pkg.pr.new | ||
| run: npx pkg-pr-new publish --no-compact --json output.json --comment=off ./.pkg-pr-new | ||
|
|
||
| - name: Comment install command | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
| with: | ||
| script: | | ||
| const fs = require("fs"); | ||
| const output = JSON.parse(fs.readFileSync("output.json", "utf8")); | ||
| const url = output?.packages?.[0]?.url; | ||
| if (!url) { | ||
| throw new Error("No package URL found in output.json"); | ||
| } | ||
|
|
||
| const body = [ | ||
| "Install this PR change globally:", | ||
| "", | ||
| "```bash", | ||
| `npm i -g ${url}`, | ||
| "```", | ||
| ].join("\n"); | ||
| const issueNumber = context.issue.number; | ||
|
|
||
| const comments = await github.paginate(github.rest.issues.listComments, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueNumber, | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| const existing = comments.find((comment) => | ||
| comment.user?.login === "github-actions[bot]" && | ||
| typeof comment.body === "string" && | ||
| comment.body.startsWith("Install this PR change globally:") | ||
| ); | ||
|
|
||
| if (existing) { | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existing.id, | ||
| body, | ||
| }); | ||
| } else { | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueNumber, | ||
| body, | ||
| }); | ||
| } | ||
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,105 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | ||
| OUT_DIR="$ROOT_DIR/.pkg-pr-new" | ||
|
|
||
| cd "$ROOT_DIR" | ||
|
|
||
| python3 scripts/fetch_meta.py | ||
|
|
||
| rm -rf "$OUT_DIR" | ||
| mkdir -p "$OUT_DIR/bin" "$OUT_DIR/scripts" | ||
|
|
||
| VERSION="$(node -p "require('./package.json').version")" | ||
| DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)" | ||
| SHA="$(git rev-parse --short HEAD)" | ||
| LDFLAGS="-s -w -X github.com/larksuite/cli/internal/build.Version=${VERSION}-${SHA} -X github.com/larksuite/cli/internal/build.Date=${DATE}" | ||
liangshuo-1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| build_target() { | ||
| local goos="$1" | ||
| local goarch="$2" | ||
| local ext="" | ||
| if [[ "$goos" == "windows" ]]; then | ||
| ext=".exe" | ||
| fi | ||
|
|
||
| local output="$OUT_DIR/bin/lark-cli-${goos}-${goarch}${ext}" | ||
| echo "Building ${goos}/${goarch} -> ${output}" | ||
| CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" go build -trimpath -ldflags "$LDFLAGS" -o "$output" ./main.go | ||
| } | ||
|
|
||
| build_target darwin arm64 | ||
| build_target linux amd64 | ||
| build_target darwin amd64 | ||
| build_target linux arm64 | ||
| build_target windows amd64 | ||
| build_target windows arm64 | ||
|
|
||
| cat > "$OUT_DIR/scripts/run.js" <<'RUNJS' | ||
| #!/usr/bin/env node | ||
| const path = require("path"); | ||
| const { execFileSync } = require("child_process"); | ||
|
|
||
| const isWindows = process.platform === "win32"; | ||
|
|
||
| const platformMap = { | ||
| darwin: "darwin", | ||
| linux: "linux", | ||
| win32: "windows", | ||
| }; | ||
|
|
||
| // TODO: Keep broad platform mapping for now; with pkg.pr.new 20MB limit we only ship a subset of binaries. | ||
| // Track upstream progress before tightening runtime handling: https://github.com/stackblitz-labs/pkg.pr.new/pull/484 | ||
|
|
||
| const archMap = { | ||
| x64: "amd64", | ||
| arm64: "arm64", | ||
| }; | ||
|
|
||
| const platform = platformMap[process.platform]; | ||
| const arch = archMap[process.arch]; | ||
|
|
||
| if (!platform || !arch) { | ||
| console.error(`Unsupported platform: ${process.platform}-${process.arch}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const ext = isWindows ? ".exe" : ""; | ||
| const binary = path.join(__dirname, "..", "bin", `lark-cli-${platform}-${arch}${ext}`); | ||
|
|
||
| try { | ||
| execFileSync(binary, process.argv.slice(2), { stdio: "inherit" }); | ||
| } catch (err) { | ||
| process.exit(err.status || 1); | ||
| } | ||
| RUNJS | ||
liangshuo-1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| chmod +x "$OUT_DIR/scripts/run.js" | ||
|
|
||
| cat > "$OUT_DIR/package.json" <<EOF_JSON | ||
| { | ||
| "name": "@larksuite/cli", | ||
| "version": "${VERSION}-pr.${SHA}", | ||
kongenpei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "description": "The official CLI for Lark/Feishu open platform (PR preview build)", | ||
| "bin": { | ||
| "lark-cli": "scripts/run.js" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/larksuite/cli.git" | ||
| }, | ||
| "license": "MIT", | ||
| "files": [ | ||
| "bin", | ||
| "scripts/run.js", | ||
| "CHANGELOG.md", | ||
| "LICENSE" | ||
| ] | ||
| } | ||
| EOF_JSON | ||
|
|
||
| cp CHANGELOG.md "$OUT_DIR/CHANGELOG.md" | ||
| cp LICENSE "$OUT_DIR/LICENSE" | ||
|
|
||
| echo "Prepared pkg.pr.new package at $OUT_DIR" | ||
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.