Update GitHub Actions to deploy to DigitalOcean after successful build
- Jekyll build runs on every push and PR (catches errors early) - DO deployment only triggers on push to main - Finds app by name via DO API, triggers /apps/:id/deploy endpoint - Uses DIGITALOCEAN_TOKEN secret for auth
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
name: Build Jekyll Site
|
||||
name: Build & Deploy Jekyll Site
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -27,3 +27,31 @@ jobs:
|
||||
JEKYLL_ENV=production bundle exec jekyll build
|
||||
env:
|
||||
JEKYLL_ENV: production
|
||||
|
||||
- name: Deploy to DigitalOcean App Platform
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
run: |
|
||||
# Find app ID by name
|
||||
APP_ID=$(curl -s -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
"https://api.digitalocean.com/v2/apps?page=1&page_limit=20" | \
|
||||
jq -r '.apps[] | select(.spec.name == "simcoetradesjournal") | .id')
|
||||
|
||||
if [ -z "$APP_ID" ] || [ "$APP_ID" = "null" ]; then
|
||||
echo "ERROR: Could not find DO app 'simcoetradesjournal'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Found DO app ID: $APP_ID"
|
||||
|
||||
# Trigger deployment
|
||||
DEPLOY_RESPONSE=$(curl -s -X POST \
|
||||
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
"https://api.digitalocean.com/v2/apps/$APP_ID/deploy")
|
||||
|
||||
DEPLOY_ID=$(echo "$DEPLOY_RESPONSE" | jq -r '.deployments[0].id')
|
||||
echo "Deployment triggered: $DEPLOY_ID"
|
||||
echo "Response: $DEPLOY_RESPONSE"
|
||||
env:
|
||||
DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }}
|
||||
|
||||
Reference in New Issue
Block a user