-
-
Notifications
You must be signed in to change notification settings - Fork 0
add gha to trigger server-side express deploy #713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| name: deploy-express-serverside | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| reason: | ||
| description: 'Reason for deploying Express API' | ||
| required: true | ||
| default: 'Manual trigger' | ||
|
|
||
| jobs: | ||
| deploy-express: | ||
| 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>" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium