Skip to content
112 changes: 102 additions & 10 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,114 @@
name: deploy

on:
workflow_dispatch:
pull_request:
push:
branches:
- production

permissions:
contents: read

jobs:
deploy:
# --- PULL REQUEST PREVIEW DEPLOYMENT ---
deploy-preview:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 15

environment:
name: Preview
url: ${{ steps.netlify.outputs.unique-url }}
permissions:
id-token: write
contents: read
pull-requests: write

steps:
- name: Checkout
uses: actions/checkout@v7

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Serve Website
run: |
deno task start &
until curl --output /dev/null --silent --head --fail http://127.0.0.1:8005; do
printf '.'
sleep 1
done
env:
SIMPLECAST_API: ${{ secrets.SIMPLECAST_API }}
UMAMI_WEBSITE_ID: ${{ secrets.UMAMI_WEBSITE_ID }}
PAGE_SENSE_SCRIPT_SRC: ${{ secrets.PAGE_SENSE_SCRIPT_SRC }}
timeout-minutes: 5

- name: Download Staticalize
run: |
wget https://github.com/thefrontside/staticalize/releases/download/v0.2.2/staticalize-linux.tar.gz \
-O /tmp/staticalize-linux.tar.gz
tar -xzf /tmp/staticalize-linux.tar.gz -C /usr/local/bin
chmod +x /usr/local/bin/staticalize-linux

- name: Staticalize
run: |
staticalize-linux \
--site=http://127.0.0.1:8005 \
--output=built \
--base=https://frontside.com

- name: Deploy Preview to Netlify
id: netlify
run: |
PR_NUMBER="${{ github.event.pull_request.number }}"
COMMIT_SHA="${{ github.event.pull_request.head.sha }}"

# 1. DEPLOY TO NETLIFY: Capture the output in JSON format
DEPLOY_OUTPUT=$(npx netlify-cli deploy \
--dir=built \
--alias="pr-$PR_NUMBER" \
--message="Preview for PR #$PR_NUMBER at commit $COMMIT_SHA" \
--auth=${{ secrets.NETLIFY_AUTH_TOKEN }} \
--site=${{ secrets.NETLIFY_SITE_ID }} \
--json)

# 2. DYNAMICALLY PARSE VALUES: Bypasses hardcoding the site subdomain
DEPLOY_ID=$(echo "$DEPLOY_OUTPUT" | jq -r '.deploy_id')
SITE_NAME=$(echo "$DEPLOY_OUTPUT" | jq -r '.site_name')

# 3. Manually construct the separate isolated URLs using the parsed site name
UNIQUE_URL="https://${DEPLOY_ID}--${SITE_NAME}.netlify.app"
STABLE_URL="https://pr-${PR_NUMBER}--${SITE_NAME}.netlify.app"

# 4. Save keys to your step outputs
echo "unique-url=$UNIQUE_URL" >> $GITHUB_OUTPUT
echo "stable-url=$STABLE_URL" >> $GITHUB_OUTPUT

- name: Comment PR with Preview Link
uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v3.0.5
with:
# The header string creates a unique, invisible signature inside the comment HTML
header: netlify-preview-deploy
message: |
🚀 **Deploy Preview Ready!**

* **Stable Review Link:** ${{ steps.netlify.outputs.stable-url }}
* **Latest Commit Snapshot:** ${{ steps.netlify.outputs.unique-url }}

# --- PRODUCTION DEPLOYMENT ---
deploy-production:
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
timeout-minutes: 15
environment:
name: Production
url: https://frontside.com

steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Setup Deno
uses: denoland/setup-deno@v2
Expand Down Expand Up @@ -51,9 +142,10 @@ jobs:
--output=built \
--base=https://frontside.com

- name: Upload to Deno Deploy
uses: denoland/deployctl@v1
with:
project: frontside
entrypoint: "jsr:@std/http/file-server"
root: built
- name: Deploy to Production
run: |
npx netlify-cli deploy \
--dir=built \
--prod \
--auth=${{ secrets.NETLIFY_AUTH_TOKEN }} \
--site=${{ secrets.NETLIFY_SITE_ID }}