mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix(release): count every pusher of a release, need a second maintainer, date approvals (#8076)
* test(release): a release's approver must not have pushed it, and a second maintainer must have * fix(release): count every pusher of a release, need a second maintainer, date approvals * docs(release): who may approve a stable release, and the second maintainer it needs * test(release): a push the activity log records with no account stops the release * fix(release): a push recorded with no account stops the release
This commit is contained in:
@@ -95,7 +95,7 @@ jobs:
|
||||
| select(.merged_at != null and .base.ref == "main" and .merge_commit_sha == $sha)
|
||||
| select(.head.repo.full_name == $repo)
|
||||
| select(.head.ref | test("^release/v[0-9]+[.][0-9]+[.][0-9]+$"))
|
||||
| [.head.ref, .number, .head.sha, .user.login, $sha] | @tsv' "$RUNNER_TEMP/pulls.json")"
|
||||
| [.head.ref, .number, .head.sha, .user.login, .user.type, $sha] | @tsv' "$RUNNER_TEMP/pulls.json")"
|
||||
# A release commit GitHub has not linked to its PR yet must fail, where a rerun recovers it, not skip.
|
||||
if [ -z "$found" ] && [[ "$subject" =~ ^chore:\ release\ v[0-9] ]]; then
|
||||
echo "::error::$commit reads as a release commit but merges no release PR from this repo; rerun once GitHub lists it"
|
||||
@@ -112,19 +112,42 @@ jobs:
|
||||
echo "::error::$SHA is the merge of more than one release PR: $(cut -f1 <<<"$heads" | tr '\n' ' ')"
|
||||
exit 1
|
||||
fi
|
||||
IFS=$'\t' read -r ref number head author release <<<"$heads"
|
||||
IFS=$'\t' read -r ref number head author author_type release <<<"$heads"
|
||||
# Branch protection can be bypassed, so a maintainer who did not open, write or push the release must approve
|
||||
# its final commit, and no maintainer's or app's change request may stand. Anyone can review a public repo:
|
||||
# a person's review counts only with write access. Each reviewer's latest verdict counts.
|
||||
gh api "repos/$REPO/pulls/$number" > "$RUNNER_TEMP/pull.json"
|
||||
gh api --paginate "repos/$REPO/pulls/$number/reviews" > "$RUNNER_TEMP/reviews.json"
|
||||
gh api --paginate "repos/$REPO/pulls/$number/commits" > "$RUNNER_TEMP/commits.json"
|
||||
gh api --paginate "repos/$REPO/issues/$number/events" > "$RUNNER_TEMP/events.json"
|
||||
# Commit names can be anyone's, so every account that pushed the branch is a writer too.
|
||||
gh api --paginate "repos/$REPO/activity?ref=refs/heads/$ref&per_page=100" > "$RUNNER_TEMP/activity.json"
|
||||
listed="$(jq -s 'add | length' "$RUNNER_TEMP/commits.json")"
|
||||
[ "$listed" = "$(jq .commits "$RUNNER_TEMP/pull.json")" ] ||
|
||||
{ echo "::error::#$number has more commits than GitHub lists ($listed), so who wrote it is unknown"; exit 1; }
|
||||
jq -s -r 'add | .[] | select(.activity_type != "branch_deletion") | [.actor.login, .actor.type] | @tsv' \
|
||||
"$RUNNER_TEMP/activity.json" > "$RUNNER_TEMP/pushers.tsv"
|
||||
[ -s "$RUNNER_TEMP/pushers.tsv" ] ||
|
||||
{ echo "::error::no push to $ref is recorded, so who pushed it is unknown"; exit 1; }
|
||||
! cut -f1 "$RUNNER_TEMP/pushers.tsv" | grep -qx '' ||
|
||||
{ echo "::error::a push to $ref is recorded with no account, so who pushed it is unknown"; exit 1; }
|
||||
{
|
||||
echo "$author"
|
||||
cut -f1 "$RUNNER_TEMP/pushers.tsv"
|
||||
jq -s -r 'add | .[] | .author.login?, .committer.login? | values' "$RUNNER_TEMP/commits.json"
|
||||
jq -s -r 'add | .[] | select(.event == "head_ref_force_pushed") | .actor.login? | values' \
|
||||
"$RUNNER_TEMP/events.json"
|
||||
} > "$RUNNER_TEMP/writers.txt"
|
||||
# A second person with write access opened or pushed it; none of them can be the approver.
|
||||
second=""
|
||||
for login in $({ [ "$author_type" != User ] || echo "$author"; awk -F'\t' '$2 == "User" { print $1 }' \
|
||||
"$RUNNER_TEMP/pushers.tsv"; } | sort -u); do
|
||||
permission="$(gh api "repos/$REPO/collaborators/$login/permission" --jq .permission)" ||
|
||||
{ echo "::error::could not read $login's permission on $REPO, so the release does not publish"; exit 1; }
|
||||
case "$permission" in admin | write) second="$login" && break ;; esac
|
||||
done
|
||||
[ -n "$second" ] ||
|
||||
{ echo "::error::no person with write access opened or pushed $ref besides its approver"; exit 1; }
|
||||
: > "$RUNNER_TEMP/maintainers.txt"
|
||||
for login in $(jq -s -r 'add
|
||||
| map(select(.user.type == "User" and (.state == "APPROVED" or .state == "CHANGES_REQUESTED")))
|
||||
@@ -134,13 +157,16 @@ jobs:
|
||||
{ echo "::error::could not read $login's permission on $REPO, so the release does not publish"; exit 1; }
|
||||
case "$permission" in admin | write) echo "$login" >> "$RUNNER_TEMP/maintainers.txt" ;; esac
|
||||
done
|
||||
reviewed="$(jq -s -r --arg head "$head" \
|
||||
# An approval counts only after the PR's last base change, so it reviewed the diff into main.
|
||||
based="$(jq -s -r 'add | map(select(.event == "base_ref_changed") | .created_at) | max // ""' \
|
||||
"$RUNNER_TEMP/events.json")"
|
||||
reviewed="$(jq -s -r --arg head "$head" --arg based "$based" \
|
||||
--rawfile maintainers "$RUNNER_TEMP/maintainers.txt" --rawfile writers "$RUNNER_TEMP/writers.txt" 'add
|
||||
| ($maintainers | split("\n")) as $maintainers | ($writers | split("\n")) as $writers
|
||||
| map(select(.state == "APPROVED" or .state == "CHANGES_REQUESTED"))
|
||||
| map(select(.user.type != "User" or (.user.login | IN($maintainers[]))))
|
||||
| group_by(.user.login) | map(max_by(.submitted_at))
|
||||
| any(.state == "APPROVED" and .commit_id == $head and .user.type == "User"
|
||||
| any(.state == "APPROVED" and .commit_id == $head and .user.type == "User" and .submitted_at > $based
|
||||
and (.user.login | IN($writers[]) | not))
|
||||
and all(.state != "CHANGES_REQUESTED")' \
|
||||
"$RUNNER_TEMP/reviews.json")"
|
||||
|
||||
Reference in New Issue
Block a user