Skip to content

Commit fd902fc

Browse files
[stable2509] Backport #10323 (#10326)
Backport #10323 into `stable2509` from EgorPopelyaev. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> --------- Co-authored-by: Egor_P <egor@parity.io>
1 parent b9669cc commit fd902fc

File tree

1 file changed

+92
-13
lines changed

1 file changed

+92
-13
lines changed

.github/workflows/check-semver.yml

Lines changed: 92 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,68 @@ jobs:
100100
echo "PR_NUMBER=$original_pr_number" >> $GITHUB_ENV
101101
102102
- name: Check semver
103+
if: ${{ github.ref != 'refs/heads/master' }}
104+
shell: bash
103105
env:
104106
PRDOC_EXTRA_ARGS: ${{ env.PRDOC_EXTRA_ARGS }}
105107
PR: ${{ env.PR_NUMBER }}
106108
BASE_BRANCH: ${{ github.event.pull_request.base.ref }}
109+
PR_LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }}
107110
run: |
108111
if [ -z "$PR" ]; then
109112
echo "Skipping master/merge queue"
110113
exit 0
111114
fi
112115
116+
# Skip semver check if PR targets stable branch and has R0-no-crate-publish-require label
117+
if [[ "$BASE_BRANCH" =~ ^stable[0-9]{4}$ ]]; then
118+
if echo "$PR_LABELS" | grep -q "R0-no-crate-publish-require"; then
119+
echo "ℹ️ Skipping the SemVer check is not recommended and should only be done in rare cases: PR targets stable branch '$BASE_BRANCH' and has 'R0-no-crate-publish-require' label."
120+
exit 0
121+
fi
122+
fi
123+
113124
export CARGO_TARGET_DIR=target
114125
export RUSTFLAGS='-A warnings -A missing_docs'
115126
export SKIP_WASM_BUILD=1
116127
117-
if ! parity-publish --color always prdoc --since old --validate prdoc/pr_$PR.prdoc $PRDOC_EXTRA_ARGS -v --toolchain $TOOLCHAIN; then
128+
prdoc_file="prdoc/pr_$PR.prdoc"
129+
130+
# Always run parity-publish to check for all issues (mismatches and missing crates)
131+
# Capture output to check for specific error types
132+
parity_output=$(mktemp)
133+
if ! parity-publish --color always prdoc --since old --validate prdoc/pr_$PR.prdoc $PRDOC_EXTRA_ARGS -v --toolchain $TOOLCHAIN 2>&1 | tee "$parity_output"; then
134+
135+
# Check if there are missing crates (files changed but not listed in prdoc)
136+
if grep -q "Files changed but crate not listed in PR Doc" "$parity_output"; then
137+
rm -f "$parity_output"
138+
cat <<EOF
139+
140+
👋 Hello developer! The SemVer check found crates with changes that are not listed in the prdoc file.
141+
142+
It is recommended to add all changed crates to the prdoc.
143+
144+
Please check the output above and see the following links for more help:
145+
- https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/prdoc.md#record-semver-changes
146+
- https://forum.polkadot.network/t/psa-polkadot-sdk-to-use-semver
147+
148+
Otherwise feel free to ask in the Merge Request or in Matrix chat.
149+
EOF
150+
151+
exit 1
152+
fi
153+
154+
rm -f "$parity_output"
155+
156+
# Check if any crate has validate: false to override semver mismatch failures
157+
if grep -q "validate:[[:space:]]*false" "$prdoc_file"; then
158+
echo ""
159+
echo "ℹ️ Found crates with 'validate: false' in prdoc. Semver validation failure is overridden."
160+
echo "⚠️ Please ensure the semver override is justified and documented in the PR description."
161+
else
162+
# No validate: false found, fail with error message
163+
cat <<EOF
118164
119-
cat <<EOF
120165
👋 Hello developer! The SemVer information that you declared in the prdoc file did not match what the CI detected.
121166
122167
Please check the output above and see the following links for more help:
@@ -126,7 +171,10 @@ jobs:
126171
Otherwise feel free to ask in the Merge Request or in Matrix chat.
127172
EOF
128173
129-
exit 1
174+
exit 1
175+
fi
176+
else
177+
rm -f "$parity_output"
130178
fi
131179
132180
# Only enforce SemVer restrictions for backports targeting stable branches
@@ -137,7 +185,28 @@ jobs:
137185
138186
echo "🔍 Backport branch detected, checking for disallowed semver changes..."
139187
140-
prdoc_file="prdoc/pr_$PR.prdoc"
188+
# Check for minor/patch bumps with validate: false
189+
if grep -qE "bump:[[:space:]]*(minor|patch)" "$prdoc_file"; then
190+
minor_patch_temp=$(mktemp)
191+
grep -A1 -E "bump:[[:space:]]*(minor|patch)" "$prdoc_file" > "$minor_patch_temp"
192+
193+
has_validate_false=false
194+
while read -r line; do
195+
if [[ "$line" =~ bump:[[:space:]]*(minor|patch) ]]; then
196+
read -r next_line
197+
if [[ "$next_line" =~ validate:[[:space:]]*false ]]; then
198+
has_validate_false=true
199+
break
200+
fi
201+
fi
202+
done < "$minor_patch_temp"
203+
204+
rm -f "$minor_patch_temp"
205+
206+
if [ "$has_validate_false" = true ]; then
207+
echo "ℹ️ Found minor/patch bumps with validate: false override. Semver validation was skipped for these crates by parity-publish."
208+
fi
209+
fi
141210
142211
# Check if there are any major bumps
143212
if ! grep -q "bump:[[:space:]]*major" "$prdoc_file"; then
@@ -149,24 +218,34 @@ jobs:
149218
temp_file=$(mktemp)
150219
grep -A1 "bump:[[:space:]]*major" "$prdoc_file" > "$temp_file"
151220
152-
while read -r line; do
221+
error_found=false
222+
while IFS= read -r line; do
153223
if [[ "$line" =~ bump:[[:space:]]*major ]]; then
154224
# This is the bump line, read the next line
155-
read -r next_line
156-
if [[ "$next_line" =~ validate:[[:space:]]*false ]]; then
157-
continue # This major bump is properly validated
225+
if IFS= read -r next_line; then
226+
if [[ "$next_line" =~ validate:[[:space:]]*false ]]; then
227+
continue # This major bump is properly validated
228+
else
229+
error_found=true
230+
break
231+
fi
158232
else
159-
echo "❌ Error: Found major bump without 'validate: false'"
160-
echo "📘 See: https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/prdoc.md#backporting-prs"
161-
echo "🔧 Add 'validate: false' after the major bump in $prdoc_file with justification."
162-
rm -f "$temp_file"
163-
exit 1
233+
# No next line, means no validate: false
234+
error_found=true
235+
break
164236
fi
165237
fi
166238
done < "$temp_file"
167239
168240
rm -f "$temp_file"
169241
242+
if [ "$error_found" = true ]; then
243+
echo "❌ Error: Found major bump without 'validate: false'"
244+
echo "📘 See: https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/prdoc.md#backporting-prs"
245+
echo "🔧 Add 'validate: false' after the major bump in $prdoc_file with justification."
246+
exit 1
247+
fi
248+
170249
# If we reach here, all major bumps have validate: false
171250
echo "⚠️ Backport contains major bumps, but they are all marked with validate: false."
172251
echo "✅ Semver override accepted. Please ensure justification is documented in the PR description."

0 commit comments

Comments
 (0)