Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(commenter): use workflows_run event to comment flamegraph #5384

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}}
Loading