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
60 changes: 57 additions & 3 deletions .github/workflows/release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,40 @@ jobs:
- name: Check for unreleased changes
id: check
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
REPO: ${{ github.repository }}
STAGING: ${{ inputs.staging-branch }}
BASE: ${{ inputs.base-branch }}
run: |
set -euo pipefail
# Release PRs are squash merged, so the commits they shipped never become
# ancestors of BASE. The head of the last merged one marks what shipped.
SINCE=""
if LAST=$(gh pr list --repo "${REPO}" --base "${BASE}" --head "${STAGING}" \
--state merged --limit 20 --json headRefOid,mergedAt,isCrossRepository \
--jq 'map(select(.isCrossRepository | not)) | sort_by(.mergedAt) | last | .headRefOid // empty'); then
if [ -z "$LAST" ]; then
echo "No merged release PR yet. Listing every commit not on ${BASE}."
elif ! [[ "$LAST" =~ ^[0-9a-f]{40}$ ]]; then
echo "::warning::The last release PR head is not a commit SHA. Listing every commit not on ${BASE}."
elif git merge-base --is-ancestor "$LAST" "origin/${STAGING}"; then
SINCE="$LAST"
else
echo "::warning::Last release head ${LAST} is not on ${STAGING}. Listing every commit not on ${BASE}."
fi
else
echo "::warning::Could not look up the last merged release PR. Listing every commit not on ${BASE}."
fi
echo "since=${SINCE}" >> "$GITHUB_OUTPUT"

RANGE=("origin/${STAGING}" "^origin/${BASE}")
if [ -n "$SINCE" ]; then
RANGE+=("^${SINCE}")
fi
if git diff --quiet "origin/${BASE}" "origin/${STAGING}"; then
AHEAD=0
else
AHEAD=$(git rev-list --count "origin/${BASE}..origin/${STAGING}")
AHEAD=$(git rev-list --count --no-merges "${RANGE[@]}")
fi
echo "ahead=$AHEAD" >> "$GITHUB_OUTPUT"
if [ "$AHEAD" -eq 0 ]; then
Expand All @@ -140,11 +166,38 @@ jobs:
STAGING: ${{ inputs.staging-branch }}
BASE: ${{ inputs.base-branch }}
FROZEN: ${{ steps.freeze.outputs.frozen }}
SINCE: ${{ steps.check.outputs.since }}
run: |
set -euo pipefail

COMMITS=$(git log --oneline --no-merges "origin/${BASE}..origin/${STAGING}")
CONTRIBUTORS=$(git log --format='%an' "origin/${BASE}..origin/${STAGING}" | sort -u | sed 's/^/- /')
RANGE=("origin/${STAGING}" "^origin/${BASE}")
if [ -n "$SINCE" ]; then
RANGE+=("^${SINCE}")
fi

# GitHub rejects a PR body over 65536 characters. Subjects have no length
# limit, so the list is capped by characters as well as by count.
MAX_LISTED=250
LIST_BUDGET=50000
TOTAL=$(git rev-list --count --no-merges "${RANGE[@]}")
CANDIDATES=$(git log --oneline --no-merges --max-count="${MAX_LISTED}" "${RANGE[@]}")
COMMITS=""
LISTED=0
if [ -n "$CANDIDATES" ]; then
while IFS= read -r LINE; do
if [ $(( ${#COMMITS} + ${#LINE} + 1 )) -gt "$LIST_BUDGET" ]; then
break
fi
COMMITS+="${LINE}"$'\n'
LISTED=$((LISTED + 1))
done <<< "$CANDIDATES"
fi
COMMITS="${COMMITS%$'\n'}"
OVERFLOW_LINE=""
if [ "$TOTAL" -gt "$LISTED" ]; then
OVERFLOW_LINE="Showing the newest ${LISTED} of ${TOTAL} commits. [Compare](https://github.com/${REPO}/compare/${SINCE:-$BASE}...${STAGING})"
fi
CONTRIBUTORS=$(git log --format='%an' "${RANGE[@]}" | sort -u | sed 's/^/- /')

# Find the PR before writing about it. The body describes whether this is
# a draft, and only the PR itself knows that: an existing PR may already
Expand Down Expand Up @@ -185,6 +238,7 @@ jobs:
\`\`\`
${COMMITS}
\`\`\`
${OVERFLOW_LINE}

### Contributors
${CONTRIBUTORS}
Expand Down
Loading