This reusable GitHub Actions workflow automates the deployment of services to a remote server with verification and optional email notifications.
The workflow performs these main tasks:
- Checkouts the repository and gets the current tag
- Deploys the service to a remote server using SSH
- Verifies the deployment by checking service availability
- Sends email notifications for successful/failed deployments (optional)
Create a workflow file (e.g., .github/workflows/deploy-service.yml
) in your repository:
name: Deploy Service
on:
workflow_dispatch:
jobs:
deploy:
uses: wrappid/workflows/.github/workflows/service-deploy.yml@main
with:
EMAIL_NOTIFY: "true"
EMAIL_SENDER_NAME: "CI/CD Pipeline"
PROJECT_HOSTED_URL: "https://your-service-url.com"
secrets:
PAT: ${{ secrets.PAT }}
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
REMOTE_SSH_KEY: ${{ secrets.REMOTE_SSH_KEY }}
REMOTE_SSH_USER: ${{ secrets.REMOTE_SSH_USER }}
REMOTE_PATH_OF_PROJECT_DEPLOYMENT_PATH: ${{ secrets.REMOTE_PATH_OF_PROJECT_DEPLOYMENT_PATH }}
EMAIL_SERVER_ADDRESS: ${{ secrets.EMAIL_SERVER_ADDRESS }}
EMAIL_SERVER_PORT: ${{ secrets.EMAIL_SERVER_PORT }}
EMAIL_USER_ID: ${{ secrets.EMAIL_USER_ID }}
EMAIL_USER_PASSWORD: ${{ secrets.EMAIL_USER_PASSWORD }}
EMAIL_TO: ${{ secrets.EMAIL_TO }}
EMAIL_CC: ${{ secrets.EMAIL_CC }}
EMAIL_BCC: ${{ secrets.EMAIL_BCC }}
Name | Required | Default | Description |
---|---|---|---|
EMAIL_NOTIFY |
Yes | "true" | Enable/disable email notifications |
EMAIL_SENDER_NAME |
No | - | Name to use as email sender |
PROJECT_HOSTED_URL |
Yes | - | URL where the service will be hosted |
PAT
: GitHub Personal Access TokenREMOTE_HOST
: Remote server hostname/IPREMOTE_SSH_KEY
: SSH private key for server accessREMOTE_SSH_USER
: SSH username for server accessREMOTE_PATH_OF_PROJECT_DEPLOYMENT_PATH
: Deployment path on remote server
EMAIL_SERVER_ADDRESS
: SMTP server addressEMAIL_SERVER_PORT
: SMTP server portEMAIL_USER_ID
: SMTP user IDEMAIL_USER_PASSWORD
: SMTP user passwordEMAIL_TO
: Recipient email address(es)
EMAIL_CC
: CC email address(es)EMAIL_BCC
: BCC email address(es)
- Checkouts the repository
- Gets the current tag version
- Deploys to remote server using SSH
- Verifies deployment by checking URL accessibility
- Outputs:
tag-version
: Deployed version tag
Two separate email notification jobs are included:
call-send-email-deployed
: Sends success notification when deployment completescall-send-email-failure
: Sends failure notification if deployment fails
- Remote server with SSH access configured
- Proper SSH key pair setup
- GitHub repository with proper permissions
- SMTP server access (if email notifications enabled)
- Service build artifacts ready for deployment
- Runs on: Ubuntu latest
- SSH Protocol: Version 2
- Required permissions: write-all
The workflow includes an automated deployment verification step that:
- Waits 10 seconds for service to start
- Checks the provided URL for HTTP 200 response
- Fails the workflow if service is not accessible
The workflow uses a deployment script (service-deploy.sh
) from the workflows repository that:
- Is executed on the remote server
- Receives deployment path and repository information
- Handles the actual service deployment process
- The workflow uses SSH for secure remote server access
- Deployment verification ensures service is actually running
- Email notifications provide immediate feedback on deployment status
- The deployment script is fetched from the workflows repository
- Verify SSH access to remote server
- Check deployment path permissions on remote server
- Ensure service URL is correctly configured
- Review SSH key configuration
- Verify email server settings if notifications aren't being received
- Use secrets for all sensitive information
- Ensure SSH keys have appropriate restrictions
- Limit deployment user permissions on remote server
- Use specific deployment paths for each service
- Regular rotation of access credentials
-
SSH Connection Failures
- Verify SSH key format and permissions
- Check remote host firewall settings
- Confirm SSH user access rights
-
Deployment Verification Failures
- Check service startup time (may need to increase wait time)
- Verify service port configuration
- Check service logs on remote server
-
Email Notification Issues
- Verify SMTP server settings
- Check email credentials
- Confirm recipient email addresses