Skip to content

Commit

Permalink
ci: fix pr comments (#5384)
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee authored Dec 26, 2023
1 parent ea4f63c commit f5e0f92
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 10 deletions.
35 changes: 29 additions & 6 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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}}
51 changes: 47 additions & 4 deletions .github/workflows/commenter.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}}

0 comments on commit f5e0f92

Please sign in to comment.