Skip to content

Conversation

@NiloCK
Copy link
Collaborator

@NiloCK NiloCK commented May 23, 2025

No description provided.

Comment on lines +12 to +109
runs-on: ubuntu-latest
steps:
- name: Trigger server-side deployment
run: |
echo "🚀 Triggering server-side deployment..."
echo "Reason: ${{ github.event.inputs.reason || 'Push to master' }}"
echo "Commit: ${{ github.sha }}"
echo "Branch: ${{ github.ref_name }}"

- name: Configure SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.DO_SSH_KEY }}
name: id_rsa
known_hosts: ${{ secrets.KNOWN_HOSTS }}

- name: Execute deployment on server
run: |
echo "Connecting to server and executing deployment..."
ssh ${{ secrets.DO_USERNAME }}@eduquilt.com << 'EOF'
set -e

# Log deployment start
echo "=== Deployment started at $(date) ==="
echo "Triggered by: ${{ github.event.inputs.reason || 'Push to master' }}"
echo "Commit: ${{ github.sha }}"
echo "Branch: ${{ github.ref_name }}"

# Change to deployment script directory
cd /home/skuilder

# Execute the deployment script
./deploy-express-minimal-downtime.sh

echo "=== Deployment completed at $(date) ==="
EOF

- name: Verify deployment
run: |
echo "Verifying Express API deployment..."
max_retries=3
retry_count=0
while [ $retry_count -lt $max_retries ]; do
response=$(curl -sS https://eduquilt.com/express)
if [[ $? -ne 0 ]]; then
echo "Error: Failed to fetch https://eduquilt.com/express"
retry_count=$((retry_count+1))
if [ $retry_count -lt $max_retries ]; then
echo "Retrying in 5 seconds... (Attempt $retry_count of $max_retries)"
sleep 5
continue
else
exit 1
fi
fi

if echo "$response" | grep -q "${{ github.SHA }}"; then
echo "Success. Current version found in production"

# Log deployment success
echo "✅ Express API deployed successfully with version ${{ github.SHA }}"
echo "✅ Deployment triggered by: ${{ github.event.inputs.reason || 'Push to master' }}"
echo "✅ Deployment timestamp: $(date -u)"

exit 0
else
echo "Current version not found in production. Retrying..."
retry_count=$((retry_count+1))
if [ $retry_count -lt $max_retries ]; then
echo "Retrying in 5 seconds... (Attempt $retry_count of $max_retries)"
sleep 5
else
echo "Error! Max retries reached. Current version not reported by production."
echo "Response received:"
echo "$response"
exit 1
fi
fi
done

- name: Deployment failure cleanup
if: failure()
run: |
echo "🔄 Deployment failed. Checking for rollback options..."
ssh ${{ secrets.DO_USERNAME }}@eduquilt.com << 'EOF'
cd /home/skuilder
echo "Available builds for potential rollback:"
./manage-deployment.sh list

echo "Current service status:"
./manage-deployment.sh status

echo "Recent service logs:"
./manage-deployment.sh logs 20 || true
EOF

echo "💡 To rollback manually, SSH to server and run:"
echo " ./manage-deployment.sh rollback <build-name>"

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
@NiloCK NiloCK merged commit ac2de38 into master May 23, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants