Deploy to Cloudflare Workers #355
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
| 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 6 * * *" # Daily at 06:00 UTC (01:00 EST) — picks up scheduled posts | |
| jobs: | |
| Test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Hugo | |
| uses: peaceiris/actions-hugo@v2 | |
| with: | |
| # Pinned deliberately. 'latest' makes peaceiris/actions-hugo resolve the | |
| # version at build time via https://formulae.brew.sh/api/formula/hugo.json, | |
| # so a Homebrew API outage fails every job before Hugo is even installed | |
| # (run 29658115531). A pinned version downloads straight from GitHub | |
| # releases. Bump intentionally after verifying the site builds clean. | |
| hugo-version: '0.164.0' | |
| 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: | |
| # Pinned deliberately. 'latest' makes peaceiris/actions-hugo resolve the | |
| # version at build time via https://formulae.brew.sh/api/formula/hugo.json, | |
| # so a Homebrew API outage fails every job before Hugo is even installed | |
| # (run 29658115531). A pinned version downloads straight from GitHub | |
| # releases. Bump intentionally after verifying the site builds clean. | |
| hugo-version: '0.164.0' | |
| 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') || github.event_name == 'schedule' | |
| 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: | |
| # Pinned deliberately. 'latest' makes peaceiris/actions-hugo resolve the | |
| # version at build time via https://formulae.brew.sh/api/formula/hugo.json, | |
| # so a Homebrew API outage fails every job before Hugo is even installed | |
| # (run 29658115531). A pinned version downloads straight from GitHub | |
| # releases. Bump intentionally after verifying the site builds clean. | |
| hugo-version: '0.164.0' | |
| 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') || github.event_name == 'schedule' | |
| 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: | |
| # Pinned deliberately. 'latest' makes peaceiris/actions-hugo resolve the | |
| # version at build time via https://formulae.brew.sh/api/formula/hugo.json, | |
| # so a Homebrew API outage fails every job before Hugo is even installed | |
| # (run 29658115531). A pinned version downloads straight from GitHub | |
| # releases. Bump intentionally after verifying the site builds clean. | |
| hugo-version: '0.164.0' | |
| 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')" |