Skip to content

Commit

Permalink
Merge pull request #7 from infinum/feature/multiple-targets-build
Browse files Browse the repository at this point in the history
Feature/multiple targets build
  • Loading branch information
jabou authored Jan 31, 2024
2 parents 60c8ef9 + 0c310f8 commit de7c1db
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Targeting commit: e3e45889b
---------------------------------------------------------------
```

Next step is selecting a target that should be run on CI:
Next step is selecting one or multiple targets that should be run on CI:

```bash

Expand Down
62 changes: 50 additions & 12 deletions app-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function main {
# CREATE TAG

deploy_options
input_to_tags
create_app_version_and_build_number

# CREATE CHANGELOG
Expand Down Expand Up @@ -108,6 +109,23 @@ function initial_checkup {
fi
}

function input_to_tags {

# Parse all selected options
IFS=', ' read -r -a environments_array <<< "$target_selection"

environments_to_build=()

for environment in "${environments_array[@]}"; do
if [ ${environment} -le $((${#environments[@]} - 1)) -a ${environment} -ge 0 ]; then
environments_to_build+=("${environments[${environment}]}")
else
echo "Error: You chose wrong, young Jedi. This is the end of your path..."
exit 4
fi
done
}

function create_app_version_and_build_number {

echo
Expand Down Expand Up @@ -146,7 +164,10 @@ function create_app_version_and_build_number {
fi

# Create tag name internal{-TargetX}/vM.m.p-{number of commits}. E.g. internal-all/v1.0.0-1234
tag="$target/v$appversion-$tags_count"
tags_to_deploy=()
for target in "${environments_to_build[@]}"; do
tags_to_deploy+=("$target/v$appversion-$tags_count")
done

echo
echo "Next app version is: ${bold}v$appversion-$tags_count${normal}"
Expand All @@ -164,8 +185,19 @@ function generate_tag_and_changelog {
echo "Enter changelog message..."
echo "------------------------------------------------------------"
sleep 1

git tag -a "$tag"

tag_message_added=0
for tag in "${tags_to_deploy[@]}"; do

if [ ${tag_message_added} -eq 1 ]; then
TAG=`git describe --exact-match`
CHANGELOG=`git show -s --format=%N ${TAG} | tail -n +4`
git tag -a "$tag" -m "${CHANGELOG}"
else
git tag -a "$tag"
tag_message_added=1
fi
done
}

function push_tag_and_start_deploy {
Expand All @@ -184,20 +216,23 @@ function push_tag_and_start_deploy {
echo "---------------------------------------------------------------"
echo " ~ CONFIGURATION ~ "
echo
echo "Target: ${bold}$target_selection. $target${normal}"
echo "Version: ${bold}v$appversion-$tags_count${normal}"
echo "Tag: ${bold}$tag${normal}"
echo "Version: ${bold}v$appversion-$tags_count${normal}"
for tag in "${tags_to_deploy[@]}"; do
echo "Tag: ${bold}$tag${normal}"
done
echo
echo "Changelog:"
echo "${bold}$changelog_message${normal}"
echo "---------------------------------------------------------------"
echo
read -r -p "Is configuration correct for the CI deployment? [y/n] " response
read -r -p "Is configuration correct for the CI deployment? [y or enter / n] " response
echo

if [[ ${response} =~ ^(no|n|N) ]] || [ -z ${response} ]; then
git tag -d "$tag"
if [[ ${response} =~ ^(no|n|N) ]]; then
echo "Aborting."
for tag in "${tags_to_deploy[@]}"; do
git tag -d "$tag"
done
exit 6
fi

Expand All @@ -209,9 +244,12 @@ function push_tag {
if [ $? -eq 0 ]; then
echo
echo "------------------------------------------------------------"
echo "Tag added. Pushing tags ..."
echo
git push origin "$tag"
echo
for tag in "${tags_to_deploy[@]}"; do
# Push if everything is ok!
echo "Tag ${bold}${tag}${normal} added. Pushing tag ..."
git push origin "$tag"
done
echo
echo "============================================================"
echo "DEPLOY TAG SUCCESSFULLY ADDED!"
Expand Down
28 changes: 6 additions & 22 deletions deploy-options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,21 @@ function deploy_options {
echo "| TryOutApps |"
echo "--------------"
echo
echo "[0] All"
echo "[1] Staging"
echo "[2] UAT"
echo "[3] Production"
echo "[0] Staging"
echo "[1] UAT"
echo "[2] Production"
echo
echo "=================="
echo
echo "---------------------"
echo "| APP STORE CONNECT |"
echo "---------------------"
echo
echo "[4] App Store"
echo "[3] App Store"
echo
read -r -p "Enter number in square brackets: " target_selection
# erase_lines

# Logic for creating first part of the tag.
# Array for creating first part of the tag.
# Should be in sync with options shown to the user.

if [ ${target_selection} -eq 0 ]; then
target="internal-all"
elif [ ${target_selection} -eq 1 ]; then
target="internal-staging"
elif [ ${target_selection} -eq 2 ]; then
target="internal-uat"
elif [ ${target_selection} -eq 3 ]; then
target="internal-production"
elif [ ${target_selection} -eq 4 ]; then
target="appstore"
else
echo "Wrong target index. Aborting..."
exit 4
fi
environments=("internal-staging" "internal-uat" "internal-production" "appstore")
}

0 comments on commit de7c1db

Please sign in to comment.