ci: fix flamegraph preview publishing - #5773
Conversation
How to testgit clone -b fix/flamegraph_publish https://github.com/hexojs/hexo.git
cd hexo
npm install
npm test |
There was a problem hiding this comment.
Pull request overview
Reworks the flamegraph preview publishing CI because, due to GitHub's tightened security policy, secrets are no longer available to workflows triggered by pull_request. Publishing for PR builds is moved into a new workflow_run-triggered workflow that can safely access the surge.sh credentials, the directory layout is consolidated so a single sha (or PR) maps to a single surge project, and a protected environment is used to gate the secrets.
Changes:
- Restructured artifact/file naming (drop leading dot so
actions/upload-artifactincludes them) and reorganized flamegraphs under a per-node-version subfolder of a single./flamegraph/project. - Added new
profiling-previewjob (inbenchmark.yml) for push/main builds and a newbenchmark-post.ymlworkflow that runs onworkflow_runto publish PR previews and post the sticky PR comment. - Removed the obsolete
comment-flamegraphjob fromcommenter.yml.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
.github/workflows/benchmark.yml |
Moves flamegraphs into ./flamegraph/<node>/, uploads them as artifacts, and adds a new profiling-preview job that publishes to surge for non-PR events; renames temp files without the leading dot. |
.github/workflows/benchmark-post.yml |
New workflow that, after a successful Benchmark run on a PR, downloads the artifacts, publishes to a per-PR surge subdomain, and posts/updates the sticky PR comment under a protected environment. |
.github/workflows/commenter.yml |
Removes the now-redundant workflow_run trigger and comment-flamegraph job, which have been replaced by benchmark-post.yml. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| url: https://${{ github.sha }}-hexo.surge.sh/ | ||
| comment_result: "tmp-comment-flamegraph.md" | ||
| steps: | ||
| - uses: actions/download-artifact@v8 | ||
| with: | ||
| pattern: "comment-*" | ||
| merge-multiple: true | ||
|
|
||
| - name: Publish flamegraph to ${{ env.url }} | ||
| uses: dswistowski/surge-sh-action@v1 | ||
| with: | ||
| domain: ${{ env.url }} |
|
|
||
| echo "pr_number=$pr_number" | tee -a "$GITHUB_OUTPUT" | ||
| echo "url=https://$pr_number-pr-hexo.surge.sh/" | tee -a "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Publish flamegraph to ${{ steps.get_info.outputs.url }} | ||
| uses: dswistowski/surge-sh-action@v1 | ||
| with: | ||
| domain: ${{ steps.get_info.outputs.url }} |
| profiling-preview: | ||
| needs: profiling | ||
| if: ${{ github.event_name != 'pull_request' }} | ||
| runs-on: ubuntu-slim |
| if: | ||
| ${{ github.event_name == 'workflow_run' && github.event.workflow_run.event | ||
| == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} | ||
| runs-on: ubuntu-slim |
| steps: | ||
| - uses: actions/download-artifact@v8 | ||
| with: | ||
| pattern: "comment-*" |
| core.setOutput('url', `https://${prNumber}-pr-hexo.surge.sh/`); | ||
|
|
||
| - name: Publish flamegraph to ${{ steps.get_info.outputs.url }} | ||
| uses: dswistowski/surge-sh-action@v1 |
| } | tee "${{ env.comment_result }}" >> "$GITHUB_STEP_SUMMARY" | ||
|
|
||
| - name: Comment PR - flamegraph | ||
| uses: marocchino/sticky-pull-request-comment@v3 |
| merge-multiple: true | ||
|
|
||
| - name: Publish flamegraph to ${{ env.url }} | ||
| uses: dswistowski/surge-sh-action@v1 |
c4c2c82 to
9e0ede7
Compare
|
I've rebased with the master branch (to address the merge conflict) and fix some problems:
|
What does it do?
since github action security policy strengthen, secrets could not be accessed in workflow 'on.pull_request'.
Previously one
shaoccupy 3 projects. Now oneshaoccupy 1 project (in main branch) or one PR occupy 1 project (in PR)environmentto strengthen secrets' security.Issue resolved: #5394
Screenshots
Pull request tasks
Add test cases for the changes.