forked from apache/datafusion
-
Notifications
You must be signed in to change notification settings - Fork 0
18660: chore: Add script to protect RC branches during the release #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
martin-augment
wants to merge
2
commits into
main
Choose a base branch
from
pr-18660-2025-11-13-06-56-33
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| #!/usr/bin/env bash | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| set -e | ||
|
|
||
| # Script to add branch protection for a new release branch in .asf.yaml | ||
| # | ||
| # This script automates the process of adding branch protection rules to .asf.yaml | ||
| # for new release branches. It ensures the branch protection block doesn't already | ||
| # exist before adding it. | ||
| # | ||
| # Usage: | ||
| # ./dev/release/add-branch-protection.sh <release_number> | ||
| # | ||
| # Examples: | ||
| # ./dev/release/add-branch-protection.sh 52 | ||
| # ./dev/release/add-branch-protection.sh 53 | ||
| # | ||
| # The script will: | ||
| # 1. Validate the release number is a positive integer | ||
| # 2. Check if branch protection already exists for branch-<release_number> | ||
| # 3. Add the branch protection block to .asf.yaml if it doesn't exist | ||
| # 4. Error out if the block already exists | ||
|
|
||
| # Check if release number is provided | ||
| if [ $# -eq 0 ]; then | ||
| echo "Error: Release number is required" | ||
| echo "Usage: $0 <release_number>" | ||
| echo "Example: $0 52" | ||
| exit 1 | ||
| fi | ||
|
|
||
| RELEASE_NUM=$1 | ||
| BRANCH_NAME="branch-${RELEASE_NUM}" | ||
| ASF_YAML_FILE=".asf.yaml" | ||
|
|
||
| # Validate release number is a positive integer | ||
| if ! [[ "$RELEASE_NUM" =~ ^[0-9]+$ ]]; then | ||
| echo "Error: Release number must be a positive integer" | ||
| echo "Provided: $RELEASE_NUM" | ||
| echo "Example: ./dev/release/add-branch-protection.sh 52" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if .asf.yaml exists | ||
| if [ ! -f "$ASF_YAML_FILE" ]; then | ||
| echo "Error: $ASF_YAML_FILE not found in current directory" | ||
| echo "Please run this script from the repository root" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if the branch exists in the official Apache DataFusion repository | ||
| GITHUB_API_URL="https://api.github.com/repos/apache/datafusion/branches/${BRANCH_NAME}" | ||
| HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$GITHUB_API_URL") | ||
|
|
||
| if [ "$HTTP_STATUS" != "200" ]; then | ||
| echo "Error: Branch ${BRANCH_NAME} does not exist in the official Apache DataFusion repository" | ||
| echo "Please create the branch '${BRANCH_NAME}' first before adding branch protection" | ||
| echo "" | ||
| echo "To check existing branches, visit:" | ||
| echo " https://github.com/apache/datafusion/branches" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if branch protection already exists for this release | ||
| if grep -q "^[[:space:]]*${BRANCH_NAME}:" "$ASF_YAML_FILE"; then | ||
| echo "Error: Branch protection for ${BRANCH_NAME} already exists in $ASF_YAML_FILE" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Create a temporary file | ||
| TEMP_FILE=$(mktemp) | ||
|
|
||
| # Read the file and insert the new branch protection block | ||
| # We'll insert it after the last branch-XX block | ||
| awk -v branch="$BRANCH_NAME" ' | ||
| /^[[:space:]]*branch-[0-9]+:/ { | ||
| last_branch_line = NR | ||
| last_branch_content = $0 | ||
| } | ||
| { | ||
| lines[NR] = $0 | ||
| } | ||
| END { | ||
| if (last_branch_line == 0) { | ||
| print "Error: No existing branch protection blocks found" > "/dev/stderr" | ||
| exit 1 | ||
| } | ||
|
|
||
| # Print all lines up to and including the last branch block | ||
| for (i = 1; i <= last_branch_line; i++) { | ||
| print lines[i] | ||
| } | ||
|
|
||
| # Print the required_pull_request_reviews lines after the last branch | ||
| for (i = last_branch_line + 1; i <= NR; i++) { | ||
| print lines[i] | ||
| # After printing the required_approving_review_count line, insert new branch | ||
| if (lines[i] ~ /required_approving_review_count:/) { | ||
| # Check if this belongs to the last branch block by looking ahead | ||
| next_non_empty = i + 1 | ||
| while (next_non_empty <= NR && lines[next_non_empty] ~ /^[[:space:]]*$/) { | ||
| next_non_empty++ | ||
| } | ||
| # If next non-empty line is not indented more than branch level, we found the end | ||
| if (next_non_empty > NR || lines[next_non_empty] !~ /^[[:space:]]{6,}/) { | ||
| print " " branch ":" | ||
| print " required_pull_request_reviews:" | ||
| print " required_approving_review_count: 1" | ||
| # Skip to next iteration to avoid double printing | ||
| for (j = i + 1; j <= NR; j++) { | ||
| i = j | ||
| if (j <= NR) print lines[j] | ||
| } | ||
| break | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ' "$ASF_YAML_FILE" > "$TEMP_FILE" | ||
|
|
||
| # Check if awk succeeded | ||
| if [ $? -ne 0 ]; then | ||
| rm -f "$TEMP_FILE" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Verify the new content was added | ||
| if ! grep -q "^[[:space:]]*${BRANCH_NAME}:" "$TEMP_FILE"; then | ||
| echo "Error: Failed to add branch protection block" | ||
| rm -f "$TEMP_FILE" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Replace the original file with the modified version | ||
| mv "$TEMP_FILE" "$ASF_YAML_FILE" | ||
|
|
||
| echo "Successfully added branch protection for ${BRANCH_NAME} to $ASF_YAML_FILE" | ||
| echo "" | ||
| echo "Added block:" | ||
| echo " ${BRANCH_NAME}:" | ||
| echo " required_pull_request_reviews:" | ||
| echo " required_approving_review_count: 1" | ||
| echo "" | ||
| echo "Please review the changes and commit them." | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This insertion relies on encountering
required_approving_review_count:and peeking only one line ahead; if additional keys are added under the last branch block after this line, the insertion never triggers and the script exits with “Failed to add branch protection block” (also applies to future YAML layout changes).🤖 Was this useful? React with 👍 or 👎