Skip to content

Report Results to PR #5738

Report Results to PR

Report Results to PR #5738

Workflow file for this run

name: Report Results to PR
on:
# The pull_request event can't write comments for PRs from forks so using this
# workflow_run workflow as a workaround
workflow_run:
workflows: ['CI']
types:
- completed
- requested
jobs:
filter_jobs:
name: Filter jobs
runs-on: ubuntu-latest
if: |
github.event.workflow_run.event == 'pull_request'
outputs:
jsChanged: ${{ steps.filter.outputs.jsChanged }}
steps:
- uses: actions/checkout@v4
# Warning: This is kinda gnarly and weird! GitHub doesn't expose the `pull_request`
# data if the PR is from a fork, nor does it let you access that data via their API
# (by querying for PRs associated with the commit or querying the commit itself, both
# come up empty for forked commits). As such, to get the base SHA of the PR we need to
# query for all PRs on the repo and match the owner+branch to find the right one and
# then extract the base SHA from that.
#
# I see no reason why GitHub shouldn't expose this, it's just an SHA, branch name, and
# URL, but they don't so we're doing it this way. Hopefully we can remove this one day.
- name: Get PR Base SHA
id: get_pr_base_sha
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FORK_OWNER: ${{ github.event.workflow_run.head_repository.owner.login }}
FORK_BRANCH: ${{ github.event.workflow_run.head_branch }}
run: |
set -euo pipefail
PR_JSON=$(gh api "repos/preactjs/preact/pulls?state=all&head=$FORK_OWNER:$FORK_BRANCH")
BASE_SHA=$(jq -r '.[0].base.sha' <<< "$PR_JSON")
echo "base_sha=$BASE_SHA" >> "$GITHUB_OUTPUT"
- uses: dorny/paths-filter@v3
id: filter
with:
# As this Workflow is triggered by a `workflow_run` event, the filter action
# can't automatically assume we're working with PR data. As such, we need to
# wire it up manually with a base (merge target) and ref (source branch).
base: ${{ steps.get_pr_base_sha.outputs.base_sha }}
ref: ${{ github.event.workflow_run.head_sha }}
# Should be kept in sync with the filter in the CI workflow
predicate-quantifier: 'every'
filters: |
jsChanged:
- '**/src/**/*.js'
- '!devtools/src/devtools.js'
report_running:
name: Report benchmarks are in-progress
needs: filter_jobs
runs-on: ubuntu-latest
# Only add the "benchmarks are running" text when a workflow_run is
# requested (a.k.a starting)
if: |
needs.filter_jobs.outputs.jsChanged == 'true' &&
github.event.action == 'requested'
steps:
- name: Report Tachometer Running
uses: andrewiggins/tachometer-reporter-action@v2
with:
# Set initialize to true so this action just creates the comment or
# adds the "benchmarks are running" text
initialize: true
report_results:
name: Report benchmark results
needs: filter_jobs
runs-on: ubuntu-latest
# Only run this job if the event action was "completed" and the triggering
# workflow_run was successful
if: |
needs.filter_jobs.outputs.jsChanged == 'true' &&
github.event.action == 'completed' &&
github.event.workflow_run.conclusion == 'success'
steps:
# Download the artifact from the triggering workflow that contains the
# Tachometer results to report
- uses: dawidd6/action-download-artifact@v2
with:
workflow: ${{ github.event.workflow.id }}
run_id: ${{ github.event.workflow_run.id }}
name_is_regexp: true
name: results-*
path: results
# Create/update the comment with the latest results
- name: Report Tachometer Results
uses: andrewiggins/tachometer-reporter-action@v2
with:
path: results/**/*.json
base-bench-name: preact-main
pr-bench-name: preact-local
summarize: 'duration, usedJSHeapSize'