Adding theoretical main variation (#17904)

This commit is contained in:
George Karr 2024-04-02 13:26:31 -05:00 committed by GitHub
parent 8a22f13f53
commit 011d97fad1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,14 +45,14 @@
# :;::,
#
#
# /$$$$$$$$ /$$ /$$$$$$$$ /$$$$$$$$ /$$$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$$$ /$$$$$$ /$$ /$$
# | $$_____/| $$ | $$_____/| $$_____/|__ $$__/ | $$__ $$ /$$__ $$|__ $$__//$$__ $$| $$ | $$
# | $$ | $$ | $$ | $$ | $$ | $$ \ $$| $$ \ $$ | $$ | $$ \__/| $$ | $$
# | $$$$$ | $$ | $$$$$ | $$$$$ | $$ | $$$$$$$/| $$$$$$$$ | $$ | $$ | $$$$$$$$
# | $$__/ | $$ | $$__/ | $$__/ | $$ | $$____/ | $$__ $$ | $$ | $$ | $$__ $$
# | $$ | $$ | $$ | $$ | $$ | $$ | $$ | $$ | $$ | $$ $$| $$ | $$
# | $$ | $$$$$$$$| $$$$$$$$| $$$$$$$$ | $$ | $$ | $$ | $$ | $$ | $$$$$$/| $$ | $$
# |__/ |________/|________/|________/ |__/ |__/ |__/ |__/ |__/ \______/ |__/ |__/
# /$$$$$$$$ /$$ /$$$$$$$$ /$$$$$$$$ /$$$$$$$$
# | $$_____/| $$ | $$_____/| $$_____/|__ $$__/
# | $$ | $$ | $$ | $$ | $$
# | $$$$$ | $$ | $$$$$ | $$$$$ | $$
# | $$__/ | $$ | $$__/ | $$__/ | $$
# | $$ | $$ | $$ | $$ | $$
# | $$ | $$$$$$$$| $$$$$$$$| $$$$$$$$ | $$
# |__/ |________/|________/|________/ |__/
#
# /$$$$$$$ /$$$$$$$$ /$$ /$$$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$$ /$$$$$$$
# | $$__ $$| $$_____/| $$ | $$_____/ /$$__ $$ /$$__ $$| $$_____/| $$__ $$
@ -68,6 +68,7 @@ usage() {
echo "Usage: $0 [options] (optional|start_version)"
echo ""
echo "Options:"
echo " -a, --main_release This is a release based off of main and not a tagged patch."
echo " -c, --cherry_pick_resolved The script has been run, had merge conflicts, and those have been resolved and all cherry picks completed manually."
echo " -d, --dry_run Perform a trial run with no changes made"
echo " -f, --force Skip all confirmations"
@ -83,6 +84,9 @@ usage() {
echo ""
echo "Environment Variables:"
echo " OPEN_API_KEY Open API key used for fallback if not provided via -o or --open-api-key option"
echo " SLACK_GENERAL_TOKEN Slack token to publish via curl to #general"
echo " SLACK_HELP_INFRA_TOKEN Slack token to publish via curl to #help-infrastructure"
echo " SLACK_HELP_ENG_TOKEN Slack token to publish via curl to #help-engineering"
echo ""
echo "Examples:"
echo " $0 -d Dry run the script"
@ -176,14 +180,22 @@ validate_and_format_date() {
}
print_announce_info() {
qa_ticket=`gh issue list --search "Release QA: $target_milestone in:title" --json url | jq -r .[0].url`
docker_deploy=`gh run list --workflow goreleaser-snapshot-fleet.yaml --json event,url,headBranch --limit 100 | jq -r "[.[]|select(.headBranch==\"$target_patch_branch\")][0].url"`
echo
echo "For announcing in #help-engineering"
echo "===================================================="
echo "Release $target_milestone QA ticket and docker publish"
echo "QA ticket for Release $target_milestone " `gh issue list --search "Release QA: $target_milestone in:title" --json url | jq -r .[0].url`
echo "Docker Deploy status " `gh run list --workflow goreleaser-snapshot-fleet.yaml --json event,url,headBranch --limit 100 | jq -r "[.[]|select(.headBranch==\"$target_patch_branch\")][0].url"`
echo "QA ticket for Release $target_milestone " $qa_ticket
echo "Docker Deploy status " $docker_deploy
echo "List of tickets pulled into release https://github.com/fleetdm/fleet/milestone/$target_milestone_number"
echo
slack_hook_url=https://hooks.slack.com/services
app_id=T019PP37ALW
announce_text="Release $target_milestone QA ticket and docker publish\nQA ticket for Release $target_milestone $qa_ticket\nDocker Deploy status $docker_deploy\nList of tickets pulled into release https://github.com/fleetdm/fleet/milestone/$target_milestone_number"
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\":\"$announce_text\"}" \
$slack_hook_url/$app_id/$SLACK_HELP_ENG_TOKEN
}
update_release_notes() {
@ -242,18 +254,15 @@ publish() {
# Slack
slack_hook_url=https://hooks.slack.com/services
app_id=T019PP37ALW
general_channel_id=B06RZ60NUHX/tzaDZOvFCSvS2HC6rECi3Mvu
help_infra_channel_id=B06RLDFLC75/biuacbLxWRsDhv0hLA2qnLbX
help_eng_channel_id=B06RDTMUP1U/x2R36PXvW13KE6daxMiUK6W7
announce_text=":cloud: :rocket: The latest version of Fleet is $target_milestone.\nMore info: https://github.com/fleetdm/fleet/releases/tag/$next_tag\nUpgrade now: https://fleetdm.com/docs/deploying/upgrading-fleet"
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\":\"$announce_text\"}" \
$slack_hook_url/$app_id/$general_channel_id
$slack_hook_url/$app_id/$SLACK_GENERAL_TOKEN
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\":\"$announce_text\nDogfood Deployed $dogfood_deploy\"}" \
$slack_hook_url/$app_id/$help_infra_channel_id
$slack_hook_url/$app_id/$SLACK_HELP_INFRA_TOKEN
}
# Validate we have all commands required to perform this script
@ -271,11 +280,13 @@ target_version=""
print_info=false
publish_release=false
release_notes=false
main_release=false
# Parse long options manually
for arg in "$@"; do
shift
case "$arg" in
"--main_release") set -- "$@" "-a" ;;
"--cherry_pick_resolved") set -- "$@" "-c" ;;
"--dry-run") set -- "$@" "-d" ;;
"--force") set -- "$@" "-f" ;;
@ -293,8 +304,9 @@ for arg in "$@"; do
done
# Extract options and their arguments using getopts
while getopts "cdfhmo:prs:t:uv:" opt; do
while getopts "acdfhmo:prs:t:uv:" opt; do
case "$opt" in
a) main_release=true ;;
c) cherry_pick_resolved=true ;;
d) dry_run=true ;;
f) force=true ;;
@ -345,6 +357,19 @@ if [ -z "$open_api_key" ]; then
fi
fi
if [ -n "$SLACK_GENERAL_TOKEN" ]; then
echo "Error: No SLACK_GENERAL_TOKEN environment variable." >&2
exit 1
fi
if [ -n "$SLACK_HELP_INFRA_TOKEN" ]; then
echo "Error: No SLACK_HELP_INFRA_TOKEN environment variable." >&2
exit 1
fi
if [ -n "$SLACK_HELP_ENG_TOKEN" ]; then
echo "Error: No SLACK_HELP_ENG_TOKEN environment variable." >&2
exit 1
fi
if [[ "$target_date" != "" ]]; then
validate_and_format_date $target_date
fi
@ -384,7 +409,13 @@ fi
start_ver_tag=fleet-$start_version
echo "Patch release from $start_version to $next_ver"
if [[ "$main_release" == "true" ]]; then
echo "Main release from $start_version to $next_ver"
start_ver_tag=main
else
echo "Patch release from $start_version to $next_ver"
fi
if [ "$force" = "false" ]; then
read -r -p "If this is correct confirm yes to continue? [y/N] " response
case "$response" in
@ -404,6 +435,10 @@ target_milestone="${next_ver:1}"
target_milestone_number=`gh api repos/:owner/:repo/milestones | jq -r ".[] | select(.title==\"$target_milestone\") | .number"`
# patch-fleet-v4.47.3
target_patch_branch="patch-fleet-$next_ver"
if [[ "$main_release" == "true" ]]; then
target_patch_branch="prepare-fleet-$next_ver"
fi
# fleet-v4.47.3
next_tag="fleet-$next_ver"
@ -438,6 +473,7 @@ if [ "$cherry_pick_resolved" = "false" ]; then
# TODO Fail if not found
if [ "$dry_run" = "false" ]; then
git checkout $start_ver_tag
git pull origin $start_ver_tag
else
echo "DRYRUN: Would have checked out starting tag $start_ver_tag"
fi
@ -494,67 +530,69 @@ if [ "$cherry_pick_resolved" = "false" ]; then
commits=""
for pr in ${total_prs[*]};
do
output=`gh pr view $pr --json state,mergeCommit,baseRefName`
state=`echo $output | jq -r .state`
commit=`echo $output | jq -r .mergeCommit.oid`
target_branch=`echo $output | jq -r .baseRefName`
echo -n "$pr $state $commit $target_branch:"
if [[ "$state" != "MERGED" || "$target_branch" != "main" ]]; then
echo " WARNING - Skipping pr https://github.com/fleetdm/fleet/pull/$pr"
else
if [[ "$commit" != "" && "$commit" != "null" ]]; then
echo " Commit looks valid - $commit, adding to cherry-pick"
commits+="$commit "
if [[ "$main_release" == "false" ]]; then
for pr in ${total_prs[*]};
do
output=`gh pr view $pr --json state,mergeCommit,baseRefName`
state=`echo $output | jq -r .state`
commit=`echo $output | jq -r .mergeCommit.oid`
target_branch=`echo $output | jq -r .baseRefName`
echo -n "$pr $state $commit $target_branch:"
if [[ "$state" != "MERGED" || "$target_branch" != "main" ]]; then
echo " WARNING - Skipping pr https://github.com/fleetdm/fleet/pull/$pr"
else
echo " WARNING - invalid commit for pr https://github.com/fleetdm/fleet/pull/$pr - $commit"
if [[ "$commit" != "" && "$commit" != "null" ]]; then
echo " Commit looks valid - $commit, adding to cherry-pick"
commits+="$commit "
else
echo " WARNING - invalid commit for pr https://github.com/fleetdm/fleet/pull/$pr - $commit"
fi
fi
fi
#echo "======================================="
done
#echo "======================================="
done
for commit in $commits;
do
# echo $commit
timestamp=`git log -n 1 --pretty=format:%at $commit`
if [ $? -ne 0 ]; then
echo "Failed to identify $commit, exiting"
exit 1
fi
# echo $timestamp
time_map[$timestamp]=$commit
done
for commit in $commits;
do
# echo $commit
timestamp=`git log -n 1 --pretty=format:%at $commit`
if [ $? -ne 0 ]; then
echo "Failed to identify $commit, exiting"
exit 1
fi
# echo $timestamp
time_map[$timestamp]=$commit
done
timestamps=""
for key in "${!time_map[@]}"; do
timestamps+="$key\n"
done
for ts in `echo -e $timestamps | sort`; do
commit_hash="${time_map[$ts]}"
# echo "# $ts $commit_hash"
if git branch --contains "$commit_hash" | $GREP_CMD -q "$(git rev-parse --abbrev-ref HEAD)"; then
echo "# Commit $commit_hash is on the current branch."
is_on_current_branch=true
else
# echo "# Commit $commit_hash is not on the current branch."
if [[ "$failed" == "false" ]]; then
timestamps=""
for key in "${!time_map[@]}"; do
timestamps+="$key\n"
done
for ts in `echo -e $timestamps | sort`; do
commit_hash="${time_map[$ts]}"
# echo "# $ts $commit_hash"
if git branch --contains "$commit_hash" | $GREP_CMD -q "$(git rev-parse --abbrev-ref HEAD)"; then
echo "# Commit $commit_hash is on the current branch."
is_on_current_branch=true
else
# echo "# Commit $commit_hash is not on the current branch."
if [[ "$failed" == "false" ]]; then
if [ "$dry_run" = "false" ]; then
git cherry-pick $commit_hash
if [ $? -ne 0 ]; then
echo "Cherry pick of $commit_hash failed. Please resolve then continue the cherry-picks manually"
failed=true
if [ "$dry_run" = "false" ]; then
git cherry-pick $commit_hash
if [ $? -ne 0 ]; then
echo "Cherry pick of $commit_hash failed. Please resolve then continue the cherry-picks manually"
failed=true
fi
else
echo "DRYRUN: Would have cherry picked $commit_hash"
fi
else
echo "DRYRUN: Would have cherry picked $commit_hash"
echo "git cherry-pick $commit_hash"
fi
else
echo "git cherry-pick $commit_hash"
is_on_current_branch=false
fi
is_on_current_branch=false
fi
done
done
fi
fi
if [[ "$failed" == "false" ]]; then