From f5e0f92eda9491116c585142c565efcf7bf7a3e3 Mon Sep 17 00:00:00 2001 From: Uiolee <22849383+uiolee@users.noreply.github.com> Date: Tue, 26 Dec 2023 14:53:53 +0800 Subject: [PATCH] ci: fix pr comments (#5384) --- .github/workflows/benchmark.yml | 35 ++++++++++++++++++---- .github/workflows/commenter.yml | 51 ++++++++++++++++++++++++++++++--- 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 5d27c7401b..e13c8847b1 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -28,15 +28,16 @@ jobs: run: npm install --silent - name: Running benchmark run: node test/benchmark.js --benchmark + profiling: runs-on: ${{ matrix.os }} - permissions: - pull-requests: write # for marocchino/sticky-pull-request-comment to create or update PR comment strategy: matrix: os: [ubuntu-latest] node-version: ["14", "16", "18"] fail-fast: false + env: + comment_file: ".tmp-comment-flamegraph-node${{ matrix.node-version }}.md" steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} @@ -54,8 +55,30 @@ jobs: project: ./.tmp-hexo-theme-unit-test/0x/ login: ${{ secrets.SURGE_LOGIN }} token: ${{ secrets.SURGE_TOKEN }} - - name: Comment PR - uses: marocchino/sticky-pull-request-comment@v2 + + - name: save comment to file + if: ${{github.event_name == 'pull_request' }} + run: | + echo "https://${{ github.sha }}-${{ matrix.node-version }}-hexo.surge.sh/flamegraph.html" > ${{env.comment_file}} + + - uses: actions/upload-artifact@v4 + if: ${{github.event_name == 'pull_request' }} + with: + retention-days: 1 + name: comment-node${{ matrix.node-version }} + path: ${{env.comment_file}} + + number: + runs-on: ubuntu-latest + if: ${{github.event_name == 'pull_request' }} + env: + pr_number_file: .tmp-comment-pr_number + steps: + - name: save PR number to file + run: | + echo -n "${{ github.event.number }}" > ${{env.pr_number_file}} + - uses: actions/upload-artifact@v4 with: - message: | - Publish flamegraph to https://${{ github.sha }}-${{ matrix.node-version }}-hexo.surge.sh/flamegraph.html + retention-days: 1 + name: comment-pr_number + path: ${{env.pr_number_file}} diff --git a/.github/workflows/commenter.yml b/.github/workflows/commenter.yml index f449809a30..1568d8d79e 100644 --- a/.github/workflows/commenter.yml +++ b/.github/workflows/commenter.yml @@ -1,19 +1,27 @@ name: Commenter -on: [pull_request_target] +on: + pull_request_target: + + workflow_run: + workflows: ["Benchmark"] + types: + - completed permissions: contents: read jobs: - commenter: + comment-test: permissions: - pull-requests: write # for marocchino/sticky-pull-request-comment to create or update PR comment + pull-requests: write # for marocchino/sticky-pull-request-comment to create or update PR comment runs-on: ubuntu-latest + if: ${{github.event_name == 'pull_request_target' }} steps: - - name: Comment PR + - name: Comment PR - How to test uses: marocchino/sticky-pull-request-comment@v2 with: + header: How to test message: | ## How to test @@ -23,3 +31,38 @@ jobs: npm install npm test ``` + + comment-flamegraph: + permissions: + pull-requests: write # for marocchino/sticky-pull-request-comment to create or update PR comment + actions: read # get artifact + runs-on: ubuntu-latest + if: ${{github.event_name == 'workflow_run' }} + env: + comment_result: ".tmp-comment-flamegraph.md" + steps: + - name: download artifact + uses: actions/download-artifact@v4 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + run-id: ${{toJSON(github.event.workflow_run.id)}} + pattern: "comment-*" + merge-multiple: true + + - name: get PR number + run: | + echo "pr_number=$(cat .tmp-comment-pr_number)" >> "$GITHUB_ENV" + + - name: combime comment + run: | + echo "## flamegraph" > ${{env.comment_result}} + echo "" >> ${{env.comment_result}} + cat .tmp-comment-flamegraph-*.md >> ${{env.comment_result}} + + - name: Comment PR - flamegraph + uses: marocchino/sticky-pull-request-comment@v2 + with: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + number: ${{env.pr_number}} + header: flamegraph + path: ${{env.comment_result}}