From c080a6163b30efad90abae2f71ece4e213955139 Mon Sep 17 00:00:00 2001 From: Mraveux Date: Mon, 25 Nov 2024 13:55:45 -0600 Subject: [PATCH 01/17] Replace release.sh by a new deploy.sh --- package.json | 2 +- release.sh | 55 ------------ scripts/deploy.sh | 214 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 215 insertions(+), 56 deletions(-) delete mode 100755 release.sh create mode 100755 scripts/deploy.sh diff --git a/package.json b/package.json index c2eb61674..ea49b5b36 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "i18n:push": "tx push --source", "i18n:sync": "yarn i18n:extract && yarn i18n:push; yarn i18n:pull", "pre": "yarn i18n:extract && test -e public/bitcoin/BitcoinJS.min.js || yarn build:bitcoinjs", - "release": "./release.sh", + "release": "./scripts/deploy.sh", "test": "echo 'No tests'", "utils:getBankList": "oasis-bank-list-update", "utils:makeNginxAllowlist": "node ./scripts/makeNginxAllowlist.js" diff --git a/release.sh b/release.sh deleted file mode 100755 index 298599f3f..000000000 --- a/release.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -# Make sure a tag name was provided -tag=$1 -shift - -if [ -z "$tag" ]; then - echo "ERROR: Must provide a tag name." - exit 1 -fi - -# Flags -SYNC_TRANSLATIONS=true - -while [[ "$#" -gt 0 ]]; do - case $1 in - --no-translations) SYNC_TRANSLATIONS=false ;; - *) echo "Unknown argument: $1"; exit 1 ;; - esac - shift -done - -# Start release - -if [ "$SYNC_TRANSLATIONS" = "true" ]; then - # Sync languages - yarn i18n:sync -fi - -# Get up-to-date EBA RT1 bank list (disabled while OASIS is not available) -# yarn utils:getBankList - -# Get up-to-date browsers support list from caniuse. -# The browserslist utility is meant to run via npx, even when usually using yarn, and is compatible with yarn.lock. -npx browserslist@latest --update-db - -# Build Nginx path allowlist -yarn utils:makeNginxAllowlist - -if [[ `git status --porcelain` ]]; then - echo "ERROR: The repository has changes. Commit them first, then run again." - exit 1 -fi - -# Tag current commit -git tag $tag && - -# Build Vue app -yarn build && - -# Push commit and tag to origin -git push && git push --tags && - -# Done -echo "FINISHED - The app was built into the ./dist folder" diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 000000000..2904479b7 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,214 @@ +#!/bin/bash + +# Check if version number is provided +if [ "$#" -lt 1 ]; then + echo "Usage: $0 [commit_message] [--deployer=NAME] [--exclude-release] [--no-translations] [--mainnet] [--deploy-only]" + echo + echo "Examples:" + echo "1. Simple message (testnet):" + echo " $0 3.0.10 'Fix network stall handling' --deployer=matheo" + echo + echo "2. Multi-line message (mainnet):" + echo " $0 3.0.4 '- Move network browsers-not-shown warning to not overlap with bottom row" + echo "- Add a \"Failed to fetch transactions\" notice when transaction fetching fails" + echo "- Add a retry-mechanism to all Nimiq network requests" + echo "- Also hide staked amounts when privacy mode is on" + echo "- Enforce minimum stake on the slider itself' --deployer=john --mainnet" + echo + echo "3. Deploy only (after a cancelled deployment):" + echo " $0 --deploy-only" + exit 1 +fi + +# Don't require version number if --deploy-only is specified +if [[ "$1" == "--deploy-only" ]]; then + VERSION="" + DEPLOY_ONLY=true + shift +else + VERSION="$1" + shift # Remove version from arguments +fi + +# Default values +DEPLOYER="matheo" +EXCLUDE_RELEASE="" +SYNC_TRANSLATIONS=true +BUILD_ENV="testnet" +DEPLOY_ONLY=false + +# Parse remaining arguments +while [[ $# -gt 0 ]]; do + case $1 in + --deployer=*) + DEPLOYER="${1#*=}" + shift + ;; + --exclude-release) + EXCLUDE_RELEASE="[exclude-release]" + shift + ;; + --no-translations) + SYNC_TRANSLATIONS=false + shift + ;; + --mainnet) + BUILD_ENV="mainnet" + shift + ;; + --deploy-only) + DEPLOY_ONLY=true + shift + ;; + *) + COMMIT_MSG="$1" + shift + ;; + esac +done + +# Function to handle SSH deployment +do_ssh_deployment() { + # Confirmation prompt before deployment + read -p "${1:-The new version is ready. Do you want to proceed with the deployment? [y/N] }" -n 1 -r + echo # Move to a new line + if [[ ! $REPLY =~ ^[Yy]$ ]] + then + echo "Deployment cancelled." + exit 1 + fi + + # SSH into deployment servers + echo "Connecting to deployment servers..." + for server in "${DEPLOY_SERVERS[@]}"; do + echo "Connecting to $server..." + ssh "$server" + done + + echo "Deployment complete!" +} + +# If deploy-only flag is set, skip to deployment +if [ "$DEPLOY_ONLY" = true ]; then + echo "Running deployment only..." + do_ssh_deployment "Are you sure you want to proceed with the deployment? [y/N] " + exit 0 +fi + +# Use default commit message if none provided +COMMIT_MSG="${COMMIT_MSG:-Update to version $VERSION}" + +# Validate version number format +if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Error: Version number must be in format X.Y.Z" + exit 1 +fi + +# Function to compare version numbers +version_gt() { + test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" +} + +# Check if new version is greater than all existing tags in current repo +echo "Checking version against existing tags in wallet repo..." +EXISTING_TAGS=$(git tag | grep "^v[0-9]" | sed 's/^v//') +for tag in $EXISTING_TAGS; do + if ! version_gt "$VERSION" "$tag"; then + echo "Error: Version $VERSION is not greater than existing version $tag" + exit 1 + fi +done + +# Configuration +DEPLOYMENT_REPO="deployment-wallet" +DEPLOY_SERVERS=("deploy_wallet@web-1" "deploy_wallet@web-2" "deploy_wallet@web-3" "deploy_wallet@web-4") + +# Set environment tag based on BUILD_ENV +ENV_TAG=$([ "$BUILD_ENV" = "mainnet" ] && echo "main" || echo "test") + +# Pre-deployment tasks +echo "Running pre-deployment tasks..." + +if [ "$SYNC_TRANSLATIONS" = "true" ]; then + echo "Syncing translations..." + yarn i18n:sync +fi + +# Get up-to-date EBA RT1 bank list (disabled while OASIS is not available) +# yarn utils:getBankList + +# Get up-to-date browsers support list from caniuse. +# The browserslist utility is meant to run via npx, even when usually using yarn, and is compatible with yarn.lock. +echo "Updating browsers support list..." +npx browserslist@latest --update-db + +# Build Nginx path allowlist +echo "Building Nginx path allowlist..." +yarn utils:makeNginxAllowlist + +# Check for uncommitted changes +if [[ `git status --porcelain` ]]; then + echo "ERROR: The repository has uncommitted changes. Commit them first, then run again." + exit 1 +fi + +# Function to create commit/tag message +create_message() { + echo "Nimiq Wallet v$VERSION + +$COMMIT_MSG + +$EXCLUDE_RELEASE" +} + +# Create and push source tag +echo "Creating source tag v$VERSION..." +git tag -a -s "v$VERSION" -m "$(create_message)" + +# Build the project +echo "Building project with $BUILD_ENV configuration..." +env "build=$BUILD_ENV" yarn build + +# Push changes and tags +echo "Pushing source changes and tags..." +git push && git push --tags + +# Deploy to deployment repository +echo "Deploying to $DEPLOYMENT_REPO..." +cd "$DEPLOYMENT_REPO" || exit 1 + +# Checkout appropriate branch and pull latest changes +DEPLOY_BRANCH=$([ "$BUILD_ENV" = "mainnet" ] && echo "mainnet" || echo "testnet") +echo "Checking out $DEPLOY_BRANCH branch..." +git checkout "$DEPLOY_BRANCH" +git pull + +# Check if new version is greater than all existing tags in deployment repo for the current branch +echo "Checking version against existing tags in deployment repo ($DEPLOY_BRANCH branch)..." +EXISTING_DEPLOY_TAGS=$(git tag | grep "^v[0-9].*-$ENV_TAG-" | sed 's/^v\([0-9][^-]*\).*/\1/') +for tag in $EXISTING_DEPLOY_TAGS; do + if ! version_gt "$VERSION" "$tag"; then + echo "Error: Version $VERSION is not greater than existing version $tag in deployment repo" + exit 1 + fi +done + +# Copy build files +echo "Copying build files..." +cp -r ../dist/. dist +git add dist + +# Commit changes +echo "Committing changes..." +git commit -m "$(create_message)" + +# Create deployment tag +echo "Creating deployment tag..." +git tag -a -s "v$VERSION-$ENV_TAG-$DEPLOYER" -m "$(create_message)" + +# Push deployment changes and tags +echo "Pushing deployment changes and tags..." +git push && git push --tags + +# Run the deployment +do_ssh_deployment From 0b0b43de6ef5558ab7e5a59ae024a2774c271de5 Mon Sep 17 00:00:00 2001 From: Mraveux Date: Mon, 25 Nov 2024 14:14:07 -0600 Subject: [PATCH 02/17] deploy.sh: add some colors --- scripts/deploy.sh | 65 +++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 2904479b7..f6119f303 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -1,22 +1,30 @@ #!/bin/bash +# Color definitions +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +NC='\033[0m' # No Color + # Check if version number is provided if [ "$#" -lt 1 ]; then - echo "Usage: $0 [commit_message] [--deployer=NAME] [--exclude-release] [--no-translations] [--mainnet] [--deploy-only]" + echo -e "${BLUE}Usage: $0 [commit_message] [--deployer=NAME] [--exclude-release] [--no-translations] [--mainnet] [--deploy-only]${NC}" echo - echo "Examples:" + echo -e "${CYAN}Examples:${NC}" echo "1. Simple message (testnet):" - echo " $0 3.0.10 'Fix network stall handling' --deployer=matheo" + echo -e " ${GREEN}$0 3.0.10 'Fix network stall handling' --deployer=matheo${NC}" echo echo "2. Multi-line message (mainnet):" - echo " $0 3.0.4 '- Move network browsers-not-shown warning to not overlap with bottom row" + echo -e " ${GREEN}$0 3.0.4 '- Move network browsers-not-shown warning to not overlap with bottom row" echo "- Add a \"Failed to fetch transactions\" notice when transaction fetching fails" echo "- Add a retry-mechanism to all Nimiq network requests" echo "- Also hide staked amounts when privacy mode is on" - echo "- Enforce minimum stake on the slider itself' --deployer=john --mainnet" + echo -e "- Enforce minimum stake on the slider itself' --deployer=john --mainnet${NC}" echo echo "3. Deploy only (after a cancelled deployment):" - echo " $0 --deploy-only" + echo -e " ${GREEN}$0 --deploy-only${NC}" exit 1 fi @@ -70,22 +78,23 @@ done # Function to handle SSH deployment do_ssh_deployment() { # Confirmation prompt before deployment - read -p "${1:-The new version is ready. Do you want to proceed with the deployment? [y/N] }" -n 1 -r + echo -e "${YELLOW}${1:-The new version is ready. Do you want to proceed with the deployment? [y/N] }${NC}" + read -n 1 -r echo # Move to a new line if [[ ! $REPLY =~ ^[Yy]$ ]] then - echo "Deployment cancelled." + echo -e "${RED}Deployment cancelled.${NC}" exit 1 fi # SSH into deployment servers - echo "Connecting to deployment servers..." + echo -e "${BLUE}Connecting to deployment servers...${NC}" for server in "${DEPLOY_SERVERS[@]}"; do - echo "Connecting to $server..." + echo -e "${CYAN}Connecting to $server...${NC}" ssh "$server" done - echo "Deployment complete!" + echo -e "${GREEN}Deployment complete!${NC}" } # If deploy-only flag is set, skip to deployment @@ -100,7 +109,7 @@ COMMIT_MSG="${COMMIT_MSG:-Update to version $VERSION}" # Validate version number format if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "Error: Version number must be in format X.Y.Z" + echo -e "${RED}Error: Version number must be in format X.Y.Z${NC}" exit 1 fi @@ -110,11 +119,11 @@ version_gt() { } # Check if new version is greater than all existing tags in current repo -echo "Checking version against existing tags in wallet repo..." +echo -e "${BLUE}Checking version against existing tags in wallet repo...${NC}" EXISTING_TAGS=$(git tag | grep "^v[0-9]" | sed 's/^v//') for tag in $EXISTING_TAGS; do if ! version_gt "$VERSION" "$tag"; then - echo "Error: Version $VERSION is not greater than existing version $tag" + echo -e "${RED}Error: Version $VERSION is not greater than existing version $tag${NC}" exit 1 fi done @@ -127,10 +136,10 @@ DEPLOY_SERVERS=("deploy_wallet@web-1" "deploy_wallet@web-2" "deploy_wallet@web-3 ENV_TAG=$([ "$BUILD_ENV" = "mainnet" ] && echo "main" || echo "test") # Pre-deployment tasks -echo "Running pre-deployment tasks..." +echo -e "${BLUE}Running pre-deployment tasks...${NC}" if [ "$SYNC_TRANSLATIONS" = "true" ]; then - echo "Syncing translations..." + echo -e "${CYAN}Syncing translations...${NC}" yarn i18n:sync fi @@ -148,7 +157,7 @@ yarn utils:makeNginxAllowlist # Check for uncommitted changes if [[ `git status --porcelain` ]]; then - echo "ERROR: The repository has uncommitted changes. Commit them first, then run again." + echo -e "${RED}ERROR: The repository has uncommitted changes. Commit them first, then run again.${NC}" exit 1 fi @@ -162,52 +171,52 @@ $EXCLUDE_RELEASE" } # Create and push source tag -echo "Creating source tag v$VERSION..." +echo -e "${BLUE}Creating source tag v$VERSION...${NC}" git tag -a -s "v$VERSION" -m "$(create_message)" # Build the project -echo "Building project with $BUILD_ENV configuration..." +echo -e "${BLUE}Building project with $BUILD_ENV configuration...${NC}" env "build=$BUILD_ENV" yarn build # Push changes and tags -echo "Pushing source changes and tags..." +echo -e "${BLUE}Pushing source changes and tags...${NC}" git push && git push --tags # Deploy to deployment repository -echo "Deploying to $DEPLOYMENT_REPO..." +echo -e "${BLUE}Deploying to $DEPLOYMENT_REPO...${NC}" cd "$DEPLOYMENT_REPO" || exit 1 # Checkout appropriate branch and pull latest changes DEPLOY_BRANCH=$([ "$BUILD_ENV" = "mainnet" ] && echo "mainnet" || echo "testnet") -echo "Checking out $DEPLOY_BRANCH branch..." +echo -e "${CYAN}Checking out $DEPLOY_BRANCH branch...${NC}" git checkout "$DEPLOY_BRANCH" git pull # Check if new version is greater than all existing tags in deployment repo for the current branch -echo "Checking version against existing tags in deployment repo ($DEPLOY_BRANCH branch)..." +echo -e "${BLUE}Checking version against existing tags in deployment repo ($DEPLOY_BRANCH branch)...${NC}" EXISTING_DEPLOY_TAGS=$(git tag | grep "^v[0-9].*-$ENV_TAG-" | sed 's/^v\([0-9][^-]*\).*/\1/') for tag in $EXISTING_DEPLOY_TAGS; do if ! version_gt "$VERSION" "$tag"; then - echo "Error: Version $VERSION is not greater than existing version $tag in deployment repo" + echo -e "${RED}Error: Version $VERSION is not greater than existing version $tag in deployment repo${NC}" exit 1 fi done # Copy build files -echo "Copying build files..." +echo -e "${CYAN}Copying build files...${NC}" cp -r ../dist/. dist git add dist # Commit changes -echo "Committing changes..." +echo -e "${CYAN}Committing changes...${NC}" git commit -m "$(create_message)" # Create deployment tag -echo "Creating deployment tag..." +echo -e "${BLUE}Creating deployment tag...${NC}" git tag -a -s "v$VERSION-$ENV_TAG-$DEPLOYER" -m "$(create_message)" # Push deployment changes and tags -echo "Pushing deployment changes and tags..." +echo -e "${BLUE}Pushing deployment changes and tags...${NC}" git push && git push --tags # Run the deployment From d4773870edd2f7952db3e966dbe19df7322fd8c1 Mon Sep 17 00:00:00 2001 From: Mraveux Date: Mon, 25 Nov 2024 14:55:39 -0600 Subject: [PATCH 03/17] make message and deployer required and remove the default deployer value as well as put the message under the -m parameter for consistency --- scripts/deploy.sh | 108 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 89 insertions(+), 19 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index f6119f303..74e944bd1 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -10,14 +10,14 @@ NC='\033[0m' # No Color # Check if version number is provided if [ "$#" -lt 1 ]; then - echo -e "${BLUE}Usage: $0 [commit_message] [--deployer=NAME] [--exclude-release] [--no-translations] [--mainnet] [--deploy-only]${NC}" + echo -e "${BLUE}Usage: $0 -m --deployer=NAME [--exclude-release] [--no-translations] [--mainnet] [--deploy-only]${NC}" echo echo -e "${CYAN}Examples:${NC}" echo "1. Simple message (testnet):" - echo -e " ${GREEN}$0 3.0.10 'Fix network stall handling' --deployer=matheo${NC}" + echo -e " ${GREEN}$0 3.0.10 -m 'Fix network stall handling' --deployer=matheo${NC}" echo echo "2. Multi-line message (mainnet):" - echo -e " ${GREEN}$0 3.0.4 '- Move network browsers-not-shown warning to not overlap with bottom row" + echo -e " ${GREEN}$0 3.0.4 -m '- Move network browsers-not-shown warning to not overlap with bottom row" echo "- Add a \"Failed to fetch transactions\" notice when transaction fetching fails" echo "- Add a retry-mechanism to all Nimiq network requests" echo "- Also hide staked amounts when privacy mode is on" @@ -39,7 +39,7 @@ else fi # Default values -DEPLOYER="matheo" +DEPLOYER="" EXCLUDE_RELEASE="" SYNC_TRANSLATIONS=true BUILD_ENV="testnet" @@ -50,6 +50,10 @@ while [[ $# -gt 0 ]]; do case $1 in --deployer=*) DEPLOYER="${1#*=}" + if [ $# -eq 0 ]; then + echo -e "${RED}Error: --deployer requires a deployer name${NC}" + exit 1 + fi shift ;; --exclude-release) @@ -68,13 +72,93 @@ while [[ $# -gt 0 ]]; do DEPLOY_ONLY=true shift ;; - *) + -m) + shift + if [ $# -eq 0 ]; then + echo -e "${RED}Error: -m requires a commit message${NC}" + exit 1 + fi COMMIT_MSG="$1" shift ;; + *) + echo -e "${RED}Error: Unknown parameter $1${NC}" + exit 1 + ;; esac done +# Parameter validation +if [ "$DEPLOY_ONLY" = false ]; then + if [ -z "$DEPLOYER" ]; then + echo -e "${RED}Error: --deployer parameter is required${NC}" + echo + echo -e "${BLUE}Usage: $0 -m --deployer=NAME [--exclude-release] [--no-translations] [--mainnet] [--deploy-only]${NC}" + echo + echo -e "${CYAN}Examples:${NC}" + echo "1. Simple message (testnet):" + echo -e " ${GREEN}$0 3.0.10 -m 'Fix network stall handling' --deployer=matheo${NC}" + echo + echo "2. Multi-line message (mainnet):" + echo -e " ${GREEN}$0 3.0.4 -m '- Move network browsers-not-shown warning to not overlap with bottom row" + echo "- Add a \"Failed to fetch transactions\" notice when transaction fetching fails" + echo "- Add a retry-mechanism to all Nimiq network requests" + echo "- Also hide staked amounts when privacy mode is on" + echo -e "- Enforce minimum stake on the slider itself' --deployer=john --mainnet${NC}" + echo + echo "3. Deploy only (after a cancelled deployment):" + echo -e " ${GREEN}$0 --deploy-only${NC}" + exit 1 + fi + if [ -z "$COMMIT_MSG" ]; then + echo -e "${RED}Error: commit message (-m) is required${NC}" + echo + echo -e "${BLUE}Usage: $0 -m --deployer=NAME [--exclude-release] [--no-translations] [--mainnet] [--deploy-only]${NC}" + echo + echo -e "${CYAN}Examples:${NC}" + echo "1. Simple message (testnet):" + echo -e " ${GREEN}$0 3.0.10 -m 'Fix network stall handling' --deployer=matheo${NC}" + echo + echo "2. Multi-line message (mainnet):" + echo -e " ${GREEN}$0 3.0.4 -m '- Move network browsers-not-shown warning to not overlap with bottom row" + echo "- Add a \"Failed to fetch transactions\" notice when transaction fetching fails" + echo "- Add a retry-mechanism to all Nimiq network requests" + echo "- Also hide staked amounts when privacy mode is on" + echo -e "- Enforce minimum stake on the slider itself' --deployer=john --mainnet${NC}" + echo + echo "3. Deploy only (after a cancelled deployment):" + echo -e " ${GREEN}$0 --deploy-only${NC}" + exit 1 + fi +fi + +# Validate version number format +if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [ "$DEPLOY_ONLY" = false ]; then + echo -e "${RED}Error: Version number must be in format X.Y.Z${NC}" + echo + echo -e "${BLUE}Usage: $0 -m --deployer=NAME [--exclude-release] [--no-translations] [--mainnet] [--deploy-only]${NC}" + echo + echo -e "${CYAN}Examples:${NC}" + echo "1. Simple message (testnet):" + echo -e " ${GREEN}$0 3.0.10 -m 'Fix network stall handling' --deployer=matheo${NC}" + echo + echo "2. Multi-line message (mainnet):" + echo -e " ${GREEN}$0 3.0.4 -m '- Move network browsers-not-shown warning to not overlap with bottom row" + echo "- Add a \"Failed to fetch transactions\" notice when transaction fetching fails" + echo "- Add a retry-mechanism to all Nimiq network requests" + echo "- Also hide staked amounts when privacy mode is on" + echo -e "- Enforce minimum stake on the slider itself' --deployer=john --mainnet${NC}" + echo + echo "3. Deploy only (after a cancelled deployment):" + echo -e " ${GREEN}$0 --deploy-only${NC}" + exit 1 +fi + +# Function to compare version numbers +version_gt() { + test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" +} + # Function to handle SSH deployment do_ssh_deployment() { # Confirmation prompt before deployment @@ -104,20 +188,6 @@ if [ "$DEPLOY_ONLY" = true ]; then exit 0 fi -# Use default commit message if none provided -COMMIT_MSG="${COMMIT_MSG:-Update to version $VERSION}" - -# Validate version number format -if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo -e "${RED}Error: Version number must be in format X.Y.Z${NC}" - exit 1 -fi - -# Function to compare version numbers -version_gt() { - test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -} - # Check if new version is greater than all existing tags in current repo echo -e "${BLUE}Checking version against existing tags in wallet repo...${NC}" EXISTING_TAGS=$(git tag | grep "^v[0-9]" | sed 's/^v//') From ee1d0b47bca892bd1154b2d4a97d4fecd5316371 Mon Sep 17 00:00:00 2001 From: Mraveux Date: Mon, 25 Nov 2024 15:00:13 -0600 Subject: [PATCH 04/17] =?UTF-8?q?DRY=20the=20=E2=80=9CUsage=E2=80=9D=20mes?= =?UTF-8?q?sage=20into=20a=20reusable=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy.sh | 73 +++++++++++------------------------------------ 1 file changed, 17 insertions(+), 56 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 74e944bd1..29e621cb4 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -8,8 +8,15 @@ BLUE='\033[0;34m' CYAN='\033[0;36m' NC='\033[0m' # No Color -# Check if version number is provided -if [ "$#" -lt 1 ]; then +# Function to display usage message +show_usage() { + local error_msg="$1" + + if [ -n "$error_msg" ]; then + echo -e "${RED}Error: $error_msg${NC}" + echo + fi + echo -e "${BLUE}Usage: $0 -m --deployer=NAME [--exclude-release] [--no-translations] [--mainnet] [--deploy-only]${NC}" echo echo -e "${CYAN}Examples:${NC}" @@ -26,6 +33,11 @@ if [ "$#" -lt 1 ]; then echo "3. Deploy only (after a cancelled deployment):" echo -e " ${GREEN}$0 --deploy-only${NC}" exit 1 +} + +# Check if version number is provided +if [ "$#" -lt 1 ]; then + show_usage fi # Don't require version number if --deploy-only is specified @@ -91,67 +103,16 @@ done # Parameter validation if [ "$DEPLOY_ONLY" = false ]; then if [ -z "$DEPLOYER" ]; then - echo -e "${RED}Error: --deployer parameter is required${NC}" - echo - echo -e "${BLUE}Usage: $0 -m --deployer=NAME [--exclude-release] [--no-translations] [--mainnet] [--deploy-only]${NC}" - echo - echo -e "${CYAN}Examples:${NC}" - echo "1. Simple message (testnet):" - echo -e " ${GREEN}$0 3.0.10 -m 'Fix network stall handling' --deployer=matheo${NC}" - echo - echo "2. Multi-line message (mainnet):" - echo -e " ${GREEN}$0 3.0.4 -m '- Move network browsers-not-shown warning to not overlap with bottom row" - echo "- Add a \"Failed to fetch transactions\" notice when transaction fetching fails" - echo "- Add a retry-mechanism to all Nimiq network requests" - echo "- Also hide staked amounts when privacy mode is on" - echo -e "- Enforce minimum stake on the slider itself' --deployer=john --mainnet${NC}" - echo - echo "3. Deploy only (after a cancelled deployment):" - echo -e " ${GREEN}$0 --deploy-only${NC}" - exit 1 + show_usage "--deployer parameter is required" fi if [ -z "$COMMIT_MSG" ]; then - echo -e "${RED}Error: commit message (-m) is required${NC}" - echo - echo -e "${BLUE}Usage: $0 -m --deployer=NAME [--exclude-release] [--no-translations] [--mainnet] [--deploy-only]${NC}" - echo - echo -e "${CYAN}Examples:${NC}" - echo "1. Simple message (testnet):" - echo -e " ${GREEN}$0 3.0.10 -m 'Fix network stall handling' --deployer=matheo${NC}" - echo - echo "2. Multi-line message (mainnet):" - echo -e " ${GREEN}$0 3.0.4 -m '- Move network browsers-not-shown warning to not overlap with bottom row" - echo "- Add a \"Failed to fetch transactions\" notice when transaction fetching fails" - echo "- Add a retry-mechanism to all Nimiq network requests" - echo "- Also hide staked amounts when privacy mode is on" - echo -e "- Enforce minimum stake on the slider itself' --deployer=john --mainnet${NC}" - echo - echo "3. Deploy only (after a cancelled deployment):" - echo -e " ${GREEN}$0 --deploy-only${NC}" - exit 1 + show_usage "commit message (-m) is required" fi fi # Validate version number format if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [ "$DEPLOY_ONLY" = false ]; then - echo -e "${RED}Error: Version number must be in format X.Y.Z${NC}" - echo - echo -e "${BLUE}Usage: $0 -m --deployer=NAME [--exclude-release] [--no-translations] [--mainnet] [--deploy-only]${NC}" - echo - echo -e "${CYAN}Examples:${NC}" - echo "1. Simple message (testnet):" - echo -e " ${GREEN}$0 3.0.10 -m 'Fix network stall handling' --deployer=matheo${NC}" - echo - echo "2. Multi-line message (mainnet):" - echo -e " ${GREEN}$0 3.0.4 -m '- Move network browsers-not-shown warning to not overlap with bottom row" - echo "- Add a \"Failed to fetch transactions\" notice when transaction fetching fails" - echo "- Add a retry-mechanism to all Nimiq network requests" - echo "- Also hide staked amounts when privacy mode is on" - echo -e "- Enforce minimum stake on the slider itself' --deployer=john --mainnet${NC}" - echo - echo "3. Deploy only (after a cancelled deployment):" - echo -e " ${GREEN}$0 --deploy-only${NC}" - exit 1 + show_usage "Version number must be in format X.Y.Z" fi # Function to compare version numbers From cbff5f7cb1df159a0be6a3f6ebd6603add86966a Mon Sep 17 00:00:00 2001 From: Mraveux Date: Mon, 25 Nov 2024 15:03:11 -0600 Subject: [PATCH 05/17] Make BUILD_ENV required and explicit --- scripts/deploy.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 29e621cb4..7a04dcdee 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -17,11 +17,11 @@ show_usage() { echo fi - echo -e "${BLUE}Usage: $0 -m --deployer=NAME [--exclude-release] [--no-translations] [--mainnet] [--deploy-only]${NC}" + echo -e "${BLUE}Usage: $0 -m --deployer=NAME [--exclude-release] [--no-translations] [--mainnet|--testnet] [--deploy-only]${NC}" echo echo -e "${CYAN}Examples:${NC}" echo "1. Simple message (testnet):" - echo -e " ${GREEN}$0 3.0.10 -m 'Fix network stall handling' --deployer=matheo${NC}" + echo -e " ${GREEN}$0 3.0.10 -m 'Fix network stall handling' --deployer=matheo --testnet${NC}" echo echo "2. Multi-line message (mainnet):" echo -e " ${GREEN}$0 3.0.4 -m '- Move network browsers-not-shown warning to not overlap with bottom row" @@ -54,7 +54,7 @@ fi DEPLOYER="" EXCLUDE_RELEASE="" SYNC_TRANSLATIONS=true -BUILD_ENV="testnet" +BUILD_ENV="" DEPLOY_ONLY=false # Parse remaining arguments @@ -80,6 +80,10 @@ while [[ $# -gt 0 ]]; do BUILD_ENV="mainnet" shift ;; + --testnet) + BUILD_ENV="testnet" + shift + ;; --deploy-only) DEPLOY_ONLY=true shift @@ -108,6 +112,9 @@ if [ "$DEPLOY_ONLY" = false ]; then if [ -z "$COMMIT_MSG" ]; then show_usage "commit message (-m) is required" fi + if [ -z "$BUILD_ENV" ]; then + show_usage "Either --mainnet or --testnet must be specified" + fi fi # Validate version number format From adc4ced8a973888f5040528151fede59f7182b5b Mon Sep 17 00:00:00 2001 From: Mraveux Date: Mon, 25 Nov 2024 15:05:33 -0600 Subject: [PATCH 06/17] =?UTF-8?q?Add=20=E2=80=9Cgit=20status=E2=80=9D=20an?= =?UTF-8?q?d=20[y/N]=20step=20before=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 7a04dcdee..b10f581c4 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -245,6 +245,19 @@ echo -e "${CYAN}Copying build files...${NC}" cp -r ../dist/. dist git add dist +# Show git status and ask for confirmation +echo -e "${YELLOW}Current git status:${NC}" +git status + +echo -e "${YELLOW}Please review the changes above. Do you want to proceed with the commit? [y/N]${NC}" +read -n 1 -r +echo # Move to a new line +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + echo -e "${RED}Deployment cancelled.${NC}" + exit 1 +fi + # Commit changes echo -e "${CYAN}Committing changes...${NC}" git commit -m "$(create_message)" From af5d8853ed7f66a5fafd0abe304cd7bf094f3e5b Mon Sep 17 00:00:00 2001 From: Mraveux Date: Mon, 25 Nov 2024 16:22:27 -0600 Subject: [PATCH 07/17] =?UTF-8?q?fix=20=E2=80=94deploy-only=20behavior?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy.sh | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index b10f581c4..38e461114 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -40,6 +40,17 @@ if [ "$#" -lt 1 ]; then show_usage fi +# Default values +DEPLOYER="" +EXCLUDE_RELEASE="" +SYNC_TRANSLATIONS=true +BUILD_ENV="" +DEPLOY_ONLY=false + +DEPLOYMENT_REPO="deployment-wallet" +DEPLOY_SERVERS=("deploy_wallet@web-1" "deploy_wallet@web-2" "deploy_wallet@web-3" "deploy_wallet@web-4") + + # Don't require version number if --deploy-only is specified if [[ "$1" == "--deploy-only" ]]; then VERSION="" @@ -50,13 +61,6 @@ else shift # Remove version from arguments fi -# Default values -DEPLOYER="" -EXCLUDE_RELEASE="" -SYNC_TRANSLATIONS=true -BUILD_ENV="" -DEPLOY_ONLY=false - # Parse remaining arguments while [[ $# -gt 0 ]]; do case $1 in @@ -166,10 +170,6 @@ for tag in $EXISTING_TAGS; do fi done -# Configuration -DEPLOYMENT_REPO="deployment-wallet" -DEPLOY_SERVERS=("deploy_wallet@web-1" "deploy_wallet@web-2" "deploy_wallet@web-3" "deploy_wallet@web-4") - # Set environment tag based on BUILD_ENV ENV_TAG=$([ "$BUILD_ENV" = "mainnet" ] && echo "main" || echo "test") @@ -194,10 +194,10 @@ echo "Building Nginx path allowlist..." yarn utils:makeNginxAllowlist # Check for uncommitted changes -if [[ `git status --porcelain` ]]; then - echo -e "${RED}ERROR: The repository has uncommitted changes. Commit them first, then run again.${NC}" - exit 1 -fi +# if [[ `git status --porcelain` ]]; then +# echo -e "${RED}ERROR: The repository has uncommitted changes. Commit them first, then run again.${NC}" +# exit 1 +# fi # Function to create commit/tag message create_message() { From d40e5c46ae19654e817f136087bcca2258f5f0d1 Mon Sep 17 00:00:00 2001 From: Mraveux Date: Mon, 25 Nov 2024 17:48:31 -0600 Subject: [PATCH 08/17] re-enable uncommitted changes check + more verbose --- scripts/deploy.sh | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 38e461114..249bcb8a5 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -147,6 +147,7 @@ do_ssh_deployment() { echo -e "${BLUE}Connecting to deployment servers...${NC}" for server in "${DEPLOY_SERVERS[@]}"; do echo -e "${CYAN}Connecting to $server...${NC}" + echo -e "${YELLOW}$ ssh $server${NC}" ssh "$server" done @@ -155,7 +156,7 @@ do_ssh_deployment() { # If deploy-only flag is set, skip to deployment if [ "$DEPLOY_ONLY" = true ]; then - echo "Running deployment only..." + echo -e "${BLUE}Running deployment only...${NC}" do_ssh_deployment "Are you sure you want to proceed with the deployment? [y/N] " exit 0 fi @@ -178,6 +179,7 @@ echo -e "${BLUE}Running pre-deployment tasks...${NC}" if [ "$SYNC_TRANSLATIONS" = "true" ]; then echo -e "${CYAN}Syncing translations...${NC}" + echo -e "${YELLOW}$ yarn i18n:sync${NC}" yarn i18n:sync fi @@ -186,18 +188,20 @@ fi # Get up-to-date browsers support list from caniuse. # The browserslist utility is meant to run via npx, even when usually using yarn, and is compatible with yarn.lock. -echo "Updating browsers support list..." +echo -e "${CYAN}Updating browsers support list...${NC}" +echo -e "${YELLOW}$ npx browserslist@latest --update-db${NC}" npx browserslist@latest --update-db # Build Nginx path allowlist -echo "Building Nginx path allowlist..." +echo -e "${CYAN}Building Nginx path allowlist...${NC}" +echo -e "${YELLOW}$ yarn utils:makeNginxAllowlist${NC}" yarn utils:makeNginxAllowlist # Check for uncommitted changes -# if [[ `git status --porcelain` ]]; then -# echo -e "${RED}ERROR: The repository has uncommitted changes. Commit them first, then run again.${NC}" -# exit 1 -# fi +if [[ `git status --porcelain` ]]; then + echo -e "${RED}ERROR: The repository has uncommitted changes. Commit them first, then run again.${NC}" + exit 1 +fi # Function to create commit/tag message create_message() { @@ -210,24 +214,30 @@ $EXCLUDE_RELEASE" # Create and push source tag echo -e "${BLUE}Creating source tag v$VERSION...${NC}" +echo -e "${YELLOW}$ git tag -a -s \"v$VERSION\" -m \"$(create_message)\"" git tag -a -s "v$VERSION" -m "$(create_message)" # Build the project echo -e "${BLUE}Building project with $BUILD_ENV configuration...${NC}" +echo -e "${YELLOW}$ env \"build=$BUILD_ENV\" yarn build${NC}" env "build=$BUILD_ENV" yarn build # Push changes and tags echo -e "${BLUE}Pushing source changes and tags...${NC}" +echo -e "${YELLOW}$ git push && git push --tags${NC}" git push && git push --tags # Deploy to deployment repository echo -e "${BLUE}Deploying to $DEPLOYMENT_REPO...${NC}" +echo -e "${YELLOW}$ cd \"$DEPLOYMENT_REPO\" || exit 1${NC}" cd "$DEPLOYMENT_REPO" || exit 1 # Checkout appropriate branch and pull latest changes DEPLOY_BRANCH=$([ "$BUILD_ENV" = "mainnet" ] && echo "mainnet" || echo "testnet") echo -e "${CYAN}Checking out $DEPLOY_BRANCH branch...${NC}" +echo -e "${YELLOW}$ git checkout $DEPLOY_BRANCH${NC}" git checkout "$DEPLOY_BRANCH" +echo -e "${YELLOW}$ git pull${NC}" git pull # Check if new version is greater than all existing tags in deployment repo for the current branch @@ -242,7 +252,9 @@ done # Copy build files echo -e "${CYAN}Copying build files...${NC}" +echo -e "${YELLOW}$ cp -r ../dist/. dist${NC}" cp -r ../dist/. dist +echo -e "${YELLOW}$ git add dist${NC}" git add dist # Show git status and ask for confirmation @@ -260,14 +272,17 @@ fi # Commit changes echo -e "${CYAN}Committing changes...${NC}" +echo -e "${YELLOW}$ git commit -m \"$(create_message)\"${NC}" git commit -m "$(create_message)" # Create deployment tag echo -e "${BLUE}Creating deployment tag...${NC}" +echo -e "${YELLOW}$ git tag -a -s \"v$VERSION-$ENV_TAG-$DEPLOYER\" -m \"$(create_message)\"${NC}" git tag -a -s "v$VERSION-$ENV_TAG-$DEPLOYER" -m "$(create_message)" # Push deployment changes and tags echo -e "${BLUE}Pushing deployment changes and tags...${NC}" +echo -e "${YELLOW}$ git push && git push --tags${NC}" git push && git push --tags # Run the deployment From 970dd87cf903963a1a43ac1946d6f4f69258eda4 Mon Sep 17 00:00:00 2001 From: Mraveux Date: Mon, 25 Nov 2024 18:10:54 -0600 Subject: [PATCH 09/17] Add error handling --- scripts/deploy.sh | 63 +++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 249bcb8a5..976353dd3 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -1,5 +1,8 @@ #!/bin/bash +# Exit on error +set -e + # Color definitions RED='\033[0;31m' GREEN='\033[0;32m' @@ -131,6 +134,18 @@ version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" } +# Function to run command with error handling +run_command() { + local cmd=$1 + local error_msg=${2:-"Command failed"} + + echo -e "${YELLOW}$ $cmd${NC}" + if ! eval "$cmd"; then + echo -e "${RED}Error: $error_msg${NC}" + exit 1 + fi +} + # Function to handle SSH deployment do_ssh_deployment() { # Confirmation prompt before deployment @@ -147,8 +162,10 @@ do_ssh_deployment() { echo -e "${BLUE}Connecting to deployment servers...${NC}" for server in "${DEPLOY_SERVERS[@]}"; do echo -e "${CYAN}Connecting to $server...${NC}" - echo -e "${YELLOW}$ ssh $server${NC}" - ssh "$server" + if ! ssh "$server"; then + echo -e "${RED}Failed to connect to $server${NC}" + exit 1 + fi done echo -e "${GREEN}Deployment complete!${NC}" @@ -179,8 +196,7 @@ echo -e "${BLUE}Running pre-deployment tasks...${NC}" if [ "$SYNC_TRANSLATIONS" = "true" ]; then echo -e "${CYAN}Syncing translations...${NC}" - echo -e "${YELLOW}$ yarn i18n:sync${NC}" - yarn i18n:sync + run_command "yarn i18n:sync" "Failed to sync translations" fi # Get up-to-date EBA RT1 bank list (disabled while OASIS is not available) @@ -189,13 +205,11 @@ fi # Get up-to-date browsers support list from caniuse. # The browserslist utility is meant to run via npx, even when usually using yarn, and is compatible with yarn.lock. echo -e "${CYAN}Updating browsers support list...${NC}" -echo -e "${YELLOW}$ npx browserslist@latest --update-db${NC}" -npx browserslist@latest --update-db +run_command "npx browserslist@latest --update-db" "Failed to update browsers list" # Build Nginx path allowlist echo -e "${CYAN}Building Nginx path allowlist...${NC}" -echo -e "${YELLOW}$ yarn utils:makeNginxAllowlist${NC}" -yarn utils:makeNginxAllowlist +run_command "yarn utils:makeNginxAllowlist" "Failed to build Nginx allowlist" # Check for uncommitted changes if [[ `git status --porcelain` ]]; then @@ -214,31 +228,25 @@ $EXCLUDE_RELEASE" # Create and push source tag echo -e "${BLUE}Creating source tag v$VERSION...${NC}" -echo -e "${YELLOW}$ git tag -a -s \"v$VERSION\" -m \"$(create_message)\"" -git tag -a -s "v$VERSION" -m "$(create_message)" +run_command "git tag -a -s \"v$VERSION\" -m \"$(create_message)\"" "Failed to create git tag" # Build the project echo -e "${BLUE}Building project with $BUILD_ENV configuration...${NC}" -echo -e "${YELLOW}$ env \"build=$BUILD_ENV\" yarn build${NC}" -env "build=$BUILD_ENV" yarn build +run_command "env \"build=$BUILD_ENV\" yarn build" "Failed to build project" # Push changes and tags echo -e "${BLUE}Pushing source changes and tags...${NC}" -echo -e "${YELLOW}$ git push && git push --tags${NC}" -git push && git push --tags +run_command "git push && git push --tags" "Failed to push changes" # Deploy to deployment repository echo -e "${BLUE}Deploying to $DEPLOYMENT_REPO...${NC}" -echo -e "${YELLOW}$ cd \"$DEPLOYMENT_REPO\" || exit 1${NC}" -cd "$DEPLOYMENT_REPO" || exit 1 +run_command "cd \"$DEPLOYMENT_REPO\" || exit 1" "Failed to change to deployment directory" # Checkout appropriate branch and pull latest changes DEPLOY_BRANCH=$([ "$BUILD_ENV" = "mainnet" ] && echo "mainnet" || echo "testnet") echo -e "${CYAN}Checking out $DEPLOY_BRANCH branch...${NC}" -echo -e "${YELLOW}$ git checkout $DEPLOY_BRANCH${NC}" -git checkout "$DEPLOY_BRANCH" -echo -e "${YELLOW}$ git pull${NC}" -git pull +run_command "git checkout $DEPLOY_BRANCH" "Failed to checkout branch" +run_command "git pull" "Failed to pull latest changes" # Check if new version is greater than all existing tags in deployment repo for the current branch echo -e "${BLUE}Checking version against existing tags in deployment repo ($DEPLOY_BRANCH branch)...${NC}" @@ -252,10 +260,8 @@ done # Copy build files echo -e "${CYAN}Copying build files...${NC}" -echo -e "${YELLOW}$ cp -r ../dist/. dist${NC}" -cp -r ../dist/. dist -echo -e "${YELLOW}$ git add dist${NC}" -git add dist +run_command "cp -r ../dist/. dist" "Failed to copy build files" +run_command "git add dist" "Failed to stage changes" # Show git status and ask for confirmation echo -e "${YELLOW}Current git status:${NC}" @@ -272,18 +278,15 @@ fi # Commit changes echo -e "${CYAN}Committing changes...${NC}" -echo -e "${YELLOW}$ git commit -m \"$(create_message)\"${NC}" -git commit -m "$(create_message)" +run_command "git commit -m \"$(create_message)\"" "Failed to commit changes" # Create deployment tag echo -e "${BLUE}Creating deployment tag...${NC}" -echo -e "${YELLOW}$ git tag -a -s \"v$VERSION-$ENV_TAG-$DEPLOYER\" -m \"$(create_message)\"${NC}" -git tag -a -s "v$VERSION-$ENV_TAG-$DEPLOYER" -m "$(create_message)" +run_command "git tag -a -s \"v$VERSION-$ENV_TAG-$DEPLOYER\" -m \"$(create_message)\"" "Failed to create deployment tag" # Push deployment changes and tags echo -e "${BLUE}Pushing deployment changes and tags...${NC}" -echo -e "${YELLOW}$ git push && git push --tags${NC}" -git push && git push --tags +run_command "git push && git push --tags" "Failed to push deployment changes" # Run the deployment do_ssh_deployment From 15c32fad704f5905f75ee484e805ac3f7a8714d0 Mon Sep 17 00:00:00 2001 From: Mraveux Date: Tue, 26 Nov 2024 12:00:18 -0600 Subject: [PATCH 10/17] Add testnet servers, and make build_env required --- scripts/deploy.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 976353dd3..e0f8e6b47 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -50,9 +50,12 @@ SYNC_TRANSLATIONS=true BUILD_ENV="" DEPLOY_ONLY=false -DEPLOYMENT_REPO="deployment-wallet" -DEPLOY_SERVERS=("deploy_wallet@web-1" "deploy_wallet@web-2" "deploy_wallet@web-3" "deploy_wallet@web-4") +# Define deploy servers for different environments +MAINNET_SERVERS=("deploy_wallet@web-1" "deploy_wallet@web-2" "deploy_wallet@web-3" "deploy_wallet@web-4") +TESTNET_SERVERS=("deploy_wallet@testnet-web1") +DEPLOY_SERVERS=() +DEPLOYMENT_REPO="deployment-wallet" # Don't require version number if --deploy-only is specified if [[ "$1" == "--deploy-only" ]]; then @@ -85,10 +88,12 @@ while [[ $# -gt 0 ]]; do ;; --mainnet) BUILD_ENV="mainnet" + DEPLOY_SERVERS=("${MAINNET_SERVERS[@]}") shift ;; --testnet) BUILD_ENV="testnet" + DEPLOY_SERVERS=("${TESTNET_SERVERS[@]}") shift ;; --deploy-only) @@ -119,9 +124,11 @@ if [ "$DEPLOY_ONLY" = false ]; then if [ -z "$COMMIT_MSG" ]; then show_usage "commit message (-m) is required" fi - if [ -z "$BUILD_ENV" ]; then - show_usage "Either --mainnet or --testnet must be specified" - fi +fi + +# Always require environment specification +if [ -z "$BUILD_ENV" ]; then + show_usage "Either --mainnet or --testnet must be specified" fi # Validate version number format From f4635093794c2fd95f1bb04347f97e454cdb4d91 Mon Sep 17 00:00:00 2001 From: Mraveux Date: Tue, 26 Nov 2024 12:16:22 -0600 Subject: [PATCH 11/17] =?UTF-8?q?Add=20a=20confirmation=20=E2=80=9Crecap?= =?UTF-8?q?=E2=80=9D=20before=20running=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index e0f8e6b47..2ec8bd559 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -198,6 +198,37 @@ done # Set environment tag based on BUILD_ENV ENV_TAG=$([ "$BUILD_ENV" = "mainnet" ] && echo "main" || echo "test") +# Function to show deployment recap +show_deployment_recap() { + echo + echo -e "${BLUE}=== Deployment Recap ===${NC}" + echo -e "${CYAN}Version:${NC} $VERSION" + echo -e "${CYAN}Environment:${NC} $BUILD_ENV" + echo -e "${CYAN}Deployer:${NC} $DEPLOYER" + echo -e "${CYAN}Target Servers:${NC}" + for server in "${DEPLOY_SERVERS[@]}"; do + echo -e " - $server" + done + echo -e "${CYAN}Exclude Release:${NC} $([ -n "$EXCLUDE_RELEASE" ] && echo "Yes" || echo "No")" + echo -e "${CYAN}Sync Translations:${NC} $SYNC_TRANSLATIONS" + echo -e "${CYAN}Commit Message:${NC}" + echo "$COMMIT_MSG" | sed 's/^/ /' + echo + echo -e "${YELLOW}Please review the deployment details above. Do you want to proceed? [y/N]${NC}" + read -n 1 -r + echo # Move to a new line + if [[ ! $REPLY =~ ^[Yy]$ ]] + then + echo -e "${RED}Deployment cancelled.${NC}" + exit 1 + fi +} + +# Add recap before starting deployment process +if [ "$DEPLOY_ONLY" = false ]; then + show_deployment_recap +fi + # Pre-deployment tasks echo -e "${BLUE}Running pre-deployment tasks...${NC}" From 493bb283d087ff4cfffd800002903d8a443346d6 Mon Sep 17 00:00:00 2001 From: Mraveux Date: Tue, 26 Nov 2024 12:20:36 -0600 Subject: [PATCH 12/17] =?UTF-8?q?Add=20=E2=80=94same-as=20to=20allow=20to?= =?UTF-8?q?=20deploy=20same=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For example “—same-as=testnet —mainnet” will deploy the version already deployed on the testnet to the mainnet --- scripts/deploy.sh | 102 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 81 insertions(+), 21 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 2ec8bd559..b02a1277d 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -20,7 +20,7 @@ show_usage() { echo fi - echo -e "${BLUE}Usage: $0 -m --deployer=NAME [--exclude-release] [--no-translations] [--mainnet|--testnet] [--deploy-only]${NC}" + echo -e "${BLUE}Usage: $0 -m --deployer=NAME [--exclude-release] [--no-translations] [--mainnet|--testnet] [--deploy-only] [--same-as=ENV]${NC}" echo echo -e "${CYAN}Examples:${NC}" echo "1. Simple message (testnet):" @@ -35,6 +35,8 @@ show_usage() { echo echo "3. Deploy only (after a cancelled deployment):" echo -e " ${GREEN}$0 --deploy-only${NC}" + echo "4. Deploy same version from testnet to mainnet:" + echo -e " ${GREEN}$0 --same-as=testnet -m 'Same fixes as testnet' --deployer=john --mainnet${NC}" exit 1 } @@ -49,6 +51,7 @@ EXCLUDE_RELEASE="" SYNC_TRANSLATIONS=true BUILD_ENV="" DEPLOY_ONLY=false +SAME_AS="" # Define deploy servers for different environments MAINNET_SERVERS=("deploy_wallet@web-1" "deploy_wallet@web-2" "deploy_wallet@web-3" "deploy_wallet@web-4") @@ -57,11 +60,23 @@ DEPLOY_SERVERS=() DEPLOYMENT_REPO="deployment-wallet" -# Don't require version number if --deploy-only is specified -if [[ "$1" == "--deploy-only" ]]; then +# Initial argument handling +if [[ "$1" =~ ^--same-as= ]]; then + SAME_AS="${1#*=}" + if [[ ! "$SAME_AS" =~ ^(testnet|mainnet)$ ]]; then + echo -e "${RED}Error: --same-as must be either 'testnet' or 'mainnet'${NC}" + exit 1 + fi + VERSION="" + shift +elif [[ "$1" == "--deploy-only" ]]; then VERSION="" DEPLOY_ONLY=true shift +elif [[ "$1" =~ ^--.*$ ]]; then + # If first argument is any other flag + VERSION="" + shift else VERSION="$1" shift # Remove version from arguments @@ -100,6 +115,14 @@ while [[ $# -gt 0 ]]; do DEPLOY_ONLY=true shift ;; + --same-as=*) + SAME_AS="${1#*=}" + if [[ ! "$SAME_AS" =~ ^(testnet|mainnet)$ ]]; then + echo -e "${RED}Error: --same-as must be either 'testnet' or 'mainnet'${NC}" + exit 1 + fi + shift + ;; -m) shift if [ $# -eq 0 ]; then @@ -131,9 +154,38 @@ if [ -z "$BUILD_ENV" ]; then show_usage "Either --mainnet or --testnet must be specified" fi -# Validate version number format -if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [ "$DEPLOY_ONLY" = false ]; then - show_usage "Version number must be in format X.Y.Z" +# After parsing arguments and before validation, handle --same-as +if [ -n "$SAME_AS" ]; then + echo -e "${BLUE}Looking up version from $SAME_AS deployment...${NC}" + + # Determine the environment tag to look for + LOOKUP_TAG=$([ "$SAME_AS" = "mainnet" ] && echo "main" || echo "test") + + # Get the latest version from the specified environment + cd "$DEPLOYMENT_REPO" || exit 1 + LATEST_VERSION=$(git tag | grep "^v[0-9].*-$LOOKUP_TAG-" | sort -V | tail -n 1 | sed 's/^v\([0-9][^-]*\).*/\1/') + cd - > /dev/null || exit 1 + + if [ -z "$LATEST_VERSION" ]; then + echo -e "${RED}Error: No version found in $SAME_AS environment${NC}" + exit 1 + fi + + echo -e "${GREEN}Found version $LATEST_VERSION${NC}" + VERSION="$LATEST_VERSION" +fi + +# Version validation +if [ "$DEPLOY_ONLY" = false ]; then + if [ -n "$SAME_AS" ]; then + if [ -n "$1" ] && [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + show_usage "Version number should not be provided when using --same-as" + fi + elif [ -z "$VERSION" ]; then + show_usage "Version number is required when not using --deploy-only or --same-as" + elif ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + show_usage "Version number must be in format X.Y.Z" + fi fi # Function to compare version numbers @@ -186,14 +238,18 @@ if [ "$DEPLOY_ONLY" = true ]; then fi # Check if new version is greater than all existing tags in current repo -echo -e "${BLUE}Checking version against existing tags in wallet repo...${NC}" -EXISTING_TAGS=$(git tag | grep "^v[0-9]" | sed 's/^v//') -for tag in $EXISTING_TAGS; do - if ! version_gt "$VERSION" "$tag"; then - echo -e "${RED}Error: Version $VERSION is not greater than existing version $tag${NC}" - exit 1 - fi -done +if [ -z "$SAME_AS" ]; then + echo -e "${BLUE}Checking version against existing tags in wallet repo...${NC}" + EXISTING_TAGS=$(git tag | grep "^v[0-9]" | sed 's/^v//') + for tag in $EXISTING_TAGS; do + if ! version_gt "$VERSION" "$tag"; then + echo -e "${RED}Error: Version $VERSION is not greater than existing version $tag${NC}" + exit 1 + fi + done +else + echo -e "${BLUE}Skipping version comparison check since --same-as is used${NC}" +fi # Set environment tag based on BUILD_ENV ENV_TAG=$([ "$BUILD_ENV" = "mainnet" ] && echo "main" || echo "test") @@ -264,18 +320,22 @@ $COMMIT_MSG $EXCLUDE_RELEASE" } -# Create and push source tag -echo -e "${BLUE}Creating source tag v$VERSION...${NC}" -run_command "git tag -a -s \"v$VERSION\" -m \"$(create_message)\"" "Failed to create git tag" +# Create and push source tag (skip if using --same-as) +if [ -z "$SAME_AS" ]; then + echo -e "${BLUE}Creating source tag v$VERSION...${NC}" + run_command "git tag -a -s \"v$VERSION\" -m \"$(create_message)\"" "Failed to create git tag" + + # Push changes and tags + echo -e "${BLUE}Pushing source changes and tags...${NC}" + run_command "git push && git push --tags" "Failed to push changes" +else + echo -e "${BLUE}Skipping source tag creation since --same-as is used${NC}" +fi # Build the project echo -e "${BLUE}Building project with $BUILD_ENV configuration...${NC}" run_command "env \"build=$BUILD_ENV\" yarn build" "Failed to build project" -# Push changes and tags -echo -e "${BLUE}Pushing source changes and tags...${NC}" -run_command "git push && git push --tags" "Failed to push changes" - # Deploy to deployment repository echo -e "${BLUE}Deploying to $DEPLOYMENT_REPO...${NC}" run_command "cd \"$DEPLOYMENT_REPO\" || exit 1" "Failed to change to deployment directory" From 2675833328c1dffd884610359aac2e3ffdee2db8 Mon Sep 17 00:00:00 2001 From: Mraveux Date: Tue, 26 Nov 2024 13:51:03 -0600 Subject: [PATCH 13/17] add ./clean.sh execution before copying dist files --- scripts/deploy.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index b02a1277d..7fa751392 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -356,6 +356,10 @@ for tag in $EXISTING_DEPLOY_TAGS; do fi done +# Clean deployment directory +echo -e "${CYAN}Cleaning deployment directory...${NC}" +run_command "./clean.sh" "Failed to clean deployment directory" + # Copy build files echo -e "${CYAN}Copying build files...${NC}" run_command "cp -r ../dist/. dist" "Failed to copy build files" From 76a81a436ba9d4eea4b4847fe8f0a77748327f58 Mon Sep 17 00:00:00 2001 From: Mraveux Date: Tue, 26 Nov 2024 13:54:32 -0600 Subject: [PATCH 14/17] =?UTF-8?q?prevent=20trailing=20newline=20if=20no=20?= =?UTF-8?q?=E2=80=94exclude-release?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 7fa751392..861d8c787 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -313,11 +313,17 @@ fi # Function to create commit/tag message create_message() { - echo "Nimiq Wallet v$VERSION + local message="Nimiq Wallet v$VERSION -$COMMIT_MSG +$COMMIT_MSG" + + if [ -n "$EXCLUDE_RELEASE" ]; then + message+=" $EXCLUDE_RELEASE" + fi + + echo "$message" } # Create and push source tag (skip if using --same-as) From e221ae23fe60fca4a4796471b19c6c17ed4181a9 Mon Sep 17 00:00:00 2001 From: Mraveux Date: Tue, 26 Nov 2024 14:05:11 -0600 Subject: [PATCH 15/17] Add post-deployment message --- scripts/deploy.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 861d8c787..82b6b31c2 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -228,6 +228,9 @@ do_ssh_deployment() { done echo -e "${GREEN}Deployment complete!${NC}" + echo -e "${YELLOW}> Please verify that the deployment went through successfully.${NC}" + echo -e "${YELLOW}> Please also verify that the website is working correctly on $BUILD_ENV and is correctly using the new version $VERSION.${NC}" + echo -e "${YELLOW}> https://$([ "$BUILD_ENV" = "mainnet" ] && echo "wallet.nimiq.com" || echo "wallet.nimiq-testnet.com")${NC}" } # If deploy-only flag is set, skip to deployment From 84ce18307c31394eb7275a9326cacdffea8c9ef5 Mon Sep 17 00:00:00 2001 From: Mraveux Date: Tue, 26 Nov 2024 14:07:54 -0600 Subject: [PATCH 16/17] =?UTF-8?q?Remove=20unnecessary=20=E2=80=94deployer?= =?UTF-8?q?=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 82b6b31c2..0c26b66af 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -87,10 +87,6 @@ while [[ $# -gt 0 ]]; do case $1 in --deployer=*) DEPLOYER="${1#*=}" - if [ $# -eq 0 ]; then - echo -e "${RED}Error: --deployer requires a deployer name${NC}" - exit 1 - fi shift ;; --exclude-release) From 2e916154ef6c4dde1d019504745cc2acee0caf0b Mon Sep 17 00:00:00 2001 From: Mraveux Date: Tue, 26 Nov 2024 14:45:30 -0600 Subject: [PATCH 17/17] =?UTF-8?q?Forbid=20version=20if=20=E2=80=94deploy-o?= =?UTF-8?q?nly=20or=20=E2=80=94same-as?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy.sh | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 0c26b66af..89d7a7773 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -40,9 +40,14 @@ show_usage() { exit 1 } -# Check if version number is provided -if [ "$#" -lt 1 ]; then - show_usage +# Check if first argument is a flag +if [[ "$1" =~ ^-- ]]; then + if [[ "$1" =~ ^--same-as= ]] || [[ "$1" == "--deploy-only" ]]; then + # These flags are allowed as first argument + : + else + show_usage "Version number must be the first argument when not using --same-as or --deploy-only" + fi fi # Default values @@ -73,13 +78,14 @@ elif [[ "$1" == "--deploy-only" ]]; then VERSION="" DEPLOY_ONLY=true shift -elif [[ "$1" =~ ^--.*$ ]]; then - # If first argument is any other flag - VERSION="" +elif [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + VERSION="$1" + VERSION_PROVIDED_BY_USER=true shift +elif [[ "$1" =~ ^- ]]; then + show_usage "Version number must be the first argument when not using --same-as or --deploy-only" else - VERSION="$1" - shift # Remove version from arguments + show_usage "First argument must be either a version number, --same-as=ENV, or --deploy-only" fi # Parse remaining arguments @@ -172,16 +178,14 @@ if [ -n "$SAME_AS" ]; then fi # Version validation -if [ "$DEPLOY_ONLY" = false ]; then - if [ -n "$SAME_AS" ]; then - if [ -n "$1" ] && [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - show_usage "Version number should not be provided when using --same-as" - fi - elif [ -z "$VERSION" ]; then +if [ "$DEPLOY_ONLY" = false ] && [ -z "$SAME_AS" ]; then + if [ -z "$VERSION" ]; then show_usage "Version number is required when not using --deploy-only or --same-as" elif ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then show_usage "Version number must be in format X.Y.Z" fi +elif [ "$VERSION_PROVIDED_BY_USER" = true ]; then + show_usage "Version number cannot be provided when using --deploy-only or --same-as" fi # Function to compare version numbers