Skip to content
Open
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
37 changes: 33 additions & 4 deletions .github/workflows/notify-benchmarks.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name: Notify binary-size benchmarks
name: Notify benchmarks

on:
# A push to main is the authoritative post-merge state, including squash and
# rebase merges. The dispatched SHA is the exact LLGo version to measure.
push:
branches: [main]
# Compatibility is intentionally release-based: publishing a stable release
# or prerelease records one durable open-source test result for that tag.
release:
types: [published]

permissions: {}

Expand All @@ -17,21 +21,46 @@ jobs:
# before the migration, then remove it to use xgo-dev/benchmarks.
BENCHMARKS_REPOSITORY: ${{ vars.BENCHMARKS_REPOSITORY || 'xgo-dev/benchmarks' }}
BENCHMARKS_DISPATCH_TOKEN: ${{ secrets.BENCHMARKS_DISPATCH_TOKEN }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
steps:
- name: Request a binary-size build for this LLGo revision
- name: Request benchmarks for this LLGo revision
run: |
set -euo pipefail
if [[ -z "$BENCHMARKS_DISPATCH_TOKEN" ]]; then
echo "BENCHMARKS_DISPATCH_TOKEN is not configured" >&2
exit 1
fi

if [[ "$GITHUB_EVENT_NAME" == "release" ]]; then
if [[ -z "$RELEASE_TAG" ]] || ! git check-ref-format "refs/tags/$RELEASE_TAG"; then
echo "invalid release tag: ${RELEASE_TAG:-missing}" >&2
exit 1
fi
tag_ref="refs/tags/$RELEASE_TAG"
tag_rows="$(git ls-remote "https://github.com/${GITHUB_REPOSITORY}.git" \
"$tag_ref" "$tag_ref^{}")"
llgo_commit="$(awk -v ref="$tag_ref^{}" '$2 == ref { print $1; exit }' <<<"$tag_rows")"
if [[ -z "$llgo_commit" ]]; then
llgo_commit="$(awk -v ref="$tag_ref" '$2 == ref { print $1; exit }' <<<"$tag_rows")"
fi
event_type=llgo-tag-released
else
llgo_commit="$GITHUB_SHA"
event_type=llgo-main-updated
fi
if [[ ! "$llgo_commit" =~ ^[0-9a-f]{40}$ ]]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: the resolved commit is validated for SHA shape only (40 hex chars), not that it actually refers to a commit object. For the normal case — an annotated release tag on a commit — this is fine, since the refs/tags/X^{} peeled entry yields the commit. In the theoretical case of an annotated tag pointing at a non-commit object, the fallback would pick the tag object's own SHA, which also passes this regex. This is extremely unlikely for GitHub release tags (which require a tag on a commit), so it's an accepted-limitation note rather than an actionable defect.

echo "invalid LLGo commit for ${RELEASE_TAG:-$GITHUB_REF}: ${llgo_commit:-missing}" >&2
exit 1
fi

payload="$(jq -cn \
--arg event_type "$event_type" \
--arg source_repository "$GITHUB_REPOSITORY" \
--arg llgo_repository "$GITHUB_REPOSITORY" \
--arg llgo_commit "$GITHUB_SHA" \
--arg llgo_commit "$llgo_commit" \
--arg llgo_tag "$RELEASE_TAG" \
--arg source_run_url "https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" \
'{event_type: "llgo-main-updated", client_payload: {source_repository: $source_repository, llgo_repository: $llgo_repository, llgo_commit: $llgo_commit, source_run_url: $source_run_url}}')"
'{event_type: $event_type, client_payload: {source_repository: $source_repository, llgo_repository: $llgo_repository, llgo_commit: $llgo_commit, llgo_tag: $llgo_tag, source_run_url: $source_run_url}}')"

curl --fail-with-body --location --request POST \
--header 'Accept: application/vnd.github+json' \
Expand Down
Loading