diff --git a/scripts/create-adaptation-pr.sh b/scripts/create-adaptation-pr.sh index 08db7705144c9..2e7d69f7916d8 100755 --- a/scripts/create-adaptation-pr.sh +++ b/scripts/create-adaptation-pr.sh @@ -14,15 +14,52 @@ set -e # abort whenever a command in the script fails # So please do not delete the following line, or the final two lines of this script. { -if [ $# -ne 2 ]; then +# Default values +AUTO="no" + +# Function to display usage +usage() { echo "Usage: $0 " + echo " or" + echo " $0 --bumpversion= --nightlydate= [--auto=]" echo "BUMPVERSION: The upcoming release that we are targeting, e.g., 'v4.10.0'" echo "NIGHTLYDATE: The date of the nightly toolchain currently used on 'nightly-testing'" + echo "AUTO: Optional flag to specify automatic mode, default is 'no'" exit 1 +} + +# Parse arguments +if [ $# -eq 2 ] && [[ $1 != --* ]] && [[ $2 != --* ]]; then + BUMPVERSION=$1 + NIGHTLYDATE=$2 +elif [ $# -ge 2 ]; then + for arg in "$@"; do + case $arg in + --bumpversion=*) + BUMPVERSION="${arg#*=}" + shift + ;; + --nightlydate=*) + NIGHTLYDATE="${arg#*=}" + shift + ;; + --auto=*) + AUTO="${arg#*=}" + shift + ;; + *) + usage + ;; + esac + done +else + usage fi -BUMPVERSION=$1 # "v4.10.0" -NIGHTLYDATE=$2 # "2024-06-25" +# Validate required arguments +if [ -z "$BUMPVERSION" ] || [ -z "$NIGHTLYDATE" ]; then + usage +fi # Check if 'gh' command is available if ! command -v gh &> /dev/null; then @@ -38,8 +75,13 @@ if [ "$status" != "completed" ]; then gh run list --branch nightly-testing exit 1 else - echo "The latest commit on 'nightly-testing' is still running CI." - read -p "Press enter to continue, or ctrl-C if you'd prefer to wait for CI." + if [ "$AUTO" = "yes" ]; then + echo "Auto mode enabled. Bailing out because the latest commit on 'nightly-testing' is still running CI." + exit 1 + else + echo "The latest commit on 'nightly-testing' is still running CI." + read -p "Press enter to continue, or ctrl-C if you'd prefer to wait for CI." + fi fi fi @@ -79,6 +121,13 @@ if git diff --name-only --diff-filter=U | grep -q .; then fi fi +if git diff --name-only --diff-filter=U | grep -q . || ! git diff-index --quiet HEAD --; then + if [ "$AUTO" = "yes" ]; then + echo "Auto mode enabled. Bailing out due to unresolved conflicts or uncommitted changes." + exit 1 + fi +fi + # Loop until all conflicts are resolved and committed while git diff --name-only --diff-filter=U | grep -q . || ! git diff-index --quiet HEAD --; do echo @@ -111,6 +160,13 @@ if git diff --name-only --diff-filter=U | grep -q .; then git add lean-toolchain lake-manifest.json fi +if git diff --name-only --diff-filter=U | grep -q .; then + if [ "$AUTO" = "yes" ]; then + echo "Auto mode enabled. Bailing out due to unresolved conflicts or uncommitted changes." + exit 1 + fi +fi + # Check if there are more merge conflicts if git diff --name-only --diff-filter=U | grep -q .; then echo @@ -143,8 +199,13 @@ if git diff --name-only bump/$BUMPVERSION bump/nightly-$NIGHTLYDATE | grep -q .; echo "Here is a suggested 'gh' command to do this:" gh_command="gh pr create -t \"$pr_title\" -b '' -B bump/$BUMPVERSION" echo "> $gh_command" - echo "Shall I run this command for you? (y/n)" - read answer + if [ "$AUTO" = "yes" ]; then + echo "Auto mode enabled. Running the command..." + answer="y" + else + echo "Shall I run this command for you? (y/n)" + read answer + fi if [ "$answer" != "${answer#[Yy]}" ]; then gh_output=$(eval $gh_command) # Extract the PR number from the output @@ -152,7 +213,7 @@ if git diff --name-only bump/$BUMPVERSION bump/nightly-$NIGHTLYDATE | grep -q .; fi echo - echo "### [user] post a link to the PR on Zulip" + echo "### [auto/user] post a link to the PR on Zulip" zulip_title="#$pr_number adaptations for nightly-$NIGHTLYDATE" zulip_body="> $pr_title #$pr_number" @@ -161,7 +222,33 @@ if git diff --name-only bump/$BUMPVERSION bump/nightly-$NIGHTLYDATE | grep -q .; echo "Here is a suggested message:" echo "Title: $zulip_title" echo " Body: $zulip_body" - read -p "Press enter to continue" + + if command -v zulip-send >/dev/null 2>&1; then + zulip_command="zulip-send --stream nightly-testing --subject \"$zulip_title\" --message \"$zulip_body\"" + echo "Here is a suggested 'zulip-send' command to do this:" + echo "> $zulip_command" + + if [ "$AUTO" = "yes" ]; then + echo "Auto mode enabled. Running the command..." + answer="y" + else + echo "Shall I run this command for you? (y/n)" + read answer + fi + + if [ "$answer" != "${answer#[Yy]}" ]; then + eval $zulip_command + fi + else + echo "Zulip CLI is not installed. Please install it to send messages automatically." + if [ "$AUTO" = "yes" ]; then + exit 1 + fi + fi + + if [ "$AUTO" != "yes" ]; then + read -p "Press enter to continue" + fi # else, let the user know that no PR is needed else @@ -195,6 +282,15 @@ if git diff --name-only --diff-filter=U | grep -q .; then fi fi +if git diff --name-only --diff-filter=U | grep -q . || ! git diff-index --quiet HEAD --; then + if [ "$AUTO" = "yes" ]; then + echo "Auto mode enabled. Bailing out due to unresolved conflicts or uncommitted changes." + echo "PR has been created, and message posted to Zulip." + echo "Error occured while merging the new branch into 'nightly-testing'." + exit 2 + fi +fi + # Loop until all conflicts are resolved and committed while git diff --name-only --diff-filter=U | grep -q . || ! git diff-index --quiet HEAD --; do echo