github.com/bytedance/gopkg@v0.0.0-20240514070511-01b2cbcf35e1/.github/workflows/pr-benchdiff.yml (about) 1 name: Benchdiff 2 3 on: 4 issue_comment: 5 types: [created] 6 pull_request: 7 types: [opened] 8 paths-ignore: 9 - '**.md' 10 11 jobs: 12 # https://github.community/t/cancelling-rest-of-job-if-condition-is-met/18181 13 trigger: 14 name: Pull request comment trigger 15 outputs: 16 triggered: ${{ steps.output.outputs.triggered }} 17 pr_number: ${{ steps.output.outputs.pr_number }} 18 runs-on: self-hosted 19 steps: 20 - name: Check pull request comment 21 if: ${{ github.event_name == 'issue_comment' }} 22 uses: khan/pull-request-comment-trigger@master 23 id: check-comment 24 with: 25 trigger: '/benchdiff' 26 env: 27 GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' 28 - name: Set output 29 id: output 30 run: | 31 echo '::set-output name=triggered::${{ github.event_name == 'pull_request' || steps.check-comment.outputs.triggered }}' 32 echo '::set-output name=pr_number::${{ github.event.pull_request.number || github.event.issue.number }}' 33 34 benchdiff: 35 name: Performance regression check 36 needs: [trigger] 37 if: needs.trigger.outputs.triggered == 'true' 38 runs-on: self-hosted 39 timeout-minutes: 30 40 env: 41 # In markdown URL syntax 42 RUNS_URL: '[${{ github.workflow }} #${{ github.run_number }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})' 43 steps: 44 - name: Report job start 45 uses: peter-evans/create-or-update-comment@v1 46 with: 47 issue-number: '${{ needs.trigger.outputs.pr_number }}' 48 body: | 49 ## Benchdiff 50 51 Runs: ${{ env.RUNS_URL }} 52 53 Job is started. 54 - name: Checkout 55 uses: actions/checkout@v2 56 - name: Checkout pull request HEAD 57 id: head 58 run: | 59 # Fetch github default branch as baseline 60 git fetch origin ${{ github.event.repository.default_branch }}:BENCHDIFF_BASE 61 git checkout BENCHDIFF_BASE 62 echo "::set-output name=base::$(git rev-parse HEAD)" 63 64 # Checkout HEAD of pull request and set its sha to step output 65 git fetch origin pull/${{ needs.trigger.outputs.pr_number }}/head:BENCHDIFF_HEAD 66 git checkout BENCHDIFF_HEAD 67 echo "::set-output name=head::$(git rev-parse HEAD)" 68 69 set -x 70 # Set modified packages to step output 71 # git diff: get difference between HEAD and baseline 72 # grep: filter non-go files 73 # xargs -r: --no-run-if-empty, ignore empty line 74 # xargs dirname: keep only the directory name (go packages) 75 # xargs ls: filter non-exist files 76 # sort | uniq: dedup 77 pkgs=$(git diff --name-only BENCHDIFF_BASE | grep '.go$' | xargs -r dirname | xargs -r ls -d 2>/dev/null | sort | uniq) 78 if [ ! -z "${pkgs}" ]; then 79 # awk: Add "./" prefix to let `go test` known they are relative paths 80 # tr: join paths to one line, otherwise benchdiff cannot recognize it 81 pkgs=$(echo "${pkgs}" | awk '{print "./" $0}' | tr '\n' ' ') 82 fi 83 echo "::set-output name=pkgs::${pkgs}" 84 - name: Setup go 85 uses: actions/setup-go@v2 86 with: 87 go-version: 1.15 88 - name: Benchdiff 89 uses: WillAbides/benchdiff-action@v0.3.3 90 id: diff 91 if: steps.head.outputs.pkgs != '' 92 with: 93 benchdiff_version: 0.7.1 94 status_sha: ${{ steps.head.outputs.head }} 95 status_name: Benchdiff result 96 status_on_degraded: neutral 97 benchdiff_args: | 98 --cpu=4 99 --packages="${{ steps.head.outputs.pkgs }}" 100 --count=10 101 --warmup-count=1 102 --benchtime=1s 103 --benchmem 104 --tolerance=50 105 --base-ref=${{ steps.head.outputs.base }} 106 --debug 107 - name: Report benchdiff result via comment 108 uses: peter-evans/create-or-update-comment@v1 109 if: steps.head.outputs.pkgs != '' 110 with: 111 issue-number: '${{ needs.trigger.outputs.pr_number }}' 112 body: | 113 ## Benchdiff 114 115 Command: `${{ steps.diff.outputs.bench_command }}` 116 HEAD: ${{ steps.diff.outputs.head_sha }} 117 Base: ${{ steps.diff.outputs.base_sha }} 118 Runs: ${{ env.RUNS_URL }} 119 Degraded: ${{ steps.diff.outputs.degraded_result }} 120 121 <details> 122 <summary>Results</summary> 123 124 ${{ steps.diff.outputs.benchstat_output }} 125 126 </details> 127 - name: On skipped 128 uses: peter-evans/create-or-update-comment@v1 129 if: steps.head.outputs.pkgs == '' 130 with: 131 issue-number: '${{ needs.trigger.outputs.pr_number }}' 132 body: | 133 ## Benchdiff 134 135 Runs: ${{ env.RUNS_URL }} 136 137 There is no package to bench. 138 - name: On failure 139 uses: peter-evans/create-or-update-comment@v1 140 if: ${{ failure() }} 141 with: 142 issue-number: '${{ needs.trigger.outputs.pr_number }}' 143 body: | 144 ## Benchdiff 145 146 Runs: ${{ env.RUNS_URL }} 147 148 Job is failed.