Skip to content

Commit

Permalink
ci: fail pipeline when deployment fails
Browse files Browse the repository at this point in the history
Previously, if the deployment got to the SSH step, then it would always
pass because we were not handling errors from the SSH script.

Related to #83
  • Loading branch information
JoosepAlviste committed Jan 6, 2024
1 parent 44d8773 commit 14d1a27
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
root = true

[*.{ts,tsx,js,json}]
[*.{ts,tsx,js,json,sh}]
indent_style = space
indent_size = 2
28 changes: 17 additions & 11 deletions bin/update-deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
# To use this manually, fill the following variables in `.env`:
# - DEPLOYMENT_SSH_HOST
# - DEPLOYMENT_SSH_USER
deploy() {
# If the required environment variables already exist (e.g., in GitHub
# Actions), then we don't need to read the `.env` file
if [[ -z "${DEPLOYMENT_SSH_HOST}" ]]; then
source .env
fi

ssh "${DEPLOYMENT_SSH_USER}@${DEPLOYMENT_SSH_HOST}" <<ENDSSH
GREEN="\033[0;32m"
RED="\033[0;31m"
COFF="\033[0m"

# If the required environment variables already exist (e.g., in GitHub
# Actions), then we don't need to read the `.env` file
if [[ -z "${DEPLOYMENT_SSH_HOST}" ]]; then
source .env
fi

ssh "${DEPLOYMENT_SSH_USER}@${DEPLOYMENT_SSH_HOST}" <<ENDSSH
cd ~/projects/serieslist
git pull
Expand All @@ -25,7 +29,9 @@ echo "Migrating database..."
docker compose -f docker-compose.production.yml exec api pnpm migrate:prod
ENDSSH

echo "Project deployed!"
}

deploy
if [[ $? = 0 ]]; then
printf "${GREEN}Deployment successful!${COFF}\n"
else
printf "${RED}Deployment failed!${COFF}\n" >&2
exit 1
fi

0 comments on commit 14d1a27

Please sign in to comment.