Skip to content

Commit f6f7c31

Browse files
authored
chore(ci): remove squash requirement (#333892)
1 parent 03978cd commit f6f7c31

1 file changed

Lines changed: 47 additions & 41 deletions

File tree

build/azure-pipelines/product-build-ado-ci.yml

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -260,57 +260,63 @@ extends:
260260
- script: |
261261
set -euo pipefail
262262
263-
if [ "$(Build.Reason)" = "PullRequest" ]; then
264-
# Azure normally checks out a synthetic merge commit for PR validation. Its first
265-
# parent is the target and its second parent is the PR head. Fall back to finding
266-
# the merge base when the provider checks out the PR head directly.
267-
parent_count=$(git rev-list --parents -n 1 HEAD | awk '{ print NF - 1 }')
268-
if [ "$parent_count" = "2" ]; then
269-
base_sha=$(git rev-parse HEAD^1)
270-
head_sha=$(git rev-parse HEAD^2)
271-
else
272-
target_branch="$(System.PullRequest.TargetBranch)"
273-
target_branch="${target_branch#refs/heads/}"
274-
git fetch origin "$target_branch:refs/remotes/origin/$target_branch"
275-
head_sha=$(git rev-parse HEAD)
276-
base_sha=$(git merge-base "origin/$target_branch" "$head_sha")
277-
fi
263+
# Only validate trailers for PR builds
264+
if [ "$(Build.Reason)" != "PullRequest" ]; then
265+
echo "Skipping trailer check for non-PR builds"
266+
exit 0
267+
fi
268+
269+
# Azure normally checks out a synthetic merge commit for PR validation. Its first
270+
# parent is the target and its second parent is the PR head. Fall back to finding
271+
# the merge base when the provider checks out the PR head directly.
272+
parent_count=$(git rev-list --parents -n 1 HEAD | awk '{ print NF - 1 }')
273+
if [ "$parent_count" = "2" ]; then
274+
base_sha=$(git rev-parse HEAD^1)
275+
head_sha=$(git rev-parse HEAD^2)
278276
else
279-
# Manual builds validate the selected branch's latest commit.
277+
target_branch="$(System.PullRequest.TargetBranch)"
278+
target_branch="${target_branch#refs/heads/}"
279+
git fetch origin "$target_branch:refs/remotes/origin/$target_branch"
280280
head_sha=$(git rev-parse HEAD)
281-
base_sha=$(git rev-parse HEAD^1)
281+
base_sha=$(git merge-base "origin/$target_branch" "$head_sha")
282282
fi
283283
284-
# MSRC pull requests must be squashed to one commit before validation succeeds.
285-
commit_count=$(git rev-list --count "$base_sha..$head_sha")
286-
if [ "$commit_count" != "1" ]; then
287-
echo "##vso[task.logissue type=error]This PR has $commit_count commits. release/msrc/* PRs must contain exactly one commit. Please squash your commits."
288-
exit 1
289-
fi
290-
echo "PR has a single commit."
284+
# Check each commit in the PR for the Msrc-Case-Id trailer
285+
commits=$(git rev-list "$base_sha..$head_sha")
286+
commits_with_trailer=0
287+
total_commits=0
291288
292-
# Extract every Msrc-Case-Id trailer value from the PR head commit.
293-
mapfile -t trailer_values < <(
294-
git log -1 --pretty='format:%(trailers:key=Msrc-Case-Id,valueonly=true)' "$head_sha" |
295-
sed '/^[[:space:]]*$/d'
296-
)
289+
for commit in $commits; do
290+
total_commits=$((total_commits + 1))
297291
298-
if [ "${#trailer_values[@]}" = "0" ]; then
299-
echo "##vso[task.logissue type=error]Commit $head_sha is missing the required 'Msrc-Case-Id' trailer."
300-
printf "Add a trailer to the commit message, for example:\n\n Msrc-Case-Id: 12345\n\nIf there is no associated case ID, use N/A:\n\n Msrc-Case-Id: N/A\n\n"
301-
exit 1
302-
fi
292+
# Extract Msrc-Case-Id trailer values from this commit
293+
mapfile -t trailer_values < <(
294+
git log -1 --pretty='format:%(trailers:key=Msrc-Case-Id,valueonly=true)' "$commit" |
295+
sed '/^[[:space:]]*$/d'
296+
)
297+
298+
if [ "${#trailer_values[@]}" -gt 0 ]; then
299+
commits_with_trailer=$((commits_with_trailer + 1))
303300
304-
# Every supplied case ID must be numeric or explicitly marked not applicable.
305-
for value in "${trailer_values[@]}"; do
306-
if [[ ! "$value" =~ ^[0-9]+$ && "$value" != "N/A" ]]; then
307-
echo "##vso[task.logissue type=error]Commit $head_sha has an invalid 'Msrc-Case-Id' trailer value. Expected a number or N/A."
308-
printf "Use a numeric case id or N/A, for example:\n\n Msrc-Case-Id: 12345\n\n"
309-
exit 1
301+
# Validate all trailer values are numeric or N/A
302+
for value in "${trailer_values[@]}"; do
303+
if [[ ! "$value" =~ ^[0-9]+$ && "$value" != "N/A" ]]; then
304+
echo "##vso[task.logissue type=error]Commit $commit has an invalid 'Msrc-Case-Id' trailer value. Expected a number or N/A."
305+
printf "Use a numeric case id or N/A, for example:\n\n Msrc-Case-Id: 12345\n\n"
306+
exit 1
307+
fi
308+
done
309+
310+
echo "Commit $commit has the following 'Msrc-Case-Id' trailers: ${trailer_values[*]}"
310311
fi
311312
done
312313
313-
echo "Commit $head_sha has the required 'Msrc-Case-Id' trailer."
314+
# At least one commit must have the Msrc-Case-Id trailer
315+
if [ "$commits_with_trailer" -lt 1 ]; then
316+
echo "##vso[task.logissue type=error]Expected at least one commit with 'Msrc-Case-Id' trailer, but found $commits_with_trailer out of $total_commits commits with a trailer."
317+
printf "Add a trailer to at least one commit message, for example:\n\n Msrc-Case-Id: 12345\n\nIf there is no associated case ID, use N/A:\n\n Msrc-Case-Id: N/A\n\n"
318+
exit 1
319+
fi
314320
displayName: Verify Commit and Trailer
315321
316322
- stage: Quality

0 commit comments

Comments
 (0)