Skip to content

Commit

Permalink
fix: compare.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Sep 17, 2024
1 parent 6cdf101 commit 7de385a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 32 deletions.
8 changes: 5 additions & 3 deletions deploy
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export DRY_RUN
main::action "$SOURCE_BRANCH" \
"$TARGET_BRANCH" \
"$DEVELOPMENT_BRANCH" \
"$FORCE_DEPLOY" \
"$DEPLOY_SUCCESSFUL_TEXT"
"$FORCE_DEPLOY"

echo "Script finished successfully."
echo -e "${COLOR_GREEN}Script completed${COLOR_RESET}"
if [ -n "$DEPLOY_SUCCESSFUL_TEXT" ]; then
echo -e "$DEPLOY_SUCCESSFUL_TEXT"
fi
10 changes: 4 additions & 6 deletions src/compare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ function compare::source_with_target() {
local source=$1
local target=$2

echo -e "${COLOR_PURPLE}============================================${COLOR_RESET}"
echo -e "Comparing ${COLOR_ORANGE}$source${COLOR_RESET} with ${COLOR_ORANGE}$target${COLOR_RESET}"
echo -e "${COLOR_BLUE}============================================${COLOR_RESET}"
echo -e "${COLOR_BLUE}------------------------------------------------------------------${COLOR_RESET}"
echo -e "Commits to include in the release (into ${COLOR_ORANGE}$target${COLOR_RESET}):"
echo "$(git log --color --oneline origin/"$target".."$source")"
echo -e "${COLOR_BLUE}============================================${COLOR_RESET}"
echo -e "${COLOR_BLUE}------------------------------------------------------------------${COLOR_RESET}"
echo -e "Changed files between '${COLOR_ORANGE}$target${COLOR_RESET}' and '${COLOR_ORANGE}$source${COLOR_RESET}':"
compare::render_changed_files "$source" "$target"
echo -e "${COLOR_PURPLE}============================================${COLOR_RESET}"
}

function compare::render_changed_files() {
Expand Down Expand Up @@ -51,15 +49,15 @@ function compare::render_changed_files() {
fi

# Modified (updated) files
if [ "${#added_files[@]}" -gt 0 ]; then
if [ "${#modified_files[@]}" -gt 0 ]; then
for file in "${modified_files[@]}"; do
echo -e "${COLOR_YELLOW}~ $file${COLOR_RESET}"
done
fi


# Deleted files
if [ "${#added_files[@]}" -gt 0 ]; then
if [ "${#deleted_files[@]}" -gt 0 ]; then
for file in "${deleted_files[@]}"; do
echo -e "${COLOR_RED}- $file${COLOR_RESET}"
done
Expand Down
14 changes: 4 additions & 10 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ function main::action() {
local target=${2:-prod}
local development=${3:-1:-}
local force_deploy=${4:-false}
local deploy_successful_text=${5:-}

main::render_steps "$source" "$target" "$development"

echo -e "${COLOR_PURPLE}============================================${COLOR_RESET}"
echo -e "${COLOR_PURPLE}------------------------------------------------------------------${COLOR_RESET}"
git fetch origin
git status
echo -e "${COLOR_BLUE}============================================${COLOR_RESET}"
echo -e "${COLOR_BLUE}------------------------------------------------------------------${COLOR_RESET}"

echo -e "Using source branch: ${COLOR_ORANGE}$source${COLOR_RESET}"
validate::no_diff_between_local_and_origin "$source" "$target" "$force_deploy"
Expand All @@ -41,11 +40,6 @@ function main::action() {
release::create_github_release "$latest_tag" "$new_tag"

main::update_development "$development" "$target"

echo -e "${COLOR_GREEN}Script completed${COLOR_RESET}"
if [ -n "$deploy_successful_text" ]; then
echo -e "$deploy_successful_text"
fi
}

function main::render_steps() {
Expand Down Expand Up @@ -85,7 +79,7 @@ function main::merge_source_to_target() {
echo -e "Merging ${COLOR_ORANGE}$source${COLOR_RESET} release to ${COLOR_ORANGE}$target${COLOR_RESET}"

if [[ "$DRY_RUN" == true ]]; then
echo -e "${COLOR_YELLOW}--dry-run enabled. Skipping git merge ($source into $target)${COLOR_RESET}"
echo -e "${COLOR_CYAN}--dry-run enabled. Skipping git merge ($source into $target)${COLOR_RESET}"
return
fi

Expand All @@ -100,7 +94,7 @@ function main::merge_source_to_target() {

function main::force_checkout() {
if [[ "$DRY_RUN" == true ]]; then
echo -e "${COLOR_YELLOW}--dry-run enabled. Skipping git checkout${COLOR_RESET}"
echo -e "${COLOR_CYAN}--dry-run enabled. Skipping git checkout${COLOR_RESET}"
return
fi

Expand Down
7 changes: 4 additions & 3 deletions src/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function release::create_tag() {
local changed_files=$2

if [[ "$DRY_RUN" == true ]]; then
echo -e "${COLOR_YELLOW}--dry-run enabled. Skipping creating a tag ($new_tag)${COLOR_RESET}"
echo -e "${COLOR_CYAN}--dry-run enabled. Skipping creating a tag ($new_tag)${COLOR_RESET}"
return
fi

Expand All @@ -46,7 +46,6 @@ function release::create_github_release() {
previous_tag="main"
fi

local commits=$(git log --oneline "$previous_tag".."$new_tag")
local release_name=$(release::generate_release_name)
local remote_url=$(git remote get-url origin)
local repo_info=$(echo "$remote_url" | sed -E 's|git@github\.com:||; s|\.git$||')
Expand All @@ -55,10 +54,12 @@ function release::create_github_release() {
local full_changelog="**Full Changelog**: $changelog_url"

if [[ "$DRY_RUN" == true ]]; then
echo -e "${COLOR_YELLOW}--dry-run enabled. Skipping creating a release ($release_name)${COLOR_RESET}"
echo -e "${COLOR_CYAN}--dry-run enabled. Skipping creating a release ($release_name)${COLOR_RESET}"
return
fi

local commits=$(git log --oneline "$previous_tag".."$new_tag")

gh release create "$new_tag" \
--title "$release_name" \
--notes "$(echo -e "$commits\n\n$full_changelog")"
Expand Down
7 changes: 5 additions & 2 deletions src/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ your${COLOR_RESET} ${COLOR_ORANGE}$source${COLOR_RESET}."
"of ${COLOR_ORANGE}origin/$source${COLOR_RESET}" \
"by ${COLOR_RED}$ahead_commits${COLOR_RESET} commit(s)${COLOR_RESET}."

io::confirm_or_exit "${COLOR_YELLOW}Are you sure you want to push them" \
"to 'origin/$target' as part of the release?${COLOR_RESET}"
# shellcheck disable=SC2155
local question=$(echo "${COLOR_YELLOW}Are you sure you want to push them" \
"to 'origin/$target' as part of the release?${COLOR_RESET}")

io::confirm_or_exit "$question"
fi
}
27 changes: 19 additions & 8 deletions tests/e2e/snapshots/main_test_sh.test_main_without_args.snapshot
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
Usage: deploy [branch name] [--force (optional)]
Arguments
branch name to deploy
Options
--force ignore that your current branch as ahead commits
Usage: deploy [options] [branch name] [target branch] [development branch]

Arguments:
branch name The branch name to deploy (SOURCE_BRANCH).
target branch The target branch to deploy to (TARGET_BRANCH, optional).
development branch The development branch (DEVELOPMENT_BRANCH, optional).

Options:
--debug Enable debug mode (set -x).
--dry-run Simulate the deployment process without making any changes.
--force Ignore that your current branch has ahead commits.
-s, --source Specify the source branch.
-t, --target Specify the target branch.
-d, --development Specify the development branch.

Examples:
- deploy main
- deploy hotfix/...
- deploy hotfix/... --force
deploy main
deploy main --dry-run
deploy hotfix/... --force
deploy feature/... --dry-run --force
deploy main feature-branch --dry-run

0 comments on commit 7de385a

Please sign in to comment.