From d783e164e00ef1a4313a8c55d500fba0710b8b6f Mon Sep 17 00:00:00 2001 From: istarkov Date: Tue, 25 Feb 2025 06:25:04 +0000 Subject: [PATCH 1/4] Add release script --- release.sh | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100755 release.sh diff --git a/release.sh b/release.sh new file mode 100755 index 000000000000..3530aaeaf9a4 --- /dev/null +++ b/release.sh @@ -0,0 +1,116 @@ +#!/bin/bash + +# Function to display error messages and exit +error_exit() { + echo "ERROR: $1" >&2 + exit 1 +} + +# Parse command line arguments +DRY_RUN=false +while getopts "d" opt; do + case $opt in + d) DRY_RUN=true ;; + *) error_exit "Usage: $0 [-d]" ;; + esac +done + +# Function to execute or simulate a command +run_cmd() { + if [ "$DRY_RUN" = true ]; then + echo "DRY RUN: Would execute: $*" + else + echo "Executing: $*" + eval "$@" || error_exit "Command failed: $*" + fi +} + +# Exit immediately if a command exits with a non-zero status (unless in dry run) +if [ "$DRY_RUN" = false ]; then + set -e +fi + +echo "Mode: $([ "$DRY_RUN" = true ] && echo "DRY RUN (no changes will be made)" || echo "LIVE RUN")" + +# 1. Check if on main branch for main repo (process is for debugging) +current_branch=$(git branch --show-current) +if [ "$current_branch" != "main" ] && [ "$current_branch" != "process" ]; then + error_exit "You are not on the main branch. Please switch to main branch first." +fi + +# 2. Check for uncommitted changes or untracked files in main repo +if [ -n "$(git status --porcelain)" ]; then + error_exit "You have uncommitted changes or untracked files. Please commit or stash them first." +fi + +# 3. Prepare release branch name with today's date +today=$(date +"%d-%m-%Y") +release_branch="release-${today}.staging" + +# 4. Check all submodules before making any changes +echo "Verifying all submodules are ready..." + +git submodule foreach --recursive ' + # Check if submodule is on main branch + submodule_branch=$(git branch --show-current) + if [ "$submodule_branch" != "main" ]; then + echo "ERROR: Submodule $name is not on main branch. Current branch: $submodule_branch" >&2 + exit 1 + fi + + # Check for uncommitted changes in submodule + if [ -n "$(git status --porcelain)" ]; then + echo "ERROR: Uncommitted changes in submodule $name." >&2 + exit 1 + fi + + echo "Submodule $name verification passed." +' || error_exit "Submodule verification failed." + +# 5. If we've reached here, all checks passed, now make the changes +echo "All checks passed. Creating release branches..." + +# Create the branch in main repo +echo "Creating release branch in main repository: $release_branch" +run_cmd "git checkout -b \"$release_branch\"" + +# Create an empty commit with release message +commit_date=$(date +"%d-%m-%Y") +run_cmd "git commit --allow-empty -m \"build: Release ${commit_date}\"" + +# 6. Create branches in all submodules and push them +echo "Creating and pushing branches in submodules..." + +# Create a function for submodule operations that supports dry run +submodule_operations() { + local dry_run="$1" + local release_br="$2" + + # Create the same branch in the submodule + if [ "$dry_run" = true ]; then + echo "DRY RUN: Would execute in submodule $name: git checkout -b $release_br" + echo "DRY RUN: Would execute in submodule $name: git push -u origin $release_br" + else + git checkout -b "$release_br" || { echo "ERROR: Failed to create branch in submodule $name." >&2; exit 1; } + git push -u origin "$release_br" || { echo "ERROR: Failed to push branch for submodule $name." >&2; exit 1; } + fi + echo "$([ "$dry_run" = true ] && echo "DRY RUN: Would have" || echo "Successfully") created and pushed branch for submodule $name" +} + +# Export the function and variables so they can be used in submodule foreach +export -f submodule_operations +export DRY_RUN +export release_branch + +git submodule foreach --recursive "submodule_operations \"$DRY_RUN\" \"$release_branch\"" + +# 7. Success message +echo "" +if [ "$DRY_RUN" = true ]; then + echo "DRY RUN COMPLETE. No changes were made." + echo "To create the release branch for real, run without the -d flag." +else + echo "Success! Release branch $release_branch is ready." + echo "You can now push it to the remote with:" + echo "git push -u origin $release_branch" +fi From 8acebb5e9086657dde53da72c83e3bf707d80e26 Mon Sep 17 00:00:00 2001 From: istarkov Date: Tue, 25 Feb 2025 06:29:28 +0000 Subject: [PATCH 2/4] Try fix --- release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.sh b/release.sh index 3530aaeaf9a4..665e2903e048 100755 --- a/release.sh +++ b/release.sh @@ -102,7 +102,7 @@ export -f submodule_operations export DRY_RUN export release_branch -git submodule foreach --recursive "submodule_operations \"$DRY_RUN\" \"$release_branch\"" +git submodule foreach --recursive 'bash -c "submodule_operations \"$DRY_RUN\" \"$release_branch\""' # 7. Success message echo "" From 427f467f498584ae18c0f7bf76fac36b652d84fc Mon Sep 17 00:00:00 2001 From: istarkov Date: Tue, 25 Feb 2025 06:33:06 +0000 Subject: [PATCH 3/4] Fix --- release.sh | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/release.sh b/release.sh index 665e2903e048..4f164373b15b 100755 --- a/release.sh +++ b/release.sh @@ -35,7 +35,7 @@ echo "Mode: $([ "$DRY_RUN" = true ] && echo "DRY RUN (no changes will be made)" # 1. Check if on main branch for main repo (process is for debugging) current_branch=$(git branch --show-current) if [ "$current_branch" != "main" ] && [ "$current_branch" != "process" ]; then - error_exit "You are not on the main branch. Please switch to main branch first." + error_exit "You are not on the main or master branch. Please switch to main or master branch first." fi # 2. Check for uncommitted changes or untracked files in main repo @@ -51,10 +51,10 @@ release_branch="release-${today}.staging" echo "Verifying all submodules are ready..." git submodule foreach --recursive ' - # Check if submodule is on main branch + # Check if submodule is on main or master branch submodule_branch=$(git branch --show-current) - if [ "$submodule_branch" != "main" ]; then - echo "ERROR: Submodule $name is not on main branch. Current branch: $submodule_branch" >&2 + if [ "$submodule_branch" != "main" ] && [ "$submodule_branch" != "master" ]; then + echo "ERROR: Submodule $name is not on main or master branch. Current branch: $submodule_branch" >&2 exit 1 fi @@ -81,28 +81,18 @@ run_cmd "git commit --allow-empty -m \"build: Release ${commit_date}\"" # 6. Create branches in all submodules and push them echo "Creating and pushing branches in submodules..." -# Create a function for submodule operations that supports dry run -submodule_operations() { - local dry_run="$1" - local release_br="$2" - - # Create the same branch in the submodule - if [ "$dry_run" = true ]; then - echo "DRY RUN: Would execute in submodule $name: git checkout -b $release_br" - echo "DRY RUN: Would execute in submodule $name: git push -u origin $release_br" - else - git checkout -b "$release_br" || { echo "ERROR: Failed to create branch in submodule $name." >&2; exit 1; } - git push -u origin "$release_br" || { echo "ERROR: Failed to push branch for submodule $name." >&2; exit 1; } - fi - echo "$([ "$dry_run" = true ] && echo "DRY RUN: Would have" || echo "Successfully") created and pushed branch for submodule $name" -} - -# Export the function and variables so they can be used in submodule foreach -export -f submodule_operations -export DRY_RUN -export release_branch - -git submodule foreach --recursive 'bash -c "submodule_operations \"$DRY_RUN\" \"$release_branch\""' +# Instead of using a function, directly execute commands in each submodule +if [ "$DRY_RUN" = true ]; then + git submodule foreach --recursive "echo \"DRY RUN: Would execute in submodule \$name: git checkout -b $release_branch\"" + git submodule foreach --recursive "echo \"DRY RUN: Would execute in submodule \$name: git push -u origin $release_branch\"" + git submodule foreach --recursive "echo \"DRY RUN: Would have created and pushed branch for submodule \$name\"" +else + git submodule foreach --recursive " + git checkout -b \"$release_branch\" || { echo \"ERROR: Failed to create branch in submodule \$name.\" >&2; exit 1; } + git push -u origin \"$release_branch\" || { echo \"ERROR: Failed to push branch for submodule \$name.\" >&2; exit 1; } + echo \"Successfully created and pushed branch for submodule \$name\" + " || error_exit "Failed to create or push branches in one or more submodules." +fi # 7. Success message echo "" @@ -113,4 +103,4 @@ else echo "Success! Release branch $release_branch is ready." echo "You can now push it to the remote with:" echo "git push -u origin $release_branch" -fi +fi \ No newline at end of file From 59ee68049890eff965e77eec1e83b8e5ebd05fa3 Mon Sep 17 00:00:00 2001 From: istarkov Date: Tue, 25 Feb 2025 06:35:28 +0000 Subject: [PATCH 4/4] Fix release.sh --- release.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/release.sh b/release.sh index 4f164373b15b..719adddeb1ec 100755 --- a/release.sh +++ b/release.sh @@ -1,5 +1,33 @@ #!/bin/bash +# +# Release Branch Creator Script +# ----------------------------- +# +# DESCRIPTION: +# This script automates the process of creating release branches in a Git repository +# with submodules. It creates a release branch with the current date in the format +# 'release-DD-MM-YYYY.staging' in both the main repository and all its submodules. +# +# FEATURES: +# - Verifies you're on main/master branch before proceeding +# - Checks for uncommitted changes in main repo and submodules +# - Creates a release branch with today's date +# - Creates an empty commit in the main repo with message "build: Release DD-MM-YYYY" +# - Creates matching branches in all submodules +# - Pushes submodule branches to their remotes +# - Provides a dry run mode (-d flag) to preview actions without making changes +# +# USAGE: +# ./release-branch-script.sh # Create and push release branches +# ./release-branch-script.sh -d # Dry run (show what would happen without making changes) +# +# REQUIREMENTS: +# - All repositories (main and submodules) must be on main/master branch +# - No uncommitted changes anywhere +# - Git must be installed and properly configured +# + # Function to display error messages and exit error_exit() { echo "ERROR: $1" >&2