From ad979c2869080ba44e07e696d3bd8dd625312e60 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Thu, 5 Dec 2024 14:22:45 +0100 Subject: [PATCH 01/39] Copy deploy options to bin folder --- app-deploy.sh | 22 +------------ install.sh | 24 +++++++++++--- sources/auto_update.sh | 31 +++++++++++++++++++ .../deploy-options.sh | 0 4 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 sources/auto_update.sh rename deploy-options.sh => sources/deploy-options.sh (100%) diff --git a/app-deploy.sh b/app-deploy.sh index 47d899c..64a2016 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash source ./.deploy-options.sh +source /usr/local/bin/app-deploy-helpers/auto_update.sh ############################################################### # DEPLOY SCRIPT # @@ -266,27 +267,6 @@ function push_tag { fi } -################################# -# UPDATE # -################################# - -function script_auto_update { - echo - echo "Please wait until main script is finished with updating..." - echo - echo "Fetching new data..." - if [ ! -d ".app_deploy_tmp" ]; then - mkdir .app_deploy_tmp - fi - git clone --quiet https://github.com/infinum/app-deploy-script.git .app_deploy_tmp - echo "Updating..." - cat .app_deploy_tmp/app-deploy.sh > /usr/local/bin/app-deploy - echo "Cleaning temporary files..." - rm -rf .app_deploy_tmp - echo "Updating finished!" - exit 0 -} - ################################# # START EVERYTHING # ################################# diff --git a/install.sh b/install.sh index 4908a4c..b8017df 100755 --- a/install.sh +++ b/install.sh @@ -25,16 +25,32 @@ if ! [[ ${c} =~ ^(yes|y|Y) ]] || [ -z ${c} ]; then fi echo echo "Fetching script data..." -mkdir .app_deploy_tmp -git clone --quiet https://github.com/infinum/app-deploy-script.git .app_deploy_tmp + +# Create temp folder +if [ ! -d ".app_deploy_tmp" ]; then + mkdir .app_deploy_tmp +else + rm -rf .app_deploy_tmp +fi + +# Get install files +git clone --quiet https://github.com/infinum/app-deploy-script.git --branch feature/v2/local-trigger .app_deploy_tmp echo "Installing..." + +# Move main script to bin folder cat .app_deploy_tmp/app-deploy.sh > /usr/local/bin/app-deploy -if ! [ -f ./.deploy-options.sh ]; then - cat .app_deploy_tmp/deploy-options.sh > ./.deploy-options.sh +# Move helpers to helpers folder inside bin +if [ ! -d "/usr/local/bin/app-deploy-helpers" ]; then + mkdir /usr/local/bin/app-deploy-helpers/ fi +cp -a .app_deploy_tmp/sources/. /usr/local/bin/app-deploy-helpers/ +# Add permission to read files chmod +rx /usr/local/bin/app-deploy +chmod +rx /usr/local/bin/app-deploy-helpers/ + +# Remove temp install folder rm -rf .app_deploy_tmp echo "Done!" diff --git a/sources/auto_update.sh b/sources/auto_update.sh new file mode 100644 index 0000000..282ffc4 --- /dev/null +++ b/sources/auto_update.sh @@ -0,0 +1,31 @@ +################################# +# UPDATE # +################################# + +function script_auto_update { + echo + echo "Please wait until main script is finished with updating..." + echo + echo "Fetching new data..." + + # Create temp folder + if [ ! -d ".app_deploy_tmp" ]; then + mkdir .app_deploy_tmp + else + rm -rf .app_deploy_tmp + fi + + # Get new data + git clone --quiet https://github.com/infinum/app-deploy-script.git --branch feature/v2/local-trigger .app_deploy_tmp + echo "Updating..." + + # Move new data to bin / helpers + cat .app_deploy_tmp/app-deploy.sh > /usr/local/bin/app-deploy + cp -a .app_deploy_tmp/sources/. /usr/local/bin/app-deploy-helpers/ + + # Remove temp folder + rm -rf .app_deploy_tmp + + echo "Updating finished!" + exit 0 +} diff --git a/deploy-options.sh b/sources/deploy-options.sh similarity index 100% rename from deploy-options.sh rename to sources/deploy-options.sh From 94313565c5a7304e79944f0813bf43f9f646c3d4 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Thu, 5 Dec 2024 15:21:38 +0100 Subject: [PATCH 02/39] Add init option --- app-deploy.sh | 9 ++++++--- sources/init.sh | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 sources/init.sh diff --git a/app-deploy.sh b/app-deploy.sh index 64a2016..2d10c4a 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -2,6 +2,7 @@ source ./.deploy-options.sh source /usr/local/bin/app-deploy-helpers/auto_update.sh +source /usr/local/bin/app-deploy-helpers/init.sh ############################################################### # DEPLOY SCRIPT # @@ -282,8 +283,10 @@ echo "# Copyright (c) 2020 Infinum. #" echo "###############################################################" echo -if ! [ "$1" == '--update' ] ; then - main -else +if [ "$1" == '--update' ] ; then script_auto_update +elif [ "$1" == 'init' ] ; then + init +else + main fi diff --git a/sources/init.sh b/sources/init.sh new file mode 100644 index 0000000..3ee4dab --- /dev/null +++ b/sources/init.sh @@ -0,0 +1,21 @@ +################################# +# INIT NEW PROJECT # +################################# + +function init { + + if [ -e "./.deploy-options.sh" ]; then + echo "Options file already exists." + echo "If you continue, stored options will be overriden!" + echo + read -r -p "Do you want to proceed? [y/n] " c + if ! [[ ${c} =~ ^(yes|y|Y) ]] || [ -z ${c} ]; then + exit 1 + fi + fi + + cat /usr/local/bin/app-deploy-helpers/deploy-options.sh > ./.deploy-options.sh + echo "The options file was generated successfully!" + echo "NOTE: Change default values to the project specific." + echo +} \ No newline at end of file From dcf2a76b3bd9eecc7c59eca7e9bee0e1f47f5413 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Thu, 5 Dec 2024 15:43:44 +0100 Subject: [PATCH 03/39] Update deploy options --- sources/deploy-options.sh | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/sources/deploy-options.sh b/sources/deploy-options.sh index d5157b7..c2fcd9c 100644 --- a/sources/deploy-options.sh +++ b/sources/deploy-options.sh @@ -1,5 +1,19 @@ #!/usr/bin/env bash +# Defines the version of workflow supported by this script. Currently, two versions are available, v1 and v2. +# +# v1 # +# An old workflow where the local script will ask you for the app version. +# The script will generate the next build number that can be used on the CI/CD. +# Each selected environment will get its tag, e.g., for Staging and UAT, you'll get two tags internal-staging/v1.0.0-1 and internal-uat/v1.0.0-1 +# +# v2 # +# New workflow, where the local script is used only as a CI/CD trigger. +# The script will not generate a build number or ask you for the app version. +# Each selected environment is concatenated into one tag. The tag will always start with `ci/` and end with `/{timestamp}.` E.g., ci/internal-staging/internal-uat/{timestamp} +# +# By default, this option is set to new workflow - v2 +script_version=v2 # If enabled, console will be cleared on every script run. # By default, this option is enabled use_automatic_console_clean=true @@ -46,15 +60,15 @@ function deploy_options { echo echo "==================" echo - echo "---------------------" - echo "| APP STORE CONNECT |" - echo "---------------------" + echo "---------" + echo "| STORE |" + echo "---------" echo - echo "[3] App Store" + echo "[3] App/Play Store" echo read -r -p "Enter number in square brackets: " target_selection - # Array 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. - environments=("internal-staging" "internal-uat" "internal-production" "appstore") + environments=("internal-staging" "internal-uat" "internal-production" "store") } From dd8309020e95ed3919b73fe094e491f2a3a92ad2 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Thu, 5 Dec 2024 15:53:33 +0100 Subject: [PATCH 04/39] Mark methods as private --- app-deploy.sh | 10 +++++----- sources/{auto_update.sh => __auto_update.sh} | 2 +- sources/{init.sh => __init.sh} | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) rename sources/{auto_update.sh => __auto_update.sh} (96%) rename sources/{init.sh => __init.sh} (97%) diff --git a/app-deploy.sh b/app-deploy.sh index 2d10c4a..0b92e83 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash source ./.deploy-options.sh -source /usr/local/bin/app-deploy-helpers/auto_update.sh -source /usr/local/bin/app-deploy-helpers/init.sh +source /usr/local/bin/app-deploy-helpers/__auto_update.sh +source /usr/local/bin/app-deploy-helpers/__init.sh ############################################################### # DEPLOY SCRIPT # @@ -279,14 +279,14 @@ echo echo "###############################################################" echo "# DEPLOY SCRIPT #" echo "# #" -echo "# Copyright (c) 2020 Infinum. #" +echo "# Copyright (c) 2024 Infinum. #" echo "###############################################################" echo if [ "$1" == '--update' ] ; then - script_auto_update + __script_auto_update elif [ "$1" == 'init' ] ; then - init + __init else main fi diff --git a/sources/auto_update.sh b/sources/__auto_update.sh similarity index 96% rename from sources/auto_update.sh rename to sources/__auto_update.sh index 282ffc4..66c6c43 100644 --- a/sources/auto_update.sh +++ b/sources/__auto_update.sh @@ -2,7 +2,7 @@ # UPDATE # ################################# -function script_auto_update { +function __script_auto_update { echo echo "Please wait until main script is finished with updating..." echo diff --git a/sources/init.sh b/sources/__init.sh similarity index 97% rename from sources/init.sh rename to sources/__init.sh index 3ee4dab..f87f21a 100644 --- a/sources/init.sh +++ b/sources/__init.sh @@ -2,7 +2,7 @@ # INIT NEW PROJECT # ################################# -function init { +function __init { if [ -e "./.deploy-options.sh" ]; then echo "Options file already exists." From 7cc6e4b11c9dad6b11262b8c084d5e3950d1c3cf Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Thu, 5 Dec 2024 16:04:09 +0100 Subject: [PATCH 05/39] Rename folder with sources files --- app-deploy.sh | 4 ++-- install.sh | 8 ++++---- sources/__auto_update.sh | 2 +- sources/__init.sh | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app-deploy.sh b/app-deploy.sh index 0b92e83..46d082e 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash source ./.deploy-options.sh -source /usr/local/bin/app-deploy-helpers/__auto_update.sh -source /usr/local/bin/app-deploy-helpers/__init.sh +source /usr/local/bin/.app-deploy-sources/__auto_update.sh +source /usr/local/bin/.app-deploy-sources/__init.sh ############################################################### # DEPLOY SCRIPT # diff --git a/install.sh b/install.sh index b8017df..5960b81 100755 --- a/install.sh +++ b/install.sh @@ -41,14 +41,14 @@ echo "Installing..." cat .app_deploy_tmp/app-deploy.sh > /usr/local/bin/app-deploy # Move helpers to helpers folder inside bin -if [ ! -d "/usr/local/bin/app-deploy-helpers" ]; then - mkdir /usr/local/bin/app-deploy-helpers/ +if [ ! -d "/usr/local/bin/.app-deploy-sources" ]; then + mkdir /usr/local/bin/.app-deploy-sources/ fi -cp -a .app_deploy_tmp/sources/. /usr/local/bin/app-deploy-helpers/ +cp -a .app_deploy_tmp/sources/. /usr/local/bin/.app-deploy-sources/ # Add permission to read files chmod +rx /usr/local/bin/app-deploy -chmod +rx /usr/local/bin/app-deploy-helpers/ +chmod +rx /usr/local/bin/.app-deploy-sources/ # Remove temp install folder rm -rf .app_deploy_tmp diff --git a/sources/__auto_update.sh b/sources/__auto_update.sh index 66c6c43..24f2e74 100644 --- a/sources/__auto_update.sh +++ b/sources/__auto_update.sh @@ -21,7 +21,7 @@ function __script_auto_update { # Move new data to bin / helpers cat .app_deploy_tmp/app-deploy.sh > /usr/local/bin/app-deploy - cp -a .app_deploy_tmp/sources/. /usr/local/bin/app-deploy-helpers/ + cp -a .app_deploy_tmp/sources/. /usr/local/bin/.app-deploy-sources/ # Remove temp folder rm -rf .app_deploy_tmp diff --git a/sources/__init.sh b/sources/__init.sh index f87f21a..b7b8d0c 100644 --- a/sources/__init.sh +++ b/sources/__init.sh @@ -14,7 +14,7 @@ function __init { fi fi - cat /usr/local/bin/app-deploy-helpers/deploy-options.sh > ./.deploy-options.sh + cat /usr/local/bin/.app-deploy-sources/deploy-options.sh > ./.deploy-options.sh echo "The options file was generated successfully!" echo "NOTE: Change default values to the project specific." echo From aacee6561a757c5f38c5f190b75f1b2dacd12f5f Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Thu, 5 Dec 2024 16:16:56 +0100 Subject: [PATCH 06/39] Move code blocks to private functions in separate files --- app-deploy.sh | 230 ++------------------------------- sources/__base_tag_handling.sh | 96 ++++++++++++++ sources/__deploy_tags.sh | 69 ++++++++++ sources/__initial_checkup.sh | 59 +++++++++ 4 files changed, 233 insertions(+), 221 deletions(-) create mode 100644 sources/__base_tag_handling.sh create mode 100644 sources/__deploy_tags.sh create mode 100644 sources/__initial_checkup.sh diff --git a/app-deploy.sh b/app-deploy.sh index 46d082e..5cd1068 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -3,6 +3,9 @@ source ./.deploy-options.sh source /usr/local/bin/.app-deploy-sources/__auto_update.sh source /usr/local/bin/.app-deploy-sources/__init.sh +source /usr/local/bin/.app-deploy-sources/__initial_checkup.sh +source /usr/local/bin/.app-deploy-sources/__base_tag_handling.sh +source /usr/local/bin/.app-deploy-sources/__deploy_tags.sh ############################################################### # DEPLOY SCRIPT # @@ -36,236 +39,21 @@ function main { # BASE INFO # commit, tag, synced head,... - initial_checkup + __initial_checkup # CREATE TAG - deploy_options - input_to_tags - create_app_version_and_build_number + deploy_options # Get from .deploy-options.sh, setup per project + __input_to_tags + __create_app_version_and_build_number # CREATE CHANGELOG - generate_tag_and_changelog + __generate_tag_and_changelog # DEPLOY - push_tag_and_start_deploy -} - -################################# -# HELPERS # -################################# - -function initial_checkup { - - echo - echo "###############################################################" - echo "# COMMIT CHECK #" - echo "###############################################################" - echo - - if [ $# -gt 1 ] || [ "$1" == '-h' ] || [ "$1" == '--help' ] || [ "$1" == 'help' ]; then - echo "Usage: $0 [optional-commit-hash]" - exit 1 - fi - - if [ $# -eq 1 ]; then - commit="$1" - else - commit=`git rev-parse --short HEAD` - fi - - commit_message=`git log --format=%B -n 1 ${commit}` - - if [ $? -ne 0 ]; then - echo "Failed to get message for commit '$commit'. Aborting." - exit 2 - fi - - echo "---------------------------------------------------------------" - echo "Targeting commit: ${bold}$commit${normal}" - echo "---------------------------------------------------------------" - echo "$commit_message" - echo "---------------------------------------------------------------" - - remote_branches=`git branch -r --contains ${commit}` - if [ $? -ne 0 ] || [ -z "$remote_branches" ]; then - echo - echo "Commit '$commit' not found on any remote branch." - if $enable_automatic_commit_push ; then - current_branch=`git rev-parse --abbrev-ref HEAD` - echo "Pushing..." - git push origin "$current_branch" - else - read -r -p "Do you want to push it? [y/n] " push_to_git - if [[ ${push_to_git} =~ ^(yes|y|Y) ]] || [ -z ${push_to_git} ]; then - current_branch=`git rev-parse --abbrev-ref HEAD` - echo "Pushing..." - git push origin "$current_branch" - else - echo "Aborting." - exit 3 - fi - fi - 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 - echo "###############################################################" - echo "# APP VERSION #" - echo "###############################################################" - echo - - # App version number - last_known_tag=`git describe --abbrev=0 --tags | sed -E 's/.*v([0-9]*\.?[0-9]*\.?[0-9]*)(-.*)?/\1/'` - - if [ -z "$last_known_tag" ] - then - read -r -p "Enter current app version (e.g. 1.0.0): " appversion - else - read -r -p "Press enter to use last known version: ${bold}$last_known_tag${normal}. (or enter different version) " new_version - [ -z "$new_version" ] && appversion=$last_known_tag || appversion=$new_version - fi - - if ! [[ "$appversion" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] - then - echo "App version is in wrong format (use M.m.p format, e.g. 1.0.0). Aborting..." - exit 5 - fi - - # Build number - - echo "Getting next build number..." - - tags_count=`git ls-remote --t --refs -q | grep -o -E '[[:<:]]\d+(\n|$)' | sort -nr | head -n1` - - if [ -z "$tags_count" ]; then - tags_count=0 - else - tags_count=$((tags_count+1)) - fi - - # Create tag name internal{-TargetX}/vM.m.p-{number of commits}. E.g. internal-all/v1.0.0-1234 - 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}" - sleep 1 -} - -function generate_tag_and_changelog { - - echo - echo "###############################################################" - echo "# CHANGELOG #" - echo "###############################################################" - echo - echo "------------------------------------------------------------" - echo "Enter changelog message..." - echo "------------------------------------------------------------" - sleep 1 - - 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 { - - changelog_message=`git show -s --format=%N ${tag} | tail -n +4` - - if ! $enable_final_confirmation ; then - push_tag - fi - - echo - echo "###############################################################" - echo "# DEPLOY #" - echo "###############################################################" - echo - echo "---------------------------------------------------------------" - echo " ~ CONFIGURATION ~ " - echo - 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 or enter / n] " response - echo - - if [[ ${response} =~ ^(no|n|N) ]]; then - echo "Aborting." - for tag in "${tags_to_deploy[@]}"; do - git tag -d "$tag" - done - exit 6 - fi - - push_tag -} - -function push_tag { - # Push if everything is ok! - if [ $? -eq 0 ]; then - echo - echo "------------------------------------------------------------" - 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!" - echo "CHECK YOUR CI FOR THE BUILD STATUS" - echo "============================================================" - echo - exit 0 - else - echo - echo "------------------------------------------------------------" - echo "Failed to add tag. Aborting." - echo "------------------------------------------------------------" - exit 7 - fi + __push_tag_and_start_deploy } ################################# diff --git a/sources/__base_tag_handling.sh b/sources/__base_tag_handling.sh new file mode 100644 index 0000000..fd9abe0 --- /dev/null +++ b/sources/__base_tag_handling.sh @@ -0,0 +1,96 @@ +################################# +# CREATE TAG # +################################# + +# Parse all selected options +function __input_to_tags { + + 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 +} + +# Generate app version and build number +function __create_app_version_and_build_number { + + echo + echo "###############################################################" + echo "# APP VERSION #" + echo "###############################################################" + echo + + # App version number + last_known_tag=`git describe --abbrev=0 --tags | sed -E 's/.*v([0-9]*\.?[0-9]*\.?[0-9]*)(-.*)?/\1/'` + + if [ -z "$last_known_tag" ] + then + read -r -p "Enter current app version (e.g. 1.0.0): " appversion + else + read -r -p "Press enter to use last known version: ${bold}$last_known_tag${normal}. (or enter different version) " new_version + [ -z "$new_version" ] && appversion=$last_known_tag || appversion=$new_version + fi + + if ! [[ "$appversion" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] + then + echo "App version is in wrong format (use M.m.p format, e.g. 1.0.0). Aborting..." + exit 5 + fi + + # Build number + + echo "Getting next build number..." + + tags_count=`git ls-remote --t --refs -q | grep -o -E '[[:<:]]\d+(\n|$)' | sort -nr | head -n1` + + if [ -z "$tags_count" ]; then + tags_count=0 + else + tags_count=$((tags_count+1)) + fi + + # Create tag name internal{-TargetX}/vM.m.p-{number of commits}. E.g. internal-all/v1.0.0-1234 + 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}" + sleep 1 +} + +# Changelog +function __generate_tag_and_changelog { + + echo + echo "###############################################################" + echo "# CHANGELOG #" + echo "###############################################################" + echo + echo "------------------------------------------------------------" + echo "Enter changelog message..." + echo "------------------------------------------------------------" + sleep 1 + + 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 +} \ No newline at end of file diff --git a/sources/__deploy_tags.sh b/sources/__deploy_tags.sh new file mode 100644 index 0000000..3419c59 --- /dev/null +++ b/sources/__deploy_tags.sh @@ -0,0 +1,69 @@ +################################# +# DEPLOY # +################################# + +function __push_tag_and_start_deploy { + + changelog_message=`git show -s --format=%N ${tag} | tail -n +4` + + if ! $enable_final_confirmation ; then + __push_tag + fi + + echo + echo "###############################################################" + echo "# DEPLOY #" + echo "###############################################################" + echo + echo "---------------------------------------------------------------" + echo " ~ CONFIGURATION ~ " + echo + 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 or enter / n] " response + echo + + if [[ ${response} =~ ^(no|n|N) ]]; then + echo "Aborting." + for tag in "${tags_to_deploy[@]}"; do + git tag -d "$tag" + done + exit 6 + fi + + __push_tag +} + +function __push_tag { + # Push if everything is ok! + if [ $? -eq 0 ]; then + echo + echo "------------------------------------------------------------" + 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!" + echo "CHECK YOUR CI FOR THE BUILD STATUS" + echo "============================================================" + echo + exit 0 + else + echo + echo "------------------------------------------------------------" + echo "Failed to add tag. Aborting." + echo "------------------------------------------------------------" + exit 7 + fi +} \ No newline at end of file diff --git a/sources/__initial_checkup.sh b/sources/__initial_checkup.sh new file mode 100644 index 0000000..8ebba91 --- /dev/null +++ b/sources/__initial_checkup.sh @@ -0,0 +1,59 @@ +################################# +# INITIAL CHECK # +################################# + +# Check commit, tag, synced head,... +# Report any uncommited changes, unpushed commits, etc.. +function __initial_checkup { + + echo + echo "###############################################################" + echo "# COMMIT CHECK #" + echo "###############################################################" + echo + + if [ $# -gt 1 ] || [ "$1" == '-h' ] || [ "$1" == '--help' ] || [ "$1" == 'help' ]; then + echo "Usage: $0 [optional-commit-hash]" + exit 1 + fi + + if [ $# -eq 1 ]; then + commit="$1" + else + commit=`git rev-parse --short HEAD` + fi + + commit_message=`git log --format=%B -n 1 ${commit}` + + if [ $? -ne 0 ]; then + echo "Failed to get message for commit '$commit'. Aborting." + exit 2 + fi + + echo "---------------------------------------------------------------" + echo "Targeting commit: ${bold}$commit${normal}" + echo "---------------------------------------------------------------" + echo "$commit_message" + echo "---------------------------------------------------------------" + + remote_branches=`git branch -r --contains ${commit}` + if [ $? -ne 0 ] || [ -z "$remote_branches" ]; then + echo + echo "Commit '$commit' not found on any remote branch." + if $enable_automatic_commit_push ; then + current_branch=`git rev-parse --abbrev-ref HEAD` + echo "Pushing..." + git push origin "$current_branch" + else + read -r -p "Do you want to push it? [y/n] " push_to_git + if [[ ${push_to_git} =~ ^(yes|y|Y) ]] || [ -z ${push_to_git} ]; then + current_branch=`git rev-parse --abbrev-ref HEAD` + echo "Pushing..." + git push origin "$current_branch" + else + echo "Aborting." + exit 3 + fi + fi + fi +} \ No newline at end of file From 1f857d6f1c8d93b4c2f603b2134bd7b687a3080c Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Thu, 5 Dec 2024 17:02:31 +0100 Subject: [PATCH 07/39] Set auto update to load local files --- sources/__auto_update.sh | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/sources/__auto_update.sh b/sources/__auto_update.sh index 24f2e74..aa092e2 100644 --- a/sources/__auto_update.sh +++ b/sources/__auto_update.sh @@ -9,22 +9,27 @@ function __script_auto_update { echo "Fetching new data..." # Create temp folder - if [ ! -d ".app_deploy_tmp" ]; then - mkdir .app_deploy_tmp - else - rm -rf .app_deploy_tmp - fi + # if [ ! -d ".app_deploy_tmp" ]; then + # mkdir .app_deploy_tmp + # else + # rm -rf .app_deploy_tmp + # fi # Get new data - git clone --quiet https://github.com/infinum/app-deploy-script.git --branch feature/v2/local-trigger .app_deploy_tmp - echo "Updating..." + # git clone --quiet https://github.com/infinum/app-deploy-script.git --branch feature/v2/local-trigger .app_deploy_tmp + # echo "Updating..." - # Move new data to bin / helpers - cat .app_deploy_tmp/app-deploy.sh > /usr/local/bin/app-deploy - cp -a .app_deploy_tmp/sources/. /usr/local/bin/.app-deploy-sources/ + # # Move new data to bin / helpers + # cat .app_deploy_tmp/app-deploy.sh > /usr/local/bin/app-deploy + # cp -a .app_deploy_tmp/sources/. /usr/local/bin/.app-deploy-sources/ + + # LOCAL DEVELOPMENT + # Comment when not in use + cat /Users/jaco/Infinum/Infinum_projects/AppDeployScript/app-deploy-script/app-deploy.sh > /usr/local/bin/app-deploy + cp -a /Users/jaco/Infinum/Infinum_projects/AppDeployScript/app-deploy-script/sources/. /usr/local/bin/.app-deploy-sources/ # Remove temp folder - rm -rf .app_deploy_tmp + # rm -rf .app_deploy_tmp echo "Updating finished!" exit 0 From dc4707c77acd18274409935b11b3f01a20ce448d Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Thu, 5 Dec 2024 17:36:26 +0100 Subject: [PATCH 08/39] Add support for v2 tag version --- app-deploy.sh | 11 +++++++---- sources/__base_tag_handling.sh | 23 +++++++++++++++++++++++ sources/__deploy_tags.sh | 4 +++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app-deploy.sh b/app-deploy.sh index 5cd1068..386feef 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -13,11 +13,9 @@ source /usr/local/bin/.app-deploy-sources/__deploy_tags.sh # Script used for creating the specific # # tag used for triggering the CI deployment # # # -# End tag should look like this: # -# internal-all/v1.0.0-1234 # # # # Prepared by Jasmin Abou Aldan # -# Copyright (c) 2020 Infinum. All rights reserved. # +# Copyright (c) 2024 Infinum. All rights reserved. # ############################################################### # Use global variables at your own risk as this can be overridden in the future. @@ -45,7 +43,12 @@ function main { deploy_options # Get from .deploy-options.sh, setup per project __input_to_tags - __create_app_version_and_build_number + + if [ -z "$script_version" ] || [ "$script_version" == "v1" ]; then + __create_app_version_and_build_number + elif [ "$script_version" == "v2" ]; then + __create_trigger_ci_timestamp_tag + fi # CREATE CHANGELOG diff --git a/sources/__base_tag_handling.sh b/sources/__base_tag_handling.sh index fd9abe0..a87cfbb 100644 --- a/sources/__base_tag_handling.sh +++ b/sources/__base_tag_handling.sh @@ -20,6 +20,7 @@ function __input_to_tags { } # Generate app version and build number +# Used in v1 version of the script function __create_app_version_and_build_number { echo @@ -68,6 +69,28 @@ function __create_app_version_and_build_number { sleep 1 } +# Generate trigger tag with timestamp +# Used in v2 version of the script +function __create_trigger_ci_timestamp_tag { + + # Create tag name ci/{environment}/{timestamp}}. E.g. ci/internal-staging/2024-12-05T17-16-28 + tags_to_deploy=() + + # Prefix ci + trigger_tag="ci/" + + # Environments + for target in "${environments_to_build[@]}"; do + trigger_tag+="$target/" + done + + # Sufix timestamp + trigger_tag+="$(date +%Y-%m-%dT%H-%M-%S)" + + # Assign to shared property + tags_to_deploy=("$trigger_tag") +} + # Changelog function __generate_tag_and_changelog { diff --git a/sources/__deploy_tags.sh b/sources/__deploy_tags.sh index 3419c59..3abfb75 100644 --- a/sources/__deploy_tags.sh +++ b/sources/__deploy_tags.sh @@ -18,7 +18,9 @@ function __push_tag_and_start_deploy { echo "---------------------------------------------------------------" echo " ~ CONFIGURATION ~ " echo - echo "Version: ${bold}v$appversion-$tags_count${normal}" + if [ -n "$appversion" ]; then + echo "Version: ${bold}v$appversion-$tags_count${normal}" + fi for tag in "${tags_to_deploy[@]}"; do echo "Tag: ${bold}$tag${normal}" done From 81168df5bca2f4cf4c8603e54cf347fc6e5c2b4b Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Fri, 6 Dec 2024 12:30:50 +0100 Subject: [PATCH 09/39] Add trigger command, disable anything else --- app-deploy.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app-deploy.sh b/app-deploy.sh index 386feef..c56dc36 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -78,6 +78,11 @@ if [ "$1" == '--update' ] ; then __script_auto_update elif [ "$1" == 'init' ] ; then __init +elif [ -z "$1" ] || [ "$1" == 'trigger' ] ; then # Empty input or "trigger" + main else - main + echo + echo "Unsuported command!" + echo + exit 0 fi From 58121636ccf3945981f20715a8cf24d101c5e58a Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Fri, 6 Dec 2024 13:25:45 +0100 Subject: [PATCH 10/39] Add logic for extracting env from input tag --- app-deploy.sh | 13 +++++----- sources/__auto_update.sh | 4 ++++ sources/__base_tag_handling.sh | 6 +++-- sources/__constants.sh | 17 ++++++++++++++ sources/__env_extractor.sh | 43 ++++++++++++++++++++++++++++++++++ sources/__init.sh | 4 ++++ 6 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 sources/__constants.sh create mode 100644 sources/__env_extractor.sh diff --git a/app-deploy.sh b/app-deploy.sh index c56dc36..9238356 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -1,11 +1,13 @@ #!/usr/bin/env bash source ./.deploy-options.sh +source /usr/local/bin/.app-deploy-sources/__constants.sh source /usr/local/bin/.app-deploy-sources/__auto_update.sh source /usr/local/bin/.app-deploy-sources/__init.sh source /usr/local/bin/.app-deploy-sources/__initial_checkup.sh source /usr/local/bin/.app-deploy-sources/__base_tag_handling.sh source /usr/local/bin/.app-deploy-sources/__deploy_tags.sh +source /usr/local/bin/.app-deploy-sources/__env_extractor.sh ############################################################### # DEPLOY SCRIPT # @@ -35,6 +37,8 @@ normal=$(tput sgr0) function main { + __header_print + # BASE INFO # commit, tag, synced head,... __initial_checkup @@ -66,13 +70,6 @@ function main { if $use_automatic_console_clean ; then clear fi -echo -echo "###############################################################" -echo "# DEPLOY SCRIPT #" -echo "# #" -echo "# Copyright (c) 2024 Infinum. #" -echo "###############################################################" -echo if [ "$1" == '--update' ] ; then __script_auto_update @@ -80,6 +77,8 @@ elif [ "$1" == 'init' ] ; then __init elif [ -z "$1" ] || [ "$1" == 'trigger' ] ; then # Empty input or "trigger" main +elif [ "$1" == 'environments' ] ; then + __env_extractor "$2" else echo echo "Unsuported command!" diff --git a/sources/__auto_update.sh b/sources/__auto_update.sh index aa092e2..93f008e 100644 --- a/sources/__auto_update.sh +++ b/sources/__auto_update.sh @@ -1,8 +1,12 @@ +source /usr/local/bin/.app-deploy-sources/__constants.sh + ################################# # UPDATE # ################################# function __script_auto_update { + + __header_print echo echo "Please wait until main script is finished with updating..." echo diff --git a/sources/__base_tag_handling.sh b/sources/__base_tag_handling.sh index a87cfbb..6c01006 100644 --- a/sources/__base_tag_handling.sh +++ b/sources/__base_tag_handling.sh @@ -1,3 +1,5 @@ +source /usr/local/bin/.app-deploy-sources/__constants.sh + ################################# # CREATE TAG # ################################# @@ -77,7 +79,7 @@ function __create_trigger_ci_timestamp_tag { tags_to_deploy=() # Prefix ci - trigger_tag="ci/" + trigger_tag="$TRIGGER_TAG_PREFIX" # Environments for target in "${environments_to_build[@]}"; do @@ -85,7 +87,7 @@ function __create_trigger_ci_timestamp_tag { done # Sufix timestamp - trigger_tag+="$(date +%Y-%m-%dT%H-%M-%S)" + trigger_tag+="$TRIGGER_TAG_SUFIX" # Assign to shared property tags_to_deploy=("$trigger_tag") diff --git a/sources/__constants.sh b/sources/__constants.sh new file mode 100644 index 0000000..9a636bd --- /dev/null +++ b/sources/__constants.sh @@ -0,0 +1,17 @@ +################################# +# CONSTANTS # +################################# + +function __header_print() { + echo + echo "###############################################################" + echo "# DEPLOY SCRIPT #" + echo "# #" + echo "# Copyright (c) 2024 Infinum. #" + echo "###############################################################" + echo +} + +TRIGGER_TAG_PREFIX="ci/" +TRIGGER_TAG_SUFIX="$(date +%Y-%m-%dT%H-%M-%S)" +TRIGGER_TAG_SUFIX_REGEX=([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2}) \ No newline at end of file diff --git a/sources/__env_extractor.sh b/sources/__env_extractor.sh new file mode 100644 index 0000000..1bf3704 --- /dev/null +++ b/sources/__env_extractor.sh @@ -0,0 +1,43 @@ +source /usr/local/bin/.app-deploy-sources/__constants.sh + +################################# +# ENVIRONMENT EXTRACTOR # +################################# + +function __env_extractor { + + # Check if input is valid + if [ -z "$1" ] ; then + echo "Missing input value!" + echo + echo "Usage: app-deploy environments input" + echo "- input: a value from which 'environments' command shoudl extract data. Should be trigger tag generated by this script." + exit 1 + fi + + if [[ $1 =~ ^$TRIGGER_TAG_PREFIX(.+)/$TRIGGER_TAG_SUFIX_REGEX$ ]]; then + paths="${BASH_REMATCH[1]}" + + # Split the captured paths into individual words + IFS='/' read -ra words <<< "$paths" + + for env in "${words[@]}"; do + ENVIRONMENTS+="$env"$'\n' + done + + # Remove last empty line + ENVIRONMENTS=$(echo -n "$ENVIRONMENTS") + echo "$ENVIRONMENTS" + else + echo + echo "Incorrect input value." + echo + echo "The environment can only be extracted from the official trigger tag." + echo + echo "Please use this script for generating the trigger tag, or use the tag in the format:" + echo "prefix: ci/" + echo "environments: env1/env2/..." + echo "sufix: /timestamp where timestamp should be in the format of +%Y-%m-%dT%H-%M-%S (2024-12-06T11-24-53)" + echo "EXAMPLE: ci/env1/env2/2024-12-06T11-24-53" + fi +} \ No newline at end of file diff --git a/sources/__init.sh b/sources/__init.sh index b7b8d0c..321fb60 100644 --- a/sources/__init.sh +++ b/sources/__init.sh @@ -1,9 +1,13 @@ +source /usr/local/bin/.app-deploy-sources/__constants.sh + ################################# # INIT NEW PROJECT # ################################# function __init { + __header_print + if [ -e "./.deploy-options.sh" ]; then echo "Options file already exists." echo "If you continue, stored options will be overriden!" From b8aa24653a68a5235335a337361822855248a561 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Fri, 6 Dec 2024 14:49:01 +0100 Subject: [PATCH 11/39] Add silent install support --- install.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 5960b81..b09d0e4 100755 --- a/install.sh +++ b/install.sh @@ -19,10 +19,13 @@ normal=$(tput sgr0) echo "==> ${bold}This script will install:${normal}" echo "/usr/local/bin/app-deploy" echo -read -r -p "Do you want to proceed? [y/n] " c -if ! [[ ${c} =~ ^(yes|y|Y) ]] || [ -z ${c} ]; then - exit 1 +if [[ $1 =~ "--silent" ]]; then + read -r -p "Do you want to proceed? [y/n] " c + if ! [[ ${c} =~ ^(yes|y|Y) ]] || [ -z ${c} ]; then + exit 1 + fi fi + echo echo "Fetching script data..." From f41f2a519faf778d02703176417036cd6e0841e4 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Fri, 6 Dec 2024 14:57:22 +0100 Subject: [PATCH 12/39] Trigger update --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index b09d0e4..d051dca 100755 --- a/install.sh +++ b/install.sh @@ -19,7 +19,7 @@ normal=$(tput sgr0) echo "==> ${bold}This script will install:${normal}" echo "/usr/local/bin/app-deploy" echo -if [[ $1 =~ "--silent" ]]; then +if ! [[ $1 == "--silent" ]]; then read -r -p "Do you want to proceed? [y/n] " c if ! [[ ${c} =~ ^(yes|y|Y) ]] || [ -z ${c} ]; then exit 1 From f7de23b93760410f8242164bbd64263d6decd34f Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Fri, 6 Dec 2024 16:02:44 +0100 Subject: [PATCH 13/39] Update install script --- install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index d051dca..5a85fbc 100755 --- a/install.sh +++ b/install.sh @@ -19,7 +19,8 @@ normal=$(tput sgr0) echo "==> ${bold}This script will install:${normal}" echo "/usr/local/bin/app-deploy" echo -if ! [[ $1 == "--silent" ]]; then + +if ! [[ "$0" == "--silent" ]]; then read -r -p "Do you want to proceed? [y/n] " c if ! [[ ${c} =~ ^(yes|y|Y) ]] || [ -z ${c} ]; then exit 1 From da8dddeb6864d8464a8f99a8ba2ce3f792e0d7e2 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Fri, 6 Dec 2024 17:21:30 +0100 Subject: [PATCH 14/39] Update extractor logic --- sources/__env_extractor.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/sources/__env_extractor.sh b/sources/__env_extractor.sh index 1bf3704..333452d 100644 --- a/sources/__env_extractor.sh +++ b/sources/__env_extractor.sh @@ -26,7 +26,6 @@ function __env_extractor { done # Remove last empty line - ENVIRONMENTS=$(echo -n "$ENVIRONMENTS") echo "$ENVIRONMENTS" else echo From 6ee21f4c9b5b77703f7e73665b32dd02e3809c82 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Fri, 6 Dec 2024 17:34:40 +0100 Subject: [PATCH 15/39] Return value from extractor --- app-deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app-deploy.sh b/app-deploy.sh index 9238356..ff936df 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -78,7 +78,7 @@ elif [ "$1" == 'init' ] ; then elif [ -z "$1" ] || [ "$1" == 'trigger' ] ; then # Empty input or "trigger" main elif [ "$1" == 'environments' ] ; then - __env_extractor "$2" + echo __env_extractor "$2" else echo echo "Unsuported command!" From 9877a45edb7b07d9995c070ea44b26db892294f7 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Fri, 6 Dec 2024 17:37:18 +0100 Subject: [PATCH 16/39] Update install branch --- app-deploy.sh | 2 +- install.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app-deploy.sh b/app-deploy.sh index ff936df..9238356 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -78,7 +78,7 @@ elif [ "$1" == 'init' ] ; then elif [ -z "$1" ] || [ "$1" == 'trigger' ] ; then # Empty input or "trigger" main elif [ "$1" == 'environments' ] ; then - echo __env_extractor "$2" + __env_extractor "$2" else echo echo "Unsuported command!" diff --git a/install.sh b/install.sh index 5a85fbc..81e21c8 100755 --- a/install.sh +++ b/install.sh @@ -38,7 +38,7 @@ else fi # Get install files -git clone --quiet https://github.com/infinum/app-deploy-script.git --branch feature/v2/local-trigger .app_deploy_tmp +git clone --quiet https://github.com/infinum/app-deploy-script.git --branch feature/v2/environments-export .app_deploy_tmp echo "Installing..." # Move main script to bin folder From 263e20ea4f3b9ef2a9499e81f2c412d3d51cc17f Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Fri, 6 Dec 2024 17:44:52 +0100 Subject: [PATCH 17/39] Return extraction value --- app-deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app-deploy.sh b/app-deploy.sh index 9238356..6a22dd6 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -78,7 +78,7 @@ elif [ "$1" == 'init' ] ; then elif [ -z "$1" ] || [ "$1" == 'trigger' ] ; then # Empty input or "trigger" main elif [ "$1" == 'environments' ] ; then - __env_extractor "$2" + echo $(__env_extractor "$2") else echo echo "Unsuported command!" From d5e81f0932d45b54f26923398211b190bc0308e7 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Fri, 6 Dec 2024 18:46:47 +0100 Subject: [PATCH 18/39] Update env extraction --- app-deploy.sh | 7 +++---- sources/__constants.sh | 7 ++++++- sources/__env_extractor.sh | 10 ++-------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app-deploy.sh b/app-deploy.sh index 6a22dd6..7b360fa 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -67,15 +67,14 @@ function main { # START EVERYTHING # ################################# -if $use_automatic_console_clean ; then - clear -fi - if [ "$1" == '--update' ] ; then + __clear_console __script_auto_update elif [ "$1" == 'init' ] ; then + __clear_console __init elif [ -z "$1" ] || [ "$1" == 'trigger' ] ; then # Empty input or "trigger" + __clear_console main elif [ "$1" == 'environments' ] ; then echo $(__env_extractor "$2") diff --git a/sources/__constants.sh b/sources/__constants.sh index 9a636bd..ee0275e 100644 --- a/sources/__constants.sh +++ b/sources/__constants.sh @@ -2,7 +2,7 @@ # CONSTANTS # ################################# -function __header_print() { +function __header_print { echo echo "###############################################################" echo "# DEPLOY SCRIPT #" @@ -12,6 +12,11 @@ function __header_print() { echo } +function __clear_console { + if $use_automatic_console_clean ; then + clear + fi +} TRIGGER_TAG_PREFIX="ci/" TRIGGER_TAG_SUFIX="$(date +%Y-%m-%dT%H-%M-%S)" TRIGGER_TAG_SUFIX_REGEX=([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2}) \ No newline at end of file diff --git a/sources/__env_extractor.sh b/sources/__env_extractor.sh index 333452d..8cf2d78 100644 --- a/sources/__env_extractor.sh +++ b/sources/__env_extractor.sh @@ -17,16 +17,10 @@ function __env_extractor { if [[ $1 =~ ^$TRIGGER_TAG_PREFIX(.+)/$TRIGGER_TAG_SUFIX_REGEX$ ]]; then paths="${BASH_REMATCH[1]}" - + # Split the captured paths into individual words IFS='/' read -ra words <<< "$paths" - - for env in "${words[@]}"; do - ENVIRONMENTS+="$env"$'\n' - done - - # Remove last empty line - echo "$ENVIRONMENTS" + echo "$(IFS=$'\n'; echo "${words[*]}")" else echo echo "Incorrect input value." From 0d760867842d7a536ca78745c23dcef8efa247ac Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Tue, 10 Dec 2024 13:03:32 +0100 Subject: [PATCH 19/39] Add exit codes --- app-deploy.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app-deploy.sh b/app-deploy.sh index 7b360fa..210f156 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -70,14 +70,18 @@ function main { if [ "$1" == '--update' ] ; then __clear_console __script_auto_update + exit 0 elif [ "$1" == 'init' ] ; then __clear_console __init + exit 0 elif [ -z "$1" ] || [ "$1" == 'trigger' ] ; then # Empty input or "trigger" __clear_console main + exit 0 elif [ "$1" == 'environments' ] ; then - echo $(__env_extractor "$2") + __env_extractor "$2" + exit 0 else echo echo "Unsuported command!" From aa4b7643e16e78ce1d0daa7d1b4eef258f1ab66a Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Tue, 10 Dec 2024 13:26:56 +0100 Subject: [PATCH 20/39] Include deploy options only if file exists --- app-deploy.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app-deploy.sh b/app-deploy.sh index 210f156..ee1744b 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash -source ./.deploy-options.sh +if [ -f ./.deploy-options.sh ]; then + source ./.deploy-options.sh +fi source /usr/local/bin/.app-deploy-sources/__constants.sh source /usr/local/bin/.app-deploy-sources/__auto_update.sh source /usr/local/bin/.app-deploy-sources/__init.sh From d4be6ede43359c0b00299bb518b54ba4fd9c7cf6 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Tue, 10 Dec 2024 14:54:15 +0100 Subject: [PATCH 21/39] Add logs --- app-deploy.sh | 3 +++ sources/__env_extractor.sh | 2 ++ 2 files changed, 5 insertions(+) diff --git a/app-deploy.sh b/app-deploy.sh index ee1744b..459fd2e 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -69,6 +69,8 @@ function main { # START EVERYTHING # ################################# +echo "STARD SCRIPT" + if [ "$1" == '--update' ] ; then __clear_console __script_auto_update @@ -82,6 +84,7 @@ elif [ -z "$1" ] || [ "$1" == 'trigger' ] ; then # Empty input or "trigger" main exit 0 elif [ "$1" == 'environments' ] ; then + echo "EXTRACT ENV" __env_extractor "$2" exit 0 else diff --git a/sources/__env_extractor.sh b/sources/__env_extractor.sh index 8cf2d78..15689a1 100644 --- a/sources/__env_extractor.sh +++ b/sources/__env_extractor.sh @@ -6,6 +6,8 @@ source /usr/local/bin/.app-deploy-sources/__constants.sh function __env_extractor { + echo "ENV EXTRACTOR CALLED" + # Check if input is valid if [ -z "$1" ] ; then echo "Missing input value!" From 95b094981bf81de2d6ef8aaa29eff9b8bdcbe9f0 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Tue, 10 Dec 2024 15:07:54 +0100 Subject: [PATCH 22/39] Fix text formatting --- app-deploy.sh | 54 +++---------------------------------- sources/__env_extractor.sh | 2 -- sources/__trigger_deploy.sh | 41 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 52 deletions(-) create mode 100644 sources/__trigger_deploy.sh diff --git a/app-deploy.sh b/app-deploy.sh index 459fd2e..38fabe4 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash -if [ -f ./.deploy-options.sh ]; then +if [ -z "$1" ] || [ "$1" == 'trigger' ] ; then source ./.deploy-options.sh + source /usr/local/bin/.app-deploy-sources/__trigger_deploy.sh fi source /usr/local/bin/.app-deploy-sources/__constants.sh source /usr/local/bin/.app-deploy-sources/__auto_update.sh @@ -24,72 +25,25 @@ source /usr/local/bin/.app-deploy-sources/__env_extractor.sh # Use global variables at your own risk as this can be overridden in the future. set -e -bold=$(tput bold) -normal=$(tput sgr0) - -################################# -# MAIN # -################################# - -# Private part of the script... -# -# In general, you don't have to edit -# this part of the script but feel free -# to edit any part of it as suits your needs. - -function main { - - __header_print - - # BASE INFO - # commit, tag, synced head,... - __initial_checkup - - # CREATE TAG - - deploy_options # Get from .deploy-options.sh, setup per project - __input_to_tags - - if [ -z "$script_version" ] || [ "$script_version" == "v1" ]; then - __create_app_version_and_build_number - elif [ "$script_version" == "v2" ]; then - __create_trigger_ci_timestamp_tag - fi - - # CREATE CHANGELOG - - __generate_tag_and_changelog - - # DEPLOY - - __push_tag_and_start_deploy -} ################################# # START EVERYTHING # ################################# -echo "STARD SCRIPT" - if [ "$1" == '--update' ] ; then __clear_console __script_auto_update - exit 0 elif [ "$1" == 'init' ] ; then __clear_console __init - exit 0 elif [ -z "$1" ] || [ "$1" == 'trigger' ] ; then # Empty input or "trigger" __clear_console - main - exit 0 + __trigger_deploy elif [ "$1" == 'environments' ] ; then - echo "EXTRACT ENV" __env_extractor "$2" - exit 0 else echo echo "Unsuported command!" echo - exit 0 + exit 29 fi diff --git a/sources/__env_extractor.sh b/sources/__env_extractor.sh index 15689a1..8cf2d78 100644 --- a/sources/__env_extractor.sh +++ b/sources/__env_extractor.sh @@ -6,8 +6,6 @@ source /usr/local/bin/.app-deploy-sources/__constants.sh function __env_extractor { - echo "ENV EXTRACTOR CALLED" - # Check if input is valid if [ -z "$1" ] ; then echo "Missing input value!" diff --git a/sources/__trigger_deploy.sh b/sources/__trigger_deploy.sh new file mode 100644 index 0000000..4159ae2 --- /dev/null +++ b/sources/__trigger_deploy.sh @@ -0,0 +1,41 @@ + +################################# +# DEPLOYMENT TRIGGER TAG # +################################# + +# Private part of the script... +# +# In general, you don't have to edit +# this part of the script but feel free +# to edit any part of it as suits your needs. + +bold=$(tput bold) +normal=$(tput sgr0) + +function __trigger_deploy { + + __header_print + + # BASE INFO + # commit, tag, synced head,... + __initial_checkup + + # CREATE TAG + + deploy_options # Get from .deploy-options.sh, setup per project + __input_to_tags + + if [ -z "$script_version" ] || [ "$script_version" == "v1" ]; then + __create_app_version_and_build_number + elif [ "$script_version" == "v2" ]; then + __create_trigger_ci_timestamp_tag + fi + + # CREATE CHANGELOG + + __generate_tag_and_changelog + + # DEPLOY + + __push_tag_and_start_deploy +} \ No newline at end of file From 58882e1829212060ddab66e8e42645789a505657 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Tue, 10 Dec 2024 16:52:39 +0100 Subject: [PATCH 23/39] Add "tagging" parameter; Add input options and options validation logic --- app-deploy.sh | 3 +++ sources/__build_tagging.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 sources/__build_tagging.sh diff --git a/app-deploy.sh b/app-deploy.sh index 38fabe4..a60dd7d 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -11,6 +11,7 @@ source /usr/local/bin/.app-deploy-sources/__initial_checkup.sh source /usr/local/bin/.app-deploy-sources/__base_tag_handling.sh source /usr/local/bin/.app-deploy-sources/__deploy_tags.sh source /usr/local/bin/.app-deploy-sources/__env_extractor.sh +source /usr/local/bin/.app-deploy-sources/__build_tagging.sh ############################################################### # DEPLOY SCRIPT # @@ -41,6 +42,8 @@ elif [ -z "$1" ] || [ "$1" == 'trigger' ] ; then # Empty input or "trigger" __trigger_deploy elif [ "$1" == 'environments' ] ; then __env_extractor "$2" +elif [ "$1" == 'tagging' ]; then + __build_tagging "$@" else echo echo "Unsuported command!" diff --git a/sources/__build_tagging.sh b/sources/__build_tagging.sh new file mode 100644 index 0000000..55bf310 --- /dev/null +++ b/sources/__build_tagging.sh @@ -0,0 +1,27 @@ + +function __build_tagging { + + __validate_options "$@" + +} + +function __validate_options { + shift + + while getopts "e:p:v:" opt; do + case "$opt" in + e) ENVIRONMENT="$OPTARG" ;; + p) APP_PATH="$OPTARG" ;; + v) BUILD_VERSION="$OPTARG" ;; + *) echo "Error: Invalid option"; exit 1 ;; + esac + done + + # Check if all mandatory options are provided + if [[ -z "$ENVIRONMENT" || -z "$APP_PATH" || -z "$BUILD_VERSION" ]]; then + echo "Error: Missing mandatory options." + echo "Usage: app-deploy tagging -e \"environment_name\" -p \"path/to/app.{ipa/apk}\" -v \"{build number}\"" + echo "Example: app-deploy tagging -e \"internal-staging\" -p \"path/to/app.ipa\" -v \"42\"" + exit 1 + fi +} \ No newline at end of file From 4f65b1d82a015d0866082b8260e0ffe7165eb2d2 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Tue, 10 Dec 2024 17:26:05 +0100 Subject: [PATCH 24/39] Get app platform from app name extension --- sources/__build_tagging.sh | 41 ++++++++++++++++++++++++++++++ sources/__build_tagging_android.sh | 13 ++++++++++ sources/__build_tagging_ios.sh | 8 ++++++ sources/__constants.sh | 5 +++- 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 sources/__build_tagging_android.sh create mode 100644 sources/__build_tagging_ios.sh diff --git a/sources/__build_tagging.sh b/sources/__build_tagging.sh index 55bf310..b31d288 100644 --- a/sources/__build_tagging.sh +++ b/sources/__build_tagging.sh @@ -1,10 +1,41 @@ +source /usr/local/bin/.app-deploy-sources/__constants.sh +source /usr/local/bin/.app-deploy-sources/__build_tagging_ios.sh +source /usr/local/bin/.app-deploy-sources/__build_tagging_android.sh + +################################# +# CREATE BUILD TAG # +################################# + +# Main logic function __build_tagging { __validate_options "$@" + + echo "Env -> $ENVIRONMENT" + echo "Path -> $APP_PATH" + echo "Build version -> $BUILD_VERSION" + + APP_PLATFORM=$(__check_platform) + + if [ "$APP_PLATFORM" == "$PLATFORM_ANDROID_APK" ]; then + __generate_app_version_from_apk "$APP_PATH" + elif [ "$APP_PLATFORM" == "$PLATFORM_ANDROID_AAB" ]; then + __generate_app_version_from_aab "$APP_PATH" + elif [ "$APP_PLATFORM" == "$PLATFORM_IOS" ]; then + __generate_app_version_from_ipa "$APP_PATH" + else + echo + echo "Unsupported file format: ${APP_PATH##*.}" + echo "Please use only supported file formats: apk, aab, or ipa" + echo + exit 1 + fi } +# Validation and checks + function __validate_options { shift @@ -24,4 +55,14 @@ function __validate_options { echo "Example: app-deploy tagging -e \"internal-staging\" -p \"path/to/app.ipa\" -v \"42\"" exit 1 fi +} + +function __check_platform { + if [ ${APP_PATH##*.} == "ipa" ]; then + echo $PLATFORM_IOS + elif [ ${APP_PATH##*.} == "apk" ]; then + echo $PLATFORM_ANDROID_APK + elif [ ${APP_PATH##*.} == "aab" ]; then + echo $PLATFORM_ANDROID_AAB + fi } \ No newline at end of file diff --git a/sources/__build_tagging_android.sh b/sources/__build_tagging_android.sh new file mode 100644 index 0000000..366b679 --- /dev/null +++ b/sources/__build_tagging_android.sh @@ -0,0 +1,13 @@ +################################# +# EXTRACT DATA FROM APK/AAB # +################################# + +function __generate_app_version_from_apk { + # TODO + echo "ANDROID APK from $1" +} + +function __generate_app_version_from_aab { + # TODO + echo "ANDROID AAB from $1" +} \ No newline at end of file diff --git a/sources/__build_tagging_ios.sh b/sources/__build_tagging_ios.sh new file mode 100644 index 0000000..ec68538 --- /dev/null +++ b/sources/__build_tagging_ios.sh @@ -0,0 +1,8 @@ +################################# +# EXTRACT DATA FROM IPA # +################################# + +function __generate_app_version_from_ipa { + # TODO + echo "IOS from $1" +} \ No newline at end of file diff --git a/sources/__constants.sh b/sources/__constants.sh index ee0275e..5d2885e 100644 --- a/sources/__constants.sh +++ b/sources/__constants.sh @@ -19,4 +19,7 @@ function __clear_console { } TRIGGER_TAG_PREFIX="ci/" TRIGGER_TAG_SUFIX="$(date +%Y-%m-%dT%H-%M-%S)" -TRIGGER_TAG_SUFIX_REGEX=([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2}) \ No newline at end of file +TRIGGER_TAG_SUFIX_REGEX=([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2}) +PLATFORM_ANDROID_APK="platform_android_apk" +PLATFORM_ANDROID_AAB="platform_android_aab" +PLATFORM_IOS="platform_ios" \ No newline at end of file From 4ad89067d546880e3b9768fba91abf51d055d5c5 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Tue, 10 Dec 2024 17:50:37 +0100 Subject: [PATCH 25/39] Extract app version from ipa file --- sources/__build_tagging.sh | 8 ++++++-- sources/__build_tagging_ios.sh | 20 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/sources/__build_tagging.sh b/sources/__build_tagging.sh index b31d288..3817f8b 100644 --- a/sources/__build_tagging.sh +++ b/sources/__build_tagging.sh @@ -17,14 +17,15 @@ function __build_tagging { echo "Path -> $APP_PATH" echo "Build version -> $BUILD_VERSION" - APP_PLATFORM=$(__check_platform) + APP_VERSION="" + APP_PLATFORM=$(__check_platform) if [ "$APP_PLATFORM" == "$PLATFORM_ANDROID_APK" ]; then __generate_app_version_from_apk "$APP_PATH" elif [ "$APP_PLATFORM" == "$PLATFORM_ANDROID_AAB" ]; then __generate_app_version_from_aab "$APP_PATH" elif [ "$APP_PLATFORM" == "$PLATFORM_IOS" ]; then - __generate_app_version_from_ipa "$APP_PATH" + APP_VERSION=$(__generate_app_version_from_ipa "$APP_PATH") else echo echo "Unsupported file format: ${APP_PATH##*.}" @@ -32,6 +33,9 @@ function __build_tagging { echo exit 1 fi + + echo "Tag:" + echo "${ENVIRONMENT}/${APP_VERSION}b${BUILD_VERSION}" } # Validation and checks diff --git a/sources/__build_tagging_ios.sh b/sources/__build_tagging_ios.sh index ec68538..9a8b8ff 100644 --- a/sources/__build_tagging_ios.sh +++ b/sources/__build_tagging_ios.sh @@ -3,6 +3,22 @@ ################################# function __generate_app_version_from_ipa { - # TODO - echo "IOS from $1" + + # Get file names + APP_PATH=$1 + FILE_NAME=$(basename $APP_PATH) + + # Unzip ipa file + unzip -q $APP_PATH -d .tmp + + # Read info .plist + INFO_PLIST=.tmp/Payload/**/Info.plist + + APP_VERSION=$(plutil -extract CFBundleShortVersionString xml1 -o - $INFO_PLIST | sed -n 's/.*\(.*\)<\/string>.*/\1/p') + BUILD_NUMBER=$(plutil -extract CFBundleVersion xml1 -o - $INFO_PLIST | sed -n 's/.*\(.*\)<\/string>.*/\1/p') + + # Remove tmp files + rm -rf .tmp + + echo "$APP_VERSION-$BUILD_NUMBER" } \ No newline at end of file From d2bcb5d0a6a8521587ad6712714dad420fd82691 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Tue, 10 Dec 2024 18:10:15 +0100 Subject: [PATCH 26/39] Get script from next branch --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 81e21c8..021ebc7 100755 --- a/install.sh +++ b/install.sh @@ -38,7 +38,7 @@ else fi # Get install files -git clone --quiet https://github.com/infinum/app-deploy-script.git --branch feature/v2/environments-export .app_deploy_tmp +git clone --quiet https://github.com/infinum/app-deploy-script.git --branch feature/v2/build-tag-creation .app_deploy_tmp echo "Installing..." # Move main script to bin folder From 6c52158a8dbcf29edbfffcc0c6c215ce5b3c6fce Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Tue, 10 Dec 2024 18:32:58 +0100 Subject: [PATCH 27/39] Update tag format --- sources/__build_tagging.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/__build_tagging.sh b/sources/__build_tagging.sh index 3817f8b..7671e75 100644 --- a/sources/__build_tagging.sh +++ b/sources/__build_tagging.sh @@ -35,7 +35,7 @@ function __build_tagging { fi echo "Tag:" - echo "${ENVIRONMENT}/${APP_VERSION}b${BUILD_VERSION}" + echo "${ENVIRONMENT}/v${APP_VERSION}b${BUILD_VERSION}" } # Validation and checks From 64edccbc6f8877c79018b54bd98a340f0d752692 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Wed, 11 Dec 2024 15:33:30 +0100 Subject: [PATCH 28/39] Add support for android parsing --- sources/__build_tagging.sh | 8 ++++---- sources/__build_tagging_android.sh | 22 ++++++++++++++++++---- sources/__build_tagging_ios.sh | 5 +++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/sources/__build_tagging.sh b/sources/__build_tagging.sh index 7671e75..79ad588 100644 --- a/sources/__build_tagging.sh +++ b/sources/__build_tagging.sh @@ -21,11 +21,11 @@ function __build_tagging { APP_PLATFORM=$(__check_platform) if [ "$APP_PLATFORM" == "$PLATFORM_ANDROID_APK" ]; then - __generate_app_version_from_apk "$APP_PATH" + APP_VERSION=$(__generate_app_version_from_apk "$APP_PATH" "$BUILD_VERSION") elif [ "$APP_PLATFORM" == "$PLATFORM_ANDROID_AAB" ]; then - __generate_app_version_from_aab "$APP_PATH" + APP_VERSION=$(__generate_app_version_from_aab "$APP_PATH" "$BUILD_VERSION") elif [ "$APP_PLATFORM" == "$PLATFORM_IOS" ]; then - APP_VERSION=$(__generate_app_version_from_ipa "$APP_PATH") + APP_VERSION=$(__generate_app_version_from_ipa "$APP_PATH" "$BUILD_VERSION") else echo echo "Unsupported file format: ${APP_PATH##*.}" @@ -35,7 +35,7 @@ function __build_tagging { fi echo "Tag:" - echo "${ENVIRONMENT}/v${APP_VERSION}b${BUILD_VERSION}" + echo "${ENVIRONMENT}/v${APP_VERSION}" } # Validation and checks diff --git a/sources/__build_tagging_android.sh b/sources/__build_tagging_android.sh index 366b679..0d0b843 100644 --- a/sources/__build_tagging_android.sh +++ b/sources/__build_tagging_android.sh @@ -3,11 +3,25 @@ ################################# function __generate_app_version_from_apk { - # TODO - echo "ANDROID APK from $1" + CI_BUILD_NUMBER=$2 + APK_MANIFEST=$(aapt dump badging $1) + VERSION_NAME=$(echo "$APK_MANIFEST" | sed -n "s/.*versionName='\([^']*\).*/\1/p") + VERSION_CODE=$(echo "$APK_MANIFEST" | sed -n "s/.*versionCode='\([^']*\).*/\1/p") + echo "${VERSION_NAME}b${CI_BUILD_NUMBER}c${VERSION_CODE}" } function __generate_app_version_from_aab { - # TODO - echo "ANDROID AAB from $1" + temp_path=$PWD + bundletool="${temp_path}/bundletool.jar" + source="https://github.com/google/bundletool/releases/download/1.17.2/bundletool-all-1.17.2.jar" + + wget -q -nv "${source}" --output-document="${bundletool}" & + wait + APK_MANIFEST=$(exec java -jar "${bundletool}" dump manifest --bundle $APP_PATH & + wait) + + CI_BUILD_NUMBER=$2 + VERSION_CODE=$(echo "$APK_MANIFEST" | sed -n "s/.*versionCode=\"\([^\"]*\).*/\1/p") + VERSION_NAME=$(echo "$APK_MANIFEST" | sed -n "s/.*versionName=\"\([^\"]*\).*/\1/p") + echo "${VERSION_NAME}b${CI_BUILD_NUMBER}c${VERSION_CODE}" } \ No newline at end of file diff --git a/sources/__build_tagging_ios.sh b/sources/__build_tagging_ios.sh index 9a8b8ff..4d724af 100644 --- a/sources/__build_tagging_ios.sh +++ b/sources/__build_tagging_ios.sh @@ -6,6 +6,7 @@ function __generate_app_version_from_ipa { # Get file names APP_PATH=$1 + CI_BUILD_NUMBER=$2 FILE_NAME=$(basename $APP_PATH) # Unzip ipa file @@ -15,10 +16,10 @@ function __generate_app_version_from_ipa { INFO_PLIST=.tmp/Payload/**/Info.plist APP_VERSION=$(plutil -extract CFBundleShortVersionString xml1 -o - $INFO_PLIST | sed -n 's/.*\(.*\)<\/string>.*/\1/p') - BUILD_NUMBER=$(plutil -extract CFBundleVersion xml1 -o - $INFO_PLIST | sed -n 's/.*\(.*\)<\/string>.*/\1/p') + APP_BUILD_NUMBER=$(plutil -extract CFBundleVersion xml1 -o - $INFO_PLIST | sed -n 's/.*\(.*\)<\/string>.*/\1/p') # Remove tmp files rm -rf .tmp - echo "$APP_VERSION-$BUILD_NUMBER" + echo "${APP_VERSION}-${APP_BUILD_NUMBER}b${CI_BUILD_NUMBER}" } \ No newline at end of file From 252374f4b651617451cf4016ee2f85aa614917b8 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Wed, 11 Dec 2024 15:47:39 +0100 Subject: [PATCH 29/39] Add changelog option; Push tag --- sources/__build_tagging.sh | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/sources/__build_tagging.sh b/sources/__build_tagging.sh index 79ad588..e581179 100644 --- a/sources/__build_tagging.sh +++ b/sources/__build_tagging.sh @@ -12,13 +12,7 @@ function __build_tagging { __validate_options "$@" - - echo "Env -> $ENVIRONMENT" - echo "Path -> $APP_PATH" - echo "Build version -> $BUILD_VERSION" - APP_VERSION="" - APP_PLATFORM=$(__check_platform) if [ "$APP_PLATFORM" == "$PLATFORM_ANDROID_APK" ]; then APP_VERSION=$(__generate_app_version_from_apk "$APP_PATH" "$BUILD_VERSION") @@ -34,8 +28,10 @@ function __build_tagging { exit 1 fi - echo "Tag:" - echo "${ENVIRONMENT}/v${APP_VERSION}" + CHANGELOG=${CHANGELOG:-""} # Set empty string if changelog is not available + TAG="${ENVIRONMENT}/v${APP_VERSION}" + git tag -a "$TAG" -m "${CHANGELOG}" + git push origin "$TAG" } # Validation and checks @@ -43,11 +39,12 @@ function __build_tagging { function __validate_options { shift - while getopts "e:p:v:" opt; do + while getopts "e:p:v:c:" opt; do case "$opt" in e) ENVIRONMENT="$OPTARG" ;; p) APP_PATH="$OPTARG" ;; v) BUILD_VERSION="$OPTARG" ;; + c) CHANGELOG="$OPTARG" ;; *) echo "Error: Invalid option"; exit 1 ;; esac done From 0349ce39d11994f0469e4433e624cb6c488f5a5a Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Thu, 12 Dec 2024 15:22:43 +0100 Subject: [PATCH 30/39] Change --- sources/__build_tagging.sh | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/sources/__build_tagging.sh b/sources/__build_tagging.sh index e581179..67b4e76 100644 --- a/sources/__build_tagging.sh +++ b/sources/__build_tagging.sh @@ -15,11 +15,11 @@ function __build_tagging { APP_VERSION="" APP_PLATFORM=$(__check_platform) if [ "$APP_PLATFORM" == "$PLATFORM_ANDROID_APK" ]; then - APP_VERSION=$(__generate_app_version_from_apk "$APP_PATH" "$BUILD_VERSION") + APP_VERSION=$(__generate_app_version_from_apk "$APP_PATH" "$BUILD_COUNT") elif [ "$APP_PLATFORM" == "$PLATFORM_ANDROID_AAB" ]; then - APP_VERSION=$(__generate_app_version_from_aab "$APP_PATH" "$BUILD_VERSION") + APP_VERSION=$(__generate_app_version_from_aab "$APP_PATH" "$BUILD_COUNT") elif [ "$APP_PLATFORM" == "$PLATFORM_IOS" ]; then - APP_VERSION=$(__generate_app_version_from_ipa "$APP_PATH" "$BUILD_VERSION") + APP_VERSION=$(__generate_app_version_from_ipa "$APP_PATH" "$BUILD_COUNT") else echo echo "Unsupported file format: ${APP_PATH##*.}" @@ -28,8 +28,20 @@ function __build_tagging { exit 1 fi + __create_and_push_tag +} + +# Tag creation & push + +function __create_and_push_tag { + + # If there is a custom app version passed, append build number to it + if [[ -n "$CUSTOM_APP_VERSION" ]]; then + CUSTOM_APP_VERSION="${CUSTOM_APP_VERSION}b${BUILD_COUNT}" + fi + CHANGELOG=${CHANGELOG:-""} # Set empty string if changelog is not available - TAG="${ENVIRONMENT}/v${APP_VERSION}" + TAG="${ENVIRONMENT}/v${CUSTOM_APP_VERSION:-$APP_VERSION}" git tag -a "$TAG" -m "${CHANGELOG}" git push origin "$TAG" } @@ -39,21 +51,22 @@ function __build_tagging { function __validate_options { shift - while getopts "e:p:v:c:" opt; do + while getopts "e:p:b:v:c:" opt; do case "$opt" in e) ENVIRONMENT="$OPTARG" ;; p) APP_PATH="$OPTARG" ;; - v) BUILD_VERSION="$OPTARG" ;; + b) BUILD_COUNT="$OPTARG" ;; + v) CUSTOM_APP_VERSION="$OPTARG" ;; c) CHANGELOG="$OPTARG" ;; *) echo "Error: Invalid option"; exit 1 ;; esac done # Check if all mandatory options are provided - if [[ -z "$ENVIRONMENT" || -z "$APP_PATH" || -z "$BUILD_VERSION" ]]; then + if [[ -z "$ENVIRONMENT" || -z "$APP_PATH" || -z "$BUILD_COUNT" ]]; then echo "Error: Missing mandatory options." - echo "Usage: app-deploy tagging -e \"environment_name\" -p \"path/to/app.{ipa/apk}\" -v \"{build number}\"" - echo "Example: app-deploy tagging -e \"internal-staging\" -p \"path/to/app.ipa\" -v \"42\"" + echo "Usage: app-deploy tagging -e \"environment_name\" -p \"path/to/app.{ipa/apk}\" -b \"{build count}\"" + echo "Example: app-deploy tagging -e \"internal-staging\" -p \"path/to/app.ipa\" -b \"42\"" exit 1 fi } From 213eed912c801b190031bcff2b1bfffd927fe82f Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Thu, 12 Dec 2024 15:36:43 +0100 Subject: [PATCH 31/39] Add support for other file types (e.g. zip) --- sources/__build_tagging.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sources/__build_tagging.sh b/sources/__build_tagging.sh index 67b4e76..9a897a9 100644 --- a/sources/__build_tagging.sh +++ b/sources/__build_tagging.sh @@ -20,10 +20,11 @@ function __build_tagging { APP_VERSION=$(__generate_app_version_from_aab "$APP_PATH" "$BUILD_COUNT") elif [ "$APP_PLATFORM" == "$PLATFORM_IOS" ]; then APP_VERSION=$(__generate_app_version_from_ipa "$APP_PATH" "$BUILD_COUNT") - else + elif [[ ! -n "$CUSTOM_APP_VERSION" ]]; then echo echo "Unsupported file format: ${APP_PATH##*.}" - echo "Please use only supported file formats: apk, aab, or ipa" + echo "If unsupported file format is used (i.e., none of apk, aab, or ipa)," + echo "you have to define the custom app version (option -v)." echo exit 1 fi From 70c7bd73589b07d6ea1dba7e83bbe2d0bdab1eda Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Thu, 12 Dec 2024 16:02:44 +0100 Subject: [PATCH 32/39] Update install branch; Minor files changes --- app-deploy.sh | 3 --- install.sh | 2 +- sources/__build_tagging.sh | 4 ++-- sources/__trigger_deploy.sh | 3 +++ sources/{ => helpers}/__base_tag_handling.sh | 0 sources/{ => helpers}/__build_tagging_android.sh | 0 sources/{ => helpers}/__build_tagging_ios.sh | 0 sources/{ => helpers}/__deploy_tags.sh | 0 sources/{ => helpers}/__initial_checkup.sh | 0 9 files changed, 6 insertions(+), 6 deletions(-) rename sources/{ => helpers}/__base_tag_handling.sh (100%) rename sources/{ => helpers}/__build_tagging_android.sh (100%) rename sources/{ => helpers}/__build_tagging_ios.sh (100%) rename sources/{ => helpers}/__deploy_tags.sh (100%) rename sources/{ => helpers}/__initial_checkup.sh (100%) diff --git a/app-deploy.sh b/app-deploy.sh index a60dd7d..2eb8047 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -7,9 +7,6 @@ fi source /usr/local/bin/.app-deploy-sources/__constants.sh source /usr/local/bin/.app-deploy-sources/__auto_update.sh source /usr/local/bin/.app-deploy-sources/__init.sh -source /usr/local/bin/.app-deploy-sources/__initial_checkup.sh -source /usr/local/bin/.app-deploy-sources/__base_tag_handling.sh -source /usr/local/bin/.app-deploy-sources/__deploy_tags.sh source /usr/local/bin/.app-deploy-sources/__env_extractor.sh source /usr/local/bin/.app-deploy-sources/__build_tagging.sh diff --git a/install.sh b/install.sh index 021ebc7..23b6430 100755 --- a/install.sh +++ b/install.sh @@ -38,7 +38,7 @@ else fi # Get install files -git clone --quiet https://github.com/infinum/app-deploy-script.git --branch feature/v2/build-tag-creation .app_deploy_tmp +git clone --quiet https://github.com/infinum/app-deploy-script.git --branch feature/v2/help-readme .app_deploy_tmp echo "Installing..." # Move main script to bin folder diff --git a/sources/__build_tagging.sh b/sources/__build_tagging.sh index 9a897a9..bdddec8 100644 --- a/sources/__build_tagging.sh +++ b/sources/__build_tagging.sh @@ -1,6 +1,6 @@ source /usr/local/bin/.app-deploy-sources/__constants.sh -source /usr/local/bin/.app-deploy-sources/__build_tagging_ios.sh -source /usr/local/bin/.app-deploy-sources/__build_tagging_android.sh +source /usr/local/bin/.app-deploy-sources/helpers/__build_tagging_ios.sh +source /usr/local/bin/.app-deploy-sources/helpers/__build_tagging_android.sh ################################# # CREATE BUILD TAG # diff --git a/sources/__trigger_deploy.sh b/sources/__trigger_deploy.sh index 4159ae2..94bbdb4 100644 --- a/sources/__trigger_deploy.sh +++ b/sources/__trigger_deploy.sh @@ -1,3 +1,6 @@ +source /usr/local/bin/.app-deploy-sources/helpers/__base_tag_handling.sh +source /usr/local/bin/.app-deploy-sources/helpers/__deploy_tags.sh +source /usr/local/bin/.app-deploy-sources/helpers/__initial_checkup.sh ################################# # DEPLOYMENT TRIGGER TAG # diff --git a/sources/__base_tag_handling.sh b/sources/helpers/__base_tag_handling.sh similarity index 100% rename from sources/__base_tag_handling.sh rename to sources/helpers/__base_tag_handling.sh diff --git a/sources/__build_tagging_android.sh b/sources/helpers/__build_tagging_android.sh similarity index 100% rename from sources/__build_tagging_android.sh rename to sources/helpers/__build_tagging_android.sh diff --git a/sources/__build_tagging_ios.sh b/sources/helpers/__build_tagging_ios.sh similarity index 100% rename from sources/__build_tagging_ios.sh rename to sources/helpers/__build_tagging_ios.sh diff --git a/sources/__deploy_tags.sh b/sources/helpers/__deploy_tags.sh similarity index 100% rename from sources/__deploy_tags.sh rename to sources/helpers/__deploy_tags.sh diff --git a/sources/__initial_checkup.sh b/sources/helpers/__initial_checkup.sh similarity index 100% rename from sources/__initial_checkup.sh rename to sources/helpers/__initial_checkup.sh From 283a7cb2d8e4a596a6e51dfaf755a009ea709eb4 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Thu, 12 Dec 2024 16:34:42 +0100 Subject: [PATCH 33/39] Add help --- app-deploy.sh | 7 +++++-- sources/__help.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 sources/__help.sh diff --git a/app-deploy.sh b/app-deploy.sh index 2eb8047..979ce54 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -1,10 +1,11 @@ #!/usr/bin/env bash +source /usr/local/bin/.app-deploy-sources/__constants.sh +source /usr/local/bin/.app-deploy-sources/__help.sh if [ -z "$1" ] || [ "$1" == 'trigger' ] ; then source ./.deploy-options.sh source /usr/local/bin/.app-deploy-sources/__trigger_deploy.sh fi -source /usr/local/bin/.app-deploy-sources/__constants.sh source /usr/local/bin/.app-deploy-sources/__auto_update.sh source /usr/local/bin/.app-deploy-sources/__init.sh source /usr/local/bin/.app-deploy-sources/__env_extractor.sh @@ -28,7 +29,9 @@ set -e # START EVERYTHING # ################################# -if [ "$1" == '--update' ] ; then +if [ "$1" == '--help' ] ; then + __help +elif [ "$1" == '--update' ] ; then __clear_console __script_auto_update elif [ "$1" == 'init' ] ; then diff --git a/sources/__help.sh b/sources/__help.sh new file mode 100644 index 0000000..030e917 --- /dev/null +++ b/sources/__help.sh @@ -0,0 +1,49 @@ +################ +# HELP # +################ + +function __help { + cat << EOF +Usage: app-deploy [OPTION] [ARGUMENTS] + +A group of scripts and tools designed to assist in the deployment process. This script can: + - Initialize deploy options. + - Create trigger tag for CI/CD. + - Extract environments from a trigger tag. + - Generate a final build tag after CI/CD deployment. + +Parameters: + --update Update the script to the latest version. + init Initialize the deploy-options file for the project. + trigger Generate a trigger tag for starting the CI/CD flow. + environments + Extract environments from the specified trigger tag. + tagging Generate a build tag after CI/CD uploads the build. + Accepts the following options: + -e Specify the environment to use as a tag prefix (e.g., internal-staging). + -p Path to the file from which app version, build number, etc., will be extracted. + Supported formats: ipa, apk, aab. + Use in combination with -v for unsupported formats (e.g. zip). + -b Specify the build count, usually the CI/CD counter. + -v Optional: Override the app version extracted from the file. + Useful for unsupported formats. + -c Optional: Add a changelog to the release tag. + +Examples: + 1. Initialize deploy options: + app-deploy init + + 2. Generate a trigger tag: + app-deploy or app-deploy trigger + output: ci/internal-staging/2024-12-12T14-32 + + 3. Extract environments from a trigger tag: + app-deploy environments ci/internal-staging/2024-12-12T14-32 + output: internal-staging + + 4. Generate a final build tag: + app-deploy tagging -e "internal-staging" -p "path/to/my-app.ipa" -b "123" -c "Added new features" + output: internal-staging/v1.2.3-44b123 + +EOF +} \ No newline at end of file From c05700babcdb486014b9b0db7d4fa2383ac3edec Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Mon, 16 Dec 2024 12:24:48 +0100 Subject: [PATCH 34/39] Update README; Add additional supporting OSS files --- CODE_OF_CONDUCT.md | 74 ++++++++++++++++++ CONTRIBUTING.md | 52 ++++++++++++ LICENSE | 4 +- README.md | 191 +++++++++++++++++++++++++++++++-------------- SECURITY.md | 19 +++++ 5 files changed, 281 insertions(+), 59 deletions(-) create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 SECURITY.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..ea88b65 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,74 @@ +# Code of conduct + +## Our pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at opensource@infinum.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 1.4, +available [here](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html). + +For answers to common questions about this code of conduct, visit +the [FAQ](https://www.contributor-covenant.org/faq) page. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..2cb209f --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,52 @@ +# Contributing guidelines + +Welcome to our project! We appreciate your interest in helping us improve it. + +## How can I contribute? + +There are multiple ways in which you can help us make this project even better. + +- Reporting bugs or suggesting new features +- Contributing code improvements or new features +- Writing, updating, or fixing tests +- Improving documentation, including inline comments, user manuals, and developer guides + +## Issue reporting + +If you found a bug or have an idea for a new feature, please open an issue. Be sure to include a clear and descriptive title, as well as a detailed description of the bug or feature. + +To avoid duplicate issues, please check if a similar issue has already been created. + +## Making changes + +To make changes to the project, please follow these steps: + +1. Fork the project repository. +2. Create a new branch for your changes, based on the project's main branch. +3. Make your changes. Ensure you've followed the coding style and standards. +4. Test your changes thoroughly, ensuring all existing tests pass and new tests cover your changes where appropriate. +5. Commit your changes with a clear and descriptive commit message. +6. Push your changes to your fork. +7. Create a pull request to the project's main branch. + +Once we check everything, we will merge the changes into the main branch and include it in the next release. + +## Guidelines for pull requests + +When submitting a pull request, please ensure that: + +- Your pull request is concise and well-scoped +- Your code is properly tested +- Your code adheres to the project's coding standards and style guidelines +- Your commit message is clear and descriptive +- Your pull request includes a description of the changes you have made and why you have made them + +Try to avoid creating large pull requests that include multiple unrelated changes. Instead, break them down into smaller, more focused pull requests. This will make it easier for us to review and merge your changes. + +## Code of conduct + +We want to ensure a welcoming environment for everyone. With that in mind, all contributors are expected to follow our [code of conduct](/CODE_OF_CONDUCT.md). + +## License + +By submitting a pull request you agree to release that code under the project's [license](/LICENSE). diff --git a/LICENSE b/LICENSE index 8c3b672..746e5f1 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2020 Infinum + Copyright 2024 Infinum Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -198,4 +198,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file + limitations under the License. diff --git a/README.md b/README.md index b3486af..23987c3 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,86 @@ # App Deploy Script -Deploy script used for creating tags with a tag message in the format `internal-all/v1.0.0-1234`, where `internal-all` is marking the workflow that should be started on the CI, `v1.2.3` represents app version and `1234` represents the build number. Tag message set from this script can be used later for the changelog message on any CI (e.g. Bitrise). The build number is number calculated as the total number of tags available on GitHub incremented by one. +## Description -## Installation +Deploy script used for creating trigger tags with a tag message in the format `ci/internal-staging/2024-12-16T10-16`, where `internal-staging` is marking the workflow that should be started on the CI. The tag message set from this script can be used later for the changelog message on any CI (e.g., Bitrise). Once the build process is finished on CI/CD and the installation file is uploaded to the deployment service (e.g., TryOut Apps), an additional script is available for creating the final build tag in format `internal-staging/v1.0.0-45b46`, where `internal-staging` is marking the build type (i.e., internal for TryOut Apps, or store for App/Play Store; staging for target/flavor type), `v1.0.0-45` represents the build version (app version, build number, ...), and `b46` that represents the unique build count on CI/CD. Optionally, on some platforms, an additional value `cXX` (e.g., `c100`) can represent the code version. + +## Table of contents + +* [Requirements](#requirements) +* [Getting started](#getting-started) +* [Usage](#usage) +* [Contributing](#contributing) +* [License](#license) +* [Credits](#credits) + +## Requirements + +To successfully push tags to the repo, the local user and/or CI/CD project should have write access to the git repository. + +## Getting started + +#### Installation + +To **install** this script, just run this command in Terminal from your home directory: -In order to install this script, just run this command in Terminal from your project root folder: ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/infinum/app-deploy-script/master/install.sh)" ``` -This script will install `app-deploy` into the `/usr/local/bin/` and `.deploy-options.sh` into the root folder of the project. -> Note: Do not change the name of the `.deploy-options.sh` file! +This script will install `app-deploy` and all the necessary components in `/usr/local/bin/`. + +Once script is installed, for local trigger tag creation, run `app-deploy init` inside the project root folder. That command will add `.deploy-options.sh` into the project's root folder. Once the file is added, update it according to your project needs. + +> Note: Do not change the name or location of the `.deploy-options.sh` file! + +#### Update + +Script can be updated by running the `--update` command. +```bash +app-deploy --update +``` +***This update will not effect `.deploy-options.sh` file.*** + +> Script commands such as `install`, and `--update` will need `sudo` to execute successfully. Use it when requested. + +## Usage +### Script modifications + +#### Main option `app-deploy init` -## Script modifications +Once `deploy-options` are generated with the `init` command, the script should be used as-is. -### Main options -In general, the script should be used as-is. +The only part that should be changed is stored inside the `.deploy-options.sh` file under the `deploy_options` function. This part of the script is responsible for creating the first part of the tag that can trigger a specific workflow on CI. If the given values are not enough or do not represent the project structure, they can be replaced with different values. -The only part that should be changed is stored inside `.deploy-options.sh` file under the `deploy_options` function. This part of the script is responsible for creating the first part of the tag that can trigger a specific workflow on CI. If the given values are not enough or they are not representing the project structure, they can be replaced with different values. +> Keep in mind that the prefix `internal-' should be used for builds created for internal testing, while builds for beta testing (e.g., Google Play Beta or Apple TestFlight) or public release should be prefixed as `beta—' or `play store`/ `app store`. -> Keep in mind that the prefix `internal-` should be used for the builds created for the internal testing, while builds for beta testing (i.e. Google Play Beta or Apple TestFlight) or public release, should be prefixed as `beta-` or `playstore`/ `appstore`. +**Final variable name inside the `deploy_options` function must stay: `target`** -**Final variable name inside `deploy_options` function must stay: `target`** +#### Configuration flags -### Configuration flags -As tag creation is separated into a few small steps, some of them can be skipped and/or disabled by changing configuration flags at the beginning of the script inside `.deploy-options.sh` file. +As tag creation is divided into several small steps, some can be skipped and/or disabled by changing configuration flags at the beginning of the script inside the `.deploy-options.sh` file. ```bash -# If enabled, console will be cleared on every script run. +# If enabled, the console will be cleared on every script run. # By default, this option is enabled use_automatic_console_clean=true -# If enabled, not pushed commits will be pushed automatically without confirmation dialog. +# If enabled, commits that are not pushed will be pushed automatically without a confirmation dialog. # By default, this option is disabled enable_automatic_commit_push=false -# If enabled, confirmation dialog with deploy summary will be presented. +# If enabled, a confirmation dialog with a deploy summary will be presented. # By default, this option is enabled enable_final_confirmation=true ``` +##### Script version +If needed, you can specify the version of the script you want to run by changing the value of the `script_version` parameter. Available options are `v1` for the old (legacy) deployment flow and `v2` for the new deployment flow. +v1 +Old deployment flow where local `app-deploy` command will generate a tag that includes and defines the app version and following build number without the `ci/` prefix (e.g.,. `internal-staging/v1.0.0-200`). -## Usage +v2 +This is a new deployment flow in which the local `app-deploy` command generates the new trigger tag described at the beginning of this readme. + +### Commands +#### Local trigger `app-deploy [optional trigger]` Script should be run just by calling the script name from the folder where `.deploy-options.sh` is stored (e.g. root folder): @@ -70,7 +112,6 @@ Targeting commit: e3e45889b The next step is selecting one or multiple targets that should be run on CI. Enter one or more numbers separated by whitespaces: ```bash - ############################################################### # DEPLOY TARGET SELECTION # ############################################################### @@ -79,37 +120,22 @@ The next step is selecting one or multiple targets that should be run on CI. Ent | TryOutApps | -------------- -[0] All -[1] Test -[2] Develop -[3] Simulation -[4] Production +[0] Test +[1] Develop +[2] Production ================== ---------------------- -| APP STORE CONNECT | ---------------------- +--------- +| STORE | +--------- -[5] App Store +[3] App Store -Enter number in square brackets: +Enter number in square brackets: 0 1 ``` -After selecting the target, the script will check the app version from the latest tag found on the current branch. The new version can be always set by typing it in the console. If the preselected version is the correct one, just hit enter and the script will continue with getting and calculating the next build number. - -```bash -############################################################### -# APP VERSION # -############################################################### - -Press enter to use last known version: 2.4.0. (or enter different version) -Getting next build number... - -Next app version is: v2.4.0-6029 -``` - -The last step is to add the changelog. When creating the tag, the console will open a preselected text editor where a changelog can be added. Keep in mind that closing that editor without entering the changelog will result in a script termination. +After selecting the target, the script will ask for the changelog. The console will open a preselected text editor where a changelog can be added. Keep in mind that closing that editor without entering the changelog will result in a script termination. ```bash ############################################################### @@ -131,9 +157,7 @@ If everything is done correctly, the confirmation step will be shown with the su --------------------------------------------------------------- ~ CONFIGURATION ~ -Target: 1. internal-test -Version: v2.4.0-6029 -Tag: internal-test/v2.4.0-6029 +Tag: ci/internal-develop/internal-test/2024-12-16T10-26 Changelog: New features: @@ -142,34 +166,87 @@ New features: * second --------------------------------------------------------------- -Is configuration correct for the CI deployment? [y/n] +Is configuration correct for the CI deployment? [y or enter / n] ``` In the end, the tag is created and pushed to the remote. -## Updating +#### Remote CI/CD build tagging `app-deploy tagging` +Once the build is deployed, you can run the `tagging` option that will read the version from the installation file (ipa, apk, aab), combined with some input options, and as output, it will generate deployed build tag (e.g., `internal-staging/v1.0.0-45b46c100`). Mandatory parameters are **e**nvironment `-e`, **p**ath to installation file `p`, and CI/CD **b**uild counter `b`: +```bash +app-deploy tagging -e "internal-staging" -p path/to/app.ipa -b $CI_COUNTER +``` +There are two optional parameters: a custom **v**ersion number that overrides one from the installation file `-v` and `-c`, which can be used to set the tag message representing the **c**hangelog. -The script has the ability to auto-update itself. To update the script, just add `--update` argument. +#### Helper command `app-deploy environments` +To help you with parsing out triggered environments from the trigger tag, you can use `app-deploy environments $TAG` command, where `$TAG` is tag used for triggering the build. Tag must be in the format used by the trigger command (i.e., `ci/env1/env2/timestamp`). ```bash -app-deploy --update +deploy environments "ci/env1/env2/timestamp" + +output: +env1 +env2 ``` -The script will fetch the latest available changes from the repo and it will change the content of the `app-deploy.sh` script with the fetched one. Keep in mind that this will result in overwrite of any changes made by you inside `app-deploy.sh` file. ***This update will not effect `.deploy-options.sh` file.*** +For example, this command could be used for mapping trigger env notation into the CI/CD workflow name: +```bash +EXTRACTED_ENVIRONMENTS=$(app-deploy environments "$CI_GIT_TAG" | tr '\n' ' ') + +# Process environments +BUILD_ENVIRONMENTS="" +IFS=$' ' read -ra environments <<< "$EXTRACTED_ENVIRONMENTS" + +# Map environment from tag to the Workflow name +for environment in "${environments[@]}"; do + if [[ $environment == 'internal-develop' ]]; then + BUILD_ENVIRONMENTS+="Development"$'\n' + elif [[ $environment == 'internal-staging' ]]; then + BUILD_ENVIRONMENTS+="Staging"$'\n' + fi +done + +# Remove empty line at the end of the list +BUILD_ENVIRONMENTS="$(echo "$BUILD_ENVIRONMENTS")" + +# Set $BUILD_ENVIRONMENTS as a global variable on CI/CD that CI can use later as a list of workflows that should be run +``` ## Contributing -Feedback and code contributions are very much welcome. Just make a pull request with a short description of your changes. By making contributions to this project you permit your code to be used under the same [license](https://github.com/infinum/app-deploy-script/blob/master/LICENSE). +We believe that the community can help us improve and build better a product. +Please refer to our [contributing guide](CONTRIBUTING.md) to learn about the types of contributions we accept and the process for submitting them. + +To ensure that our community remains respectful and professional, we defined a [code of conduct](CODE_OF_CONDUCT.md) that we expect all contributors to follow. + +We appreciate your interest and look forward to your contributions. + +## License + +```text +Copyright 2024 Infinum + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +``` ## Credits -Maintained and sponsored by -[Infinum](https://infinum.com). +Maintained and sponsored by [Infinum](https://infinum.com). -

- +

+ - -

+ +
diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..b456b29 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,19 @@ +# Security + +## Reporting security issues + +At Infinum we are committed to ensuring the security of our software. If you have discovered a security vulnerability or have concerns regarding the security of our project, we encourage you to report it to us in a responsible manner. + +If you discover a security vulnerability, please report it to us by emailing us at opensource@infinum.com. We will review your report, and if the issue is confirmed, we will work to resolve the issue as soon as possible and coordinate the release of a security patch. + +## Responsible disclosure + +We request that you practice responsible disclosure by allowing us time to investigate and address any reported vulnerabilities before making them public. We believe this approach helps protect our users and provides a better outcome for everyone involved. + +## Preferred languages + +We prefer all communication to be in English. + +## Contributions + +We greatly appreciate your help in keeping Infinum projects secure. Your efforts contribute to the ongoing improvement of our project's security. From 36ce36d6ef4879eebb7984d091c1df42c3c85b0a Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Mon, 16 Dec 2024 13:27:48 +0100 Subject: [PATCH 35/39] Add version check --- app-deploy.sh | 6 +++++- sources/__help.sh | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app-deploy.sh b/app-deploy.sh index 979ce54..5b84c7c 100755 --- a/app-deploy.sh +++ b/app-deploy.sh @@ -25,12 +25,16 @@ source /usr/local/bin/.app-deploy-sources/__build_tagging.sh # Use global variables at your own risk as this can be overridden in the future. set -e +VERSION="2.0.0" + ################################# # START EVERYTHING # ################################# -if [ "$1" == '--help' ] ; then +if [ "$1" == '-h' ] || [ "$1" == '--help' ] ; then __help +elif [ "$1" == '-v' ] || [ "$1" == '--version' ] ; then + echo "app-deploy $VERSION" elif [ "$1" == '--update' ] ; then __clear_console __script_auto_update diff --git a/sources/__help.sh b/sources/__help.sh index 030e917..952171e 100644 --- a/sources/__help.sh +++ b/sources/__help.sh @@ -13,6 +13,8 @@ A group of scripts and tools designed to assist in the deployment process. This - Generate a final build tag after CI/CD deployment. Parameters: + -v, --version Check installed script version + -h, --help Show this help and exit --update Update the script to the latest version. init Initialize the deploy-options file for the project. trigger Generate a trigger tag for starting the CI/CD flow. From 0a969b4842974af18fe8b1e72ed9aac41b23ba6c Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Mon, 16 Dec 2024 13:53:15 +0100 Subject: [PATCH 36/39] Set install/update link to main branch --- install.sh | 2 +- sources/__auto_update.sh | 29 ++++++++++++----------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/install.sh b/install.sh index 23b6430..00e30e5 100755 --- a/install.sh +++ b/install.sh @@ -38,7 +38,7 @@ else fi # Get install files -git clone --quiet https://github.com/infinum/app-deploy-script.git --branch feature/v2/help-readme .app_deploy_tmp +git clone --quiet https://github.com/infinum/app-deploy-script.git .app_deploy_tmp echo "Installing..." # Move main script to bin folder diff --git a/sources/__auto_update.sh b/sources/__auto_update.sh index 93f008e..2db0295 100644 --- a/sources/__auto_update.sh +++ b/sources/__auto_update.sh @@ -13,28 +13,23 @@ function __script_auto_update { echo "Fetching new data..." # Create temp folder - # if [ ! -d ".app_deploy_tmp" ]; then - # mkdir .app_deploy_tmp - # else - # rm -rf .app_deploy_tmp - # fi + if [ ! -d ".app_deploy_tmp" ]; then + mkdir .app_deploy_tmp + else + rm -rf .app_deploy_tmp + fi # Get new data - # git clone --quiet https://github.com/infinum/app-deploy-script.git --branch feature/v2/local-trigger .app_deploy_tmp - # echo "Updating..." + git clone --quiet https://github.com/infinum/app-deploy-script.git .app_deploy_tmp + echo "Updating..." - # # Move new data to bin / helpers - # cat .app_deploy_tmp/app-deploy.sh > /usr/local/bin/app-deploy - # cp -a .app_deploy_tmp/sources/. /usr/local/bin/.app-deploy-sources/ - - # LOCAL DEVELOPMENT - # Comment when not in use - cat /Users/jaco/Infinum/Infinum_projects/AppDeployScript/app-deploy-script/app-deploy.sh > /usr/local/bin/app-deploy - cp -a /Users/jaco/Infinum/Infinum_projects/AppDeployScript/app-deploy-script/sources/. /usr/local/bin/.app-deploy-sources/ + # Move new data to bin / helpers + cat .app_deploy_tmp/app-deploy.sh > /usr/local/bin/app-deploy + cp -a .app_deploy_tmp/sources/. /usr/local/bin/.app-deploy-sources/ # Remove temp folder - # rm -rf .app_deploy_tmp + rm -rf .app_deploy_tmp - echo "Updating finished!" + echo "Updated to $VERSION!" exit 0 } From 43d9ee141e74c4f36a5958161a53b3916b82afb2 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Mon, 13 Jan 2025 11:35:23 +0100 Subject: [PATCH 37/39] PR Fixes --- sources/__init.sh | 2 +- sources/deploy-options.sh | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sources/__init.sh b/sources/__init.sh index b7b8d0c..8c0b9b7 100644 --- a/sources/__init.sh +++ b/sources/__init.sh @@ -6,7 +6,7 @@ function __init { if [ -e "./.deploy-options.sh" ]; then echo "Options file already exists." - echo "If you continue, stored options will be overriden!" + echo "If you continue, stored options will be overridden!" echo read -r -p "Do you want to proceed? [y/n] " c if ! [[ ${c} =~ ^(yes|y|Y) ]] || [ -z ${c} ]; then diff --git a/sources/deploy-options.sh b/sources/deploy-options.sh index c2fcd9c..070db23 100644 --- a/sources/deploy-options.sh +++ b/sources/deploy-options.sh @@ -66,7 +66,9 @@ function deploy_options { echo echo "[3] App/Play Store" echo - read -r -p "Enter number in square brackets: " target_selection + echo "Enter number written in the square brackets." + echo "To run multiple targets, write multiple numbers separated by empty space (e.g. Enter targets: 0 3)" + read -r -p "Enter targets: " target_selection # Array for creating first part of the tag. # Should be in sync with options shown to the user. From 0cf81fc5e58c80ae3b8ac356b0e5dfd5fef6ae2b Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Mon, 13 Jan 2025 11:42:44 +0100 Subject: [PATCH 38/39] PR Fixes --- sources/__build_tagging_android.sh | 4 +++- sources/__constants.sh | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sources/__build_tagging_android.sh b/sources/__build_tagging_android.sh index 0d0b843..e762715 100644 --- a/sources/__build_tagging_android.sh +++ b/sources/__build_tagging_android.sh @@ -1,3 +1,5 @@ +source /usr/local/bin/.app-deploy-sources/__constants.sh + ################################# # EXTRACT DATA FROM APK/AAB # ################################# @@ -13,7 +15,7 @@ function __generate_app_version_from_apk { function __generate_app_version_from_aab { temp_path=$PWD bundletool="${temp_path}/bundletool.jar" - source="https://github.com/google/bundletool/releases/download/1.17.2/bundletool-all-1.17.2.jar" + source="https://github.com/google/bundletool/releases/download/${BUNDLE_TOOL_VERSION}/bundletool-all-1.17.2.jar" wget -q -nv "${source}" --output-document="${bundletool}" & wait diff --git a/sources/__constants.sh b/sources/__constants.sh index 5d2885e..b367040 100644 --- a/sources/__constants.sh +++ b/sources/__constants.sh @@ -22,4 +22,5 @@ TRIGGER_TAG_SUFIX="$(date +%Y-%m-%dT%H-%M-%S)" TRIGGER_TAG_SUFIX_REGEX=([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2}) PLATFORM_ANDROID_APK="platform_android_apk" PLATFORM_ANDROID_AAB="platform_android_aab" -PLATFORM_IOS="platform_ios" \ No newline at end of file +PLATFORM_IOS="platform_ios" +BUNDLE_TOOL_VERSION="1.17.2" \ No newline at end of file From 6e15c119e078f2724841e579cd3eb663ebe9e745 Mon Sep 17 00:00:00 2001 From: Jasmin Abou Aldan Date: Tue, 14 Jan 2025 13:13:13 +0100 Subject: [PATCH 39/39] PR Fixes --- README.md | 10 ++++++++-- install.sh | 4 ++-- sources/__auto_update.sh | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 23987c3..2495373 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,14 @@ # App Deploy Script -## Description +A group of scripts facilitates mobile app deployment over CI with the following features: +- Initialize deploy options +- Extract environments from a trigger tag +- Creating trigger tags for starting a specific deployment workflow on the CI +- Creating final build tags by extracting environment and version data from the trigger tag and the resulting binary. -Deploy script used for creating trigger tags with a tag message in the format `ci/internal-staging/2024-12-16T10-16`, where `internal-staging` is marking the workflow that should be started on the CI. The tag message set from this script can be used later for the changelog message on any CI (e.g., Bitrise). Once the build process is finished on CI/CD and the installation file is uploaded to the deployment service (e.g., TryOut Apps), an additional script is available for creating the final build tag in format `internal-staging/v1.0.0-45b46`, where `internal-staging` is marking the build type (i.e., internal for TryOut Apps, or store for App/Play Store; staging for target/flavor type), `v1.0.0-45` represents the build version (app version, build number, ...), and `b46` that represents the unique build count on CI/CD. Optionally, on some platforms, an additional value `cXX` (e.g., `c100`) can represent the code version. +Trigger tags use the following format: `ci/internal-staging/2024-12-16T10-16`, where `internal-staging` should match the trigger condition for starting the appropriate workflow on the CI. The tag message set from this script can be used later for the changelog message on any CI (e.g., Bitrise). + +Once the build process is finished on CI/CD and the installation file is uploaded to the deployment service, an additional script is available for creating the final build tag in format `internal-staging/v1.0.0-45b46`, where `internal-staging` is marking the build type (i.e., internal for TryOut Apps, or store for App/Play Store; staging for target/flavor type), `v1.0.0-45` represents the build version (app version, build number, ...), and `b46` that represents the unique build count on CI/CD. Optionally, an additional value, `cXX` (e.g., `c100`), can represent the code version on some platforms. ## Table of contents diff --git a/install.sh b/install.sh index 00e30e5..5fd4635 100755 --- a/install.sh +++ b/install.sh @@ -34,7 +34,7 @@ echo "Fetching script data..." if [ ! -d ".app_deploy_tmp" ]; then mkdir .app_deploy_tmp else - rm -rf .app_deploy_tmp + trap "rm -rf .app_deploy_tmp" EXIT fi # Get install files @@ -55,7 +55,7 @@ chmod +rx /usr/local/bin/app-deploy chmod +rx /usr/local/bin/.app-deploy-sources/ # Remove temp install folder -rm -rf .app_deploy_tmp +trap "rm -rf .app_deploy_tmp" EXIT echo "Done!" exit 0 diff --git a/sources/__auto_update.sh b/sources/__auto_update.sh index 2db0295..1b176e1 100644 --- a/sources/__auto_update.sh +++ b/sources/__auto_update.sh @@ -16,7 +16,7 @@ function __script_auto_update { if [ ! -d ".app_deploy_tmp" ]; then mkdir .app_deploy_tmp else - rm -rf .app_deploy_tmp + trap "rm -rf .app_deploy_tmp" EXIT fi # Get new data @@ -28,7 +28,7 @@ function __script_auto_update { cp -a .app_deploy_tmp/sources/. /usr/local/bin/.app-deploy-sources/ # Remove temp folder - rm -rf .app_deploy_tmp + trap "rm -rf .app_deploy_tmp" EXIT echo "Updated to $VERSION!" exit 0