Skip to content

Aggregating code snippets output branches #154

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
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions scripts/code_snippets/cherry_pick_snippet_updates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

set -eou pipefail

release_branch="$1"
if [[ -z "${release_branch}" ]]; then
echo "Usage: $0 <release-branch>"
exit 1
fi
current_date=$(date "+%Y%m%d")s
branch_pattern="origin/mck-snippets-update-${current_date}*"
new_branch_name="mck-snippets-update-cherry-picked-${current_date}-$(date "+%H%M%S")"

echo "Fetching from origin..."
git fetch origin

echo "Looking for branches matching '${branch_pattern}'..."
branches_to_pick=()
while IFS= read -r line; do
branches_to_pick+=("$line")
done < <(git branch -r --list "${branch_pattern}" | sed 's/^[[:space:]]*//')

if [[ ${#branches_to_pick[@]} -eq 0 ]]; then
echo "No branches found matching '${branch_pattern}'. Exiting."
exit 0
fi

echo "Found branches to cherry-pick:"
printf " %s\n" "${branches_to_pick[@]}"

echo "Creating new branch '${new_branch_name}' from 'origin/${release_branch}'..."
git checkout -b "${new_branch_name}" "origin/${release_branch}"

echo "Cherry-picking commits..."
for branch in "${branches_to_pick[@]}"; do
echo " Picking from ${branch}..."
git cherry-pick "${branch}" || true

# automatically resolve cherry-pick conflicts by taking whatever it is in the cherry-picked commit
# in case there are no conflicts, this will do nothing
git status --porcelain | grep "^UU" | awk '{print $2}' | xargs -I {} git checkout --theirs {} || true
git status --porcelain | grep "^UU" | awk '{print $2}' | xargs -I {} git add {} || true
# || true for ignoring errors if there are no conflicts
git cherry-pick --continue || true
done

echo "New branch '${new_branch_name}' created with cherry-picked commits."
echo "Push with: git push origin ${new_branch_name}"
2 changes: 1 addition & 1 deletion scripts/code_snippets/sample_commit_output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source scripts/dev/set_env_context.sh

if [ "${COMMIT_OUTPUT:-false}" = true ]; then
echo "Pushing output files"
branch="meko-snippets-update-$(date "+%Y%m%d%H%M%S")"
branch="mck-snippets-update-$(date "+%Y%m%d%H%M%S")"
git checkout -b "${branch}"
git reset
git add public/architectures/**/*.out
Expand Down