mirror of
https://github.com/yamadashy/repomix.git
synced 2026-05-30 11:18:53 +02:00
042750cb4e
Now that the minimum supported Node.js version is 22, `node --run` is available everywhere. It avoids the npm process-spawn overhead and matches the style already used in package.json scripts. Affects all GitHub Actions workflows that invoke npm scripts and the website/server Dockerfile bundle step. `npm ci` is left as-is since it is npm-specific.
166 lines
5.9 KiB
YAML
166 lines
5.9 KiB
YAML
name: Performance Benchmark
|
|
|
|
on:
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
concurrency:
|
|
group: perf-benchmark-${{ github.event.pull_request.number }}
|
|
cancel-in-progress: false
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
post-pending:
|
|
name: Post Pending Comment
|
|
runs-on: ubuntu-latest
|
|
if: ${{ github.event.pull_request.head.repo.fork == false }}
|
|
permissions:
|
|
pull-requests: write
|
|
steps:
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
sparse-checkout: .github/scripts/perf-benchmark
|
|
persist-credentials: false
|
|
|
|
- name: Post or update pending comment
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
GH_REPO: ${{ github.repository }}
|
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
|
|
WORKFLOW_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
run: |
|
|
COMMENT_MARKER="<!-- repomix-perf-benchmark -->"
|
|
|
|
# Find existing comment by marker
|
|
COMMENT_ID=$(gh api "repos/${GH_REPO}/issues/${PR_NUMBER}/comments" --paginate --jq ".[] | select(.body | startswith(\"${COMMENT_MARKER}\")) | .id" | head -1)
|
|
|
|
# Save existing comment body to file for safe parsing
|
|
if [ -n "$COMMENT_ID" ]; then
|
|
gh api "repos/${GH_REPO}/issues/comments/${COMMENT_ID}" --jq '.body' > "$RUNNER_TEMP/old-comment.txt"
|
|
else
|
|
echo "" > "$RUNNER_TEMP/old-comment.txt"
|
|
fi
|
|
|
|
# Fetch commit message in shell (avoids escaping issues in Node)
|
|
COMMIT_MSG=$(gh api "repos/${GH_REPO}/commits/${COMMIT_SHA}" --jq '.commit.message | split("\n") | .[0]' 2>/dev/null || echo "")
|
|
|
|
COMMIT_MSG="$COMMIT_MSG" node .github/scripts/perf-benchmark/bench-pending.mjs
|
|
|
|
BODY=$(cat "$RUNNER_TEMP/new-comment.md")
|
|
|
|
if [ -n "$COMMENT_ID" ]; then
|
|
gh api "repos/${GH_REPO}/issues/comments/${COMMENT_ID}" -X PATCH -f body="$BODY"
|
|
else
|
|
gh pr comment "$PR_NUMBER" --body "$BODY"
|
|
fi
|
|
|
|
benchmark:
|
|
name: Benchmark (${{ matrix.os }})
|
|
runs-on: ${{ matrix.os }}
|
|
timeout-minutes: 15
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- os: ubuntu-latest
|
|
runs: 20
|
|
- os: macos-latest
|
|
runs: 30
|
|
- os: windows-latest
|
|
runs: 20
|
|
steps:
|
|
# Checkout PR branch and main branch into separate directories for isolation
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
path: pr-branch
|
|
persist-credentials: false
|
|
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
ref: main
|
|
path: main-branch
|
|
persist-credentials: false
|
|
|
|
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
|
|
with:
|
|
node-version-file: pr-branch/.tool-versions
|
|
cache: npm
|
|
cache-dependency-path: |
|
|
pr-branch/package-lock.json
|
|
main-branch/package-lock.json
|
|
|
|
- name: Install and build (PR branch)
|
|
working-directory: pr-branch
|
|
run: npm ci && node --run build
|
|
|
|
- name: Install and build (main branch)
|
|
working-directory: main-branch
|
|
run: npm ci && node --run build
|
|
|
|
- name: Run benchmark
|
|
shell: bash
|
|
env:
|
|
BENCH_RUNS: ${{ matrix.runs }}
|
|
run: node pr-branch/.github/scripts/perf-benchmark/bench-run.mjs "$GITHUB_WORKSPACE/pr-branch" "$GITHUB_WORKSPACE/main-branch"
|
|
|
|
- name: Upload benchmark result
|
|
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
|
with:
|
|
name: bench-result-${{ matrix.os }}
|
|
path: ${{ runner.temp }}/bench-result.json
|
|
retention-days: 1
|
|
|
|
comment:
|
|
name: Comment Results
|
|
needs: [benchmark, post-pending]
|
|
runs-on: ubuntu-latest
|
|
if: ${{ always() && !cancelled() }}
|
|
permissions:
|
|
pull-requests: write
|
|
steps:
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
sparse-checkout: .github/scripts/perf-benchmark
|
|
persist-credentials: false
|
|
|
|
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
|
|
with:
|
|
path: results
|
|
pattern: bench-result-*
|
|
|
|
- name: Comment on PR
|
|
if: ${{ github.event.pull_request.head.repo.fork == false }}
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
GH_REPO: ${{ github.repository }}
|
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
|
|
WORKFLOW_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
run: |
|
|
COMMENT_MARKER="<!-- repomix-perf-benchmark -->"
|
|
|
|
# Find existing comment and save old body to file
|
|
COMMENT_ID=$(gh api "repos/${GH_REPO}/issues/${PR_NUMBER}/comments" --paginate --jq ".[] | select(.body | startswith(\"${COMMENT_MARKER}\")) | .id" | head -1)
|
|
|
|
if [ -n "$COMMENT_ID" ]; then
|
|
gh api "repos/${GH_REPO}/issues/comments/${COMMENT_ID}" --jq '.body' > "$RUNNER_TEMP/old-comment.txt"
|
|
else
|
|
echo "" > "$RUNNER_TEMP/old-comment.txt"
|
|
fi
|
|
|
|
# Fetch commit message in shell
|
|
COMMIT_MSG=$(gh api "repos/${GH_REPO}/commits/${COMMIT_SHA}" --jq '.commit.message | split("\n") | .[0]' 2>/dev/null || echo "")
|
|
|
|
COMMIT_MSG="$COMMIT_MSG" node .github/scripts/perf-benchmark/bench-comment.mjs
|
|
|
|
BODY=$(cat "$RUNNER_TEMP/new-comment.md")
|
|
|
|
if [ -n "$COMMENT_ID" ]; then
|
|
gh api "repos/${GH_REPO}/issues/comments/${COMMENT_ID}" -X PATCH -f body="$BODY"
|
|
else
|
|
gh pr comment "$PR_NUMBER" --body "$BODY"
|
|
fi
|