Skip to content

Deploy to Cloudflare Workers #87

Deploy to Cloudflare Workers

Deploy to Cloudflare Workers #87

name: Deploy to Cloudflare Workers
on:
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
required: true
default: 'development'
type: choice
options:
- development
- mst
- qas
- tst
- staging
- production
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "0 0 * * *" # Daily builds for content updates
jobs:
Test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest'
extended: true
- name: Test Hugo build
run: |
cd blog
hugo --panicOnWarning --minify --gc --cleanDestinationDir --destination public --baseURL https://support.tools
- name: Check for expired content
run: |
cd blog
hugo list expired
Deploy-NonProd:
runs-on: ubuntu-latest
needs: Test
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main') || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment != 'production')
strategy:
matrix:
environment:
- ${{ github.event.inputs.environment || 'development' }}
environment:
name: ${{ matrix.environment }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest'
extended: true
- name: Build Hugo site
run: |
cd blog
hugo --minify --gc --cleanDestinationDir --baseURL https://support.tools
- name: Install Wrangler
run: npm install -g wrangler
- name: Deploy to Cloudflare Workers
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: |
echo "Deploying to ${{ matrix.environment }} environment"
wrangler deploy --env ${{ matrix.environment }}
- name: Verify deployment
run: |
case "${{ matrix.environment }}" in
"production")
ENDPOINT="https://support.tools"
;;
"staging")
ENDPOINT="https://stg.support.tools"
;;
"development")
ENDPOINT="https://dev.support.tools"
;;
"mst")
ENDPOINT="https://mst.support.tools"
;;
"qas")
ENDPOINT="https://qas.support.tools"
;;
"tst")
ENDPOINT="https://tst.support.tools"
;;
esac
echo "Checking deployment at $ENDPOINT"
# Wait a bit for deployment to propagate
sleep 30
# Check if site is responding
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$ENDPOINT" || echo "000")
if [ "$HTTP_STATUS" = "200" ]; then
echo "✅ Deployment successful - site is responding"
else
echo "❌ Deployment may have issues - HTTP status: $HTTP_STATUS"
exit 1
fi
# Check health endpoint
HEALTH_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$ENDPOINT/healthz" || echo "000")
if [ "$HEALTH_STATUS" = "200" ] || [ "$HEALTH_STATUS" = "301" ]; then
echo "✅ Health check passed"
else
echo "⚠️ Health check returned status: $HEALTH_STATUS"
fi
Deploy-Staging:
runs-on: ubuntu-latest
needs: Test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment:
name: staging
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest'
extended: true
- name: Build Hugo site
run: |
cd blog
hugo --minify --gc --cleanDestinationDir --baseURL https://support.tools
- name: Install Wrangler
run: npm install -g wrangler
- name: Deploy to Cloudflare Workers
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: |
echo "Deploying to staging environment"
wrangler deploy --env staging
- name: Verify staging deployment
run: |
echo "Checking staging deployment at https://stg.support.tools"
sleep 30
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://stg.support.tools" || echo "000")
if [ "$HTTP_STATUS" = "200" ]; then
echo "✅ Staging deployment successful"
else
echo "❌ Staging deployment failed - HTTP status: $HTTP_STATUS"
exit 1
fi
Deploy-Production:
runs-on: ubuntu-latest
needs: Deploy-Staging
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment:
name: production
url: https://support.tools
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest'
extended: true
- name: Build Hugo site
run: |
cd blog
hugo --minify --gc --cleanDestinationDir --baseURL https://support.tools
- name: Install Wrangler
run: npm install -g wrangler
- name: Deploy to Cloudflare Workers
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: |
echo "Deploying to production environment"
wrangler deploy --env production
- name: Verify production deployment
run: |
echo "Checking production deployment at https://support.tools"
sleep 30
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://support.tools" || echo "000")
if [ "$HTTP_STATUS" = "200" ]; then
echo "✅ Production deployment successful"
else
echo "❌ Production deployment failed - HTTP status: $HTTP_STATUS"
exit 1
fi
- name: Create deployment notification
run: |
echo "🚀 Successfully deployed to production!"
echo "URL: https://support.tools"
echo "Version: ${{ github.sha }}"
echo "Deployed at: $(date -u +'%Y-%m-%d %H:%M:%S UTC')"