benchmark.yml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. name: Benchmark
  2. on:
  3. issue_comment:
  4. types: [created]
  5. workflow_dispatch:
  6. env:
  7. TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
  8. TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
  9. FORCE_COLOR: true
  10. jobs:
  11. benchmark:
  12. if: ${{ github.repository_owner == 'withastro' && github.event.issue.pull_request && startsWith(github.event.comment.body, '!bench') }}
  13. runs-on: ubuntu-latest
  14. permissions:
  15. contents: read
  16. outputs:
  17. PR-BENCH: ${{ steps.benchmark-pr.outputs.BENCH_RESULT }}
  18. MAIN-BENCH: ${{ steps.benchmark-main.outputs.BENCH_RESULT }}
  19. steps:
  20. # https://github.com/actions/checkout/issues/331#issuecomment-1438220926
  21. - uses: actions/checkout@v4
  22. with:
  23. persist-credentials: false
  24. ref: refs/pull/${{ github.event.issue.number }}/head
  25. - name: Setup PNPM
  26. uses: pnpm/action-setup@v2
  27. - name: Setup Node
  28. uses: actions/setup-node@v4
  29. with:
  30. node-version: 18
  31. cache: "pnpm"
  32. - name: Install dependencies
  33. run: pnpm install
  34. - name: Build Packages
  35. run: pnpm run build
  36. - name: Get bench command
  37. id: bench-command
  38. env:
  39. # protects from untrusted user input and command injection
  40. COMMENT: ${{ github.event.comment.body }}
  41. run: |
  42. benchcmd=$(echo "$COMMENT" | grep '!bench' | awk -F ' ' '{print $2}')
  43. echo "bench=$benchcmd" >> $GITHUB_OUTPUT
  44. shell: bash
  45. - name: Run benchmark
  46. id: benchmark-pr
  47. run: |
  48. result=$(pnpm run --silent benchmark ${{ steps.bench-command.outputs.bench }})
  49. processed=$(node ./benchmark/ci-helper.js "$result")
  50. echo "BENCH_RESULT<<BENCHEOF" >> $GITHUB_OUTPUT
  51. echo "### PR Benchmark" >> $GITHUB_OUTPUT
  52. echo "$processed" >> $GITHUB_OUTPUT
  53. echo "BENCHEOF" >> $GITHUB_OUTPUT
  54. shell: bash
  55. # main benchmark
  56. - uses: actions/checkout@v4
  57. with:
  58. persist-credentials: false
  59. ref: "main"
  60. - name: Install
  61. run: |
  62. pnpm install
  63. - name: Build Packages
  64. run: pnpm run build
  65. - name: Run benchmark
  66. id: benchmark-main
  67. run: |
  68. result=$(pnpm run --silent benchmark ${{ steps.bench-command.outputs.bench }})
  69. processed=$(node ./benchmark/ci-helper.js "$result")
  70. echo "BENCH_RESULT<<BENCHEOF" >> $GITHUB_OUTPUT
  71. echo "### Main Benchmark" >> $GITHUB_OUTPUT
  72. echo "$processed" >> $GITHUB_OUTPUT
  73. echo "BENCHEOF" >> $GITHUB_OUTPUT
  74. shell: bash
  75. output-benchmark:
  76. if: ${{ github.repository_owner == 'withastro' && github.event.issue.pull_request && startsWith(github.event.comment.body, '!bench') }}
  77. needs: [benchmark]
  78. runs-on: ubuntu-latest
  79. permissions:
  80. pull-requests: write
  81. steps:
  82. - name: Comment PR
  83. uses: peter-evans/create-or-update-comment@v4
  84. continue-on-error: true
  85. with:
  86. issue-number: ${{ github.event.issue.number }}
  87. body: |
  88. ${{ needs.benchmark.outputs.PR-BENCH }}
  89. ${{ needs.benchmark.outputs.MAIN-BENCH }}
  90. edit-mode: replace