From 4bc2d096417881ae462cc8d202a48ffd62e0dd62 Mon Sep 17 00:00:00 2001 From: Alexander Goscinski Date: Thu, 1 May 2025 10:52:05 +0200 Subject: [PATCH] Add tools for minor release --- utils/minor-release.sh | 64 ++++++++++++++++++++++++++++++++++++++++++ utils/patch-release.sh | 6 ++-- 2 files changed, 67 insertions(+), 3 deletions(-) create mode 100755 utils/minor-release.sh diff --git a/utils/minor-release.sh b/utils/minor-release.sh new file mode 100755 index 0000000000..1e55551354 --- /dev/null +++ b/utils/minor-release.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# Script: patch-release.sh +# Description: +# Cherry-picks a list of commits, amends each with the original commit hash for tracking, +# and generates a summary from the short github commit messages with links to each commit. +# +# Usage: +# ./patch-release.sh ... +# +# Example: +# ./patch-release.sh abc1234 def5678 + +set -e + +# Check if at least two arguments are provided (repo and at least one commit) +if [ "$#" -lt 1 ]; then + echo "Usage: $0 ..." + echo "Example: $0 abc1234 def5678" + exit 1 +fi + +GITHUB_REPO="aiidateam/aiida-core" + +# Create an array to store commit summaries +declare -a commit_summaries=() +commit_list=$(git rev-list "$1"..HEAD) + +commits=() +while IFS= read -r line; do + commits+=("$line") +done <<< "$commit_list" + + + +# Loop through each commit hash +for commit in "${commits[@]}"; do + # Cherry-pick the commit + if git cat-file -t "$commit"; then + # If cherry-pick succeeds, get the short message and short hash + commit_message=$(git log -1 --pretty=format:"%B" $commit) + original_short_hash=$(git log -1 --pretty=format:"%h" "$commit") + original_long_hash=$(git rev-parse $original_short_hash) + + # Amend the cherry-picked commit to include the original commit ID for tracking + #git commit --amend -m "$commit_message" -m "Cherry-pick: $original_long_hash" + + # Format the output as a Markdown list item and add to the array + short_commit_message=$(git log -1 --pretty=format:"%s" $commit) + cherry_picked_hash=$(git log -1 --pretty=format:"%h" $commit) + commit_summaries+=("- $short_commit_message [[${commit}]](https://github.com/$GITHUB_REPO/commit/${original_long_hash})") + else + echo "Failed to cherry-pick commit $commit" + # Abort the cherry-pick in case of conflict + git cherry-pick --abort + exit 1 + fi +done + +# Print the summary +echo -e "\n### Cherry-Picked Commits Summary:\n" +for summary in "${commit_summaries[@]}"; do + echo "$summary" +done diff --git a/utils/patch-release.sh b/utils/patch-release.sh index a9d67bee79..5b2a896a57 100755 --- a/utils/patch-release.sh +++ b/utils/patch-release.sh @@ -30,7 +30,7 @@ for commit in "$@"; do # Cherry-pick the commit if git cherry-pick "$commit"; then # If cherry-pick succeeds, get the short message and short hash - commit_message=$(git log -1 --pretty=format:"%B" HEAD) + commit_message=$(git log -1 --pretty=format:"%B" $commit) original_short_hash=$(git log -1 --pretty=format:"%h" "$commit") original_long_hash=$(git rev-parse $original_short_hash) @@ -38,8 +38,8 @@ for commit in "$@"; do git commit --amend -m "$commit_message" -m "Cherry-pick: $original_long_hash" # Format the output as a Markdown list item and add to the array - short_commit_message=$(git log -1 --pretty=format:"%s" HEAD) - cherry_picked_hash=$(git log -1 --pretty=format:"%h" HEAD) + short_commit_message=$(git log -1 --pretty=format:"%s" $commit) + cherry_picked_hash=$(git log -1 --pretty=format:"%h" $commit) commit_summaries+=("- $short_commit_message [[${commit}]](https://github.com/$GITHUB_REPO/commit/${original_long_hash})") else echo "Failed to cherry-pick commit $commit"