Skip to content

🎻 Support Service Update #14

🎻 Support Service Update

🎻 Support Service Update #14

name: 🎻 Support Service Update
on:
push:
branches:
# TODO: Only declared during development
# should be removed
- develop
- chore/support-cicd-service-update
paths:
- 'Services/ZenDesk/**'
workflow_dispatch:
jobs:
support-service-update-process:
runs-on: ubuntu-latest
environment: production
steps:
- name: SSH to Server
uses: appleboy/[email protected]
env:
SUPPORT_SERVICE_PATHNAME: ${{ secrets.SUPPORT_SERVICE_PATHNAME }}
SUPPORT_SERVICE_SYSTEMD_NAME: ${{ secrets.SUPPORT_SERVICE_SYSTEMD_NAME }}
with:
host: ${{ secrets.SUPPORT_SERVICE_HOST }}
username: ${{ secrets.SUPPORT_SERVICE_USERNAME }}
key: ${{ secrets.SUPPORT_SERVICE_KEY }}
port: ${{ secrets.SUPPORT_SERVICE_PORT }}
envs: SUPPORT_SERVICE_PATHNAME,SUPPORT_SERVICE_SYSTEMD_NAME
script: |
checkout_branch="origin/chore/support-cicd-service-update"
if ! cd "$SUPPORT_SERVICE_PATHNAME"; then
echo "👹 Oops! Failed to change work directory"
exit 1
fi
echo "✅ Changed to work directory."
# TODO: Should use default branch not hard-typed
# due to testing, develop is hard typed here
if ! git fetch origin && git reset --hard "$checkout_branch" && git checkout "$checkout_branch"; then
echo "👹 Oops! Failed to change work directory"
exit 1
fi
commit_hash=$(git rev-parse HEAD)
commit_msg=$(git log -1 --pretty=format:"%s")
echo "✅ Pulled latest ($commit_hash), $commit_msg"
if ! sudo systemctl daemon-reload && sudo systemctl restart "$SUPPORT_SERVICE_SYSTEMD_NAME"; then
echo "👹 Oops! Failed restart the Systemd Service"
exit 1
fi
echo "✅ Restarted the service."
- name: Health Check
run: |
public_health_chech_endpoint="https://support-prod-eu-lon-1-01.flkservices.io.service/health"
response_message=$(curl -s "$public_health_chech_endpoint" | jq -r '.message')
if [[ "$response_message" != "OK" ]]; then
echo "👹 Oops! The health check failed."
exit 1
fi
echo "✅ The service is healthy!"