Skip to content

Commit

Permalink
ci: fix diff branch creation logic (#3726)
Browse files Browse the repository at this point in the history
* ci: fix diff branch creation logic

* ci: update origin config

* ci: create old ref branch if not exists

* ci: ignore error in code block
  • Loading branch information
krtk6160 authored Dec 20, 2023
1 parent e010ac0 commit 9ed020c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 46 deletions.
44 changes: 21 additions & 23 deletions ci/apps/tasks/open-charts-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,41 @@ gh auth setup-git
# switch to https to use the token
git remote set-url origin ${github_url}

git checkout ${old_ref}
app_src_files=($(buck2 uquery 'inputs(deps("'"//apps/${APP}:"'"))' 2>/dev/null))

# create a branch with the old state of the app
git checkout --orphan ${APP}-${old_ref}
git rm -rf . > /dev/null
for file in "${app_src_files[@]}"; do
git checkout "$old_ref" -- "$file"
done
git commit -m "Commit state of \`${APP}\` at \`${old_ref}\`"
git push -fu origin ${APP}-${old_ref}
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

# create a branch from the old state
git branch ${APP}-${ref}
git checkout ${ref}
app_src_files=($(buck2 uquery 'inputs(deps("'"//apps/${APP}:"'"))' 2>/dev/null))

# commit the new state of the app
git checkout ${APP}-${ref}
# create a branch from the old state and commit the new state of the app
set +e
git fetch origin ${APP}-${old_ref}
# if the above exits with 128, it means the branch doesn't exist yet
if [[ $? -eq 128 ]]; then
git checkout --orphan ${APP}-${old_ref}
git rm -rf . > /dev/null
for file in "${app_src_files[@]}"; do
git checkout "$old_ref" -- "$file"
done
git commit -m "Commit state of \`${APP}\` at \`${old_ref}\`"
git push -fu origin ${APP}-${old_ref}
fi
set -e

git checkout ${APP}-${old_ref}
git checkout -b ${APP}-${ref}
for file in "${app_src_files[@]}"; do
git checkout "$ref" -- "$file"
done

if [[ $(git status --porcelain -u no) != '' ]]; then
git commit -m "Commit state of \`core\` at \`${ref}\`"
git push -fu origin ${APP}-${ref}
github_diff_url="${github_url}/compare/${app}-${old_ref}...${app}-${ref}"
else
github_diff_url="${github_url}/compare/${old_ref}...${ref}"
fi
git commit -m "Commit state of \`${APP}\` at \`${ref}\`" --allow-empty
git push -fu origin ${APP}-${ref}

cat <<EOF >> ../body.md
# Bump ${APP} image
Code diff contained in this image:
${github_diff_url}
${github_url}/compare/${APP}-${old_ref}...${APP}-${ref}
The ${APP} image will be bumped to digest:
\`\`\`
Expand Down
45 changes: 22 additions & 23 deletions ci/tasks/open-charts-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ git checkout ${BRANCH}
old_ref=$(yq e '.galoy.images.app.git_ref' charts/galoy/values.yaml)

pushd ../repo

if [[ -z $(git config --global user.email) ]]; then
git config --global user.email "[email protected]"
fi
Expand All @@ -30,43 +31,41 @@ gh auth setup-git
# switch to https to use the token
git remote set-url origin ${github_url}

git checkout ${old_ref}
app_src_files=($(buck2 uquery 'inputs(deps("//core/..."))' 2>/dev/null))

# create a branch with the old state of core
git checkout --orphan core-${old_ref}
git rm -rf . > /dev/null
for file in "${app_src_files[@]}"; do
git checkout "$old_ref" -- "$file"
done
git commit -m "Commit state of \`core\` at \`${old_ref}\`"
git push -fu origin core-${old_ref}
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

# create a branch from the old state
git branch core-${ref}
git checkout ${ref}
app_src_files=($(buck2 uquery 'inputs(deps("//core/..."))' 2>/dev/null))

# commit the new state of core
git checkout core-${ref}
# create a branch from the old state and commit the new state of core
set +e
git fetch origin core-${old_ref}
# if the above exits with 128, it means the branch doesn't exist yet
if [[ $? -eq 128 ]]; then
git checkout --orphan core-${old_ref}
git rm -rf . > /dev/null
for file in "${app_src_files[@]}"; do
git checkout "$old_ref" -- "$file"
done
git commit -m "Commit state of \`core\` at \`${old_ref}\`"
git push -fu origin core-${old_ref}
fi
set -e

git checkout core-${old_ref}
git checkout -b core-${ref}
for file in "${app_src_files[@]}"; do
git checkout "$ref" -- "$file"
done

if [[ $(git status --porcelain -u no) != '' ]]; then
git commit -m "Commit state of \`core\` at \`${ref}\`"
git push -fu origin core-${ref}
github_diff_url="${github_url}/compare/core-${old_ref}...core-${ref}"
else
github_diff_url="${github_url}/compare/${old_ref}...${ref}"
fi
git commit -m "Commit state of \`core\` at \`${ref}\`" --allow-empty
git push -fu origin core-${ref}

cat <<EOF >> ../body.md
# Bump galoy image
Code diff contained in this image:
${github_diff_url}
${github_url}/compare/core-${old_ref}...core-${ref}
The galoy api image will be bumped to digest:
\`\`\`
Expand Down

0 comments on commit 9ed020c

Please sign in to comment.