Skip to content

Merge pull request #68 from OSSPhilippines/update-place-black-scoop-c… #59

Merge pull request #68 from OSSPhilippines/update-place-black-scoop-c…

Merge pull request #68 from OSSPhilippines/update-place-black-scoop-c… #59

name: Build and Deploy Places Data
on:
push:
branches:
- main
paths:
- 'apps/web/src/data/places/*.json'
- 'scripts/build-places-index.ts'
- 'scripts/build-stats.ts'
workflow_dispatch: # Allow manual triggers
permissions:
contents: write
jobs:
build-and-deploy:
name: Build Index and Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for proper git operations
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check if this is an auto-generated commit
id: check_trigger
run: |
COMMIT_MSG=$(git log -1 --pretty=%B)
if [[ "$COMMIT_MSG" == "chore: auto-generate places index and stats" ]]; then
echo "is_auto_generated=true" >> $GITHUB_OUTPUT
echo "⏭️ Skipping workflow - this is an auto-generated commit"
echo ""
echo "ℹ️ This commit was created by the previous workflow run."
echo " The index files are already up to date."
echo ""
echo "✅ Vercel will deploy this commit automatically."
else
echo "is_auto_generated=false" >> $GITHUB_OUTPUT
echo "ℹ️ This is a regular commit - will build and generate index"
fi
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "is_manual=true" >> $GITHUB_OUTPUT
echo "ℹ️ Manual trigger detected"
else
echo "is_manual=false" >> $GITHUB_OUTPUT
fi
- name: Setup Node.js
if: steps.check_trigger.outputs.is_auto_generated == 'false'
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup pnpm
if: steps.check_trigger.outputs.is_auto_generated == 'false'
uses: pnpm/action-setup@v3
with:
version: 9.0.0
- name: Get pnpm store directory
if: steps.check_trigger.outputs.is_auto_generated == 'false'
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
if: steps.check_trigger.outputs.is_auto_generated == 'false'
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
if: steps.check_trigger.outputs.is_auto_generated == 'false'
run: pnpm install --frozen-lockfile
- name: Validate changed place files
if: steps.check_trigger.outputs.is_auto_generated == 'false'
run: |
# Get list of changed place files
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD | grep 'apps/web/src/data/places/.*\.json$' || true)
if [ -n "$CHANGED_FILES" ]; then
echo "✅ Validation already passed in PR review"
echo "Re-validating changed files as a safety check:"
echo "$CHANGED_FILES"
echo ""
VALIDATION_FAILED=false
for file in $CHANGED_FILES; do
if [ -f "$file" ]; then
echo "Validating $file..."
if ! pnpm validate:place "$file"; then
VALIDATION_FAILED=true
fi
echo ""
fi
done
if [ "$VALIDATION_FAILED" = true ]; then
echo "❌ Validation failed! This should not happen if PR validation passed."
echo "Please check the validation workflow."
exit 1
fi
echo "✅ All files validated successfully"
else
echo "ℹ️ No place files changed, skipping validation"
fi
- name: Build places index
if: steps.check_trigger.outputs.is_auto_generated == 'false'
run: pnpm build:index
- name: Build stats file
if: steps.check_trigger.outputs.is_auto_generated == 'false'
run: pnpm build:stats
- name: Check for changes
if: steps.check_trigger.outputs.is_auto_generated == 'false'
id: check_changes
run: |
if git diff --quiet apps/web/src/data/places.json apps/web/src/data/stats.json; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Commit built files
if: steps.check_trigger.outputs.is_auto_generated == 'false' && steps.check_changes.outputs.changed == 'true'
id: commit
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add apps/web/src/data/places.json apps/web/src/data/stats.json
git commit -m "chore: auto-generate places index and stats"
echo "📤 Pushing changes to main..."
git push
# Get the commit SHA that was just pushed
COMMIT_SHA=$(git rev-parse HEAD)
echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT
echo "✅ Pushed commit: $COMMIT_SHA"
- name: Deployment complete
if: steps.check_trigger.outputs.is_auto_generated == 'false' && steps.check_changes.outputs.changed == 'true'
run: |
echo "✅ Places data built and committed successfully!"
echo ""
echo "📦 Updated files:"
echo " - apps/web/src/data/places.json"
echo " - apps/web/src/data/stats.json"
echo ""
echo "🚀 The auto-generated commit will trigger Vercel to deploy"
echo " Next workflow run will skip rebuilding (to avoid infinite loop)"
echo ""
echo "🔗 Check deployment at: https://vercel.com/dashboard"
- name: Webhook fallback (optional)
if: false # Disabled - Using GitHub integration instead
env:
VERCEL_DEPLOY_HOOK: ${{ secrets.VERCEL_DEPLOY_HOOK }}
run: |
if [ -z "$VERCEL_DEPLOY_HOOK" ]; then
echo "❌ VERCEL_DEPLOY_HOOK not set!"
echo "Please add your Vercel Deploy Hook URL to repository secrets."
echo ""
echo "To create a deploy hook:"
echo "1. Go to Vercel Dashboard → Your Project → Settings → Git → Deploy Hooks"
echo "2. Create a new deploy hook for the 'main' branch"
echo "3. Copy the URL and add it as VERCEL_DEPLOY_HOOK secret in GitHub"
exit 1
fi
echo "🚀 Triggering Vercel deployment..."
echo "📦 Repository: ${{ github.repository }}"
echo "🌿 Branch: main"
echo "📝 Commit: ${{ steps.commit.outputs.commit_sha }}"
echo ""
# Trigger deployment
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "$VERCEL_DEPLOY_HOOK")
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
BODY=$(echo "$RESPONSE" | sed '$d')
echo "📊 HTTP Status: $HTTP_CODE"
echo "📄 Response:"
echo "$BODY" | jq '.' 2>/dev/null || echo "$BODY"
echo ""
# Check if successful
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
JOB_ID=$(echo "$BODY" | jq -r '.job.id' 2>/dev/null)
JOB_STATE=$(echo "$BODY" | jq -r '.job.state' 2>/dev/null)
if [ -n "$JOB_ID" ] && [ "$JOB_ID" != "null" ]; then
echo "✅ Deployment triggered successfully!"
echo "📋 Job ID: $JOB_ID"
echo "📊 State: $JOB_STATE"
echo ""
# Extract project ID from webhook URL
PROJECT_ID=$(echo "$VERCEL_DEPLOY_HOOK" | grep -oP 'prj_[^/]+' || echo "unknown")
echo "🆔 Project ID: $PROJECT_ID"
echo ""
# Wait a bit for deployment to start
echo "⏳ Waiting 5 seconds for deployment to initialize..."
sleep 5
# Try to get more info about the deployment
echo "🔍 Checking deployment status..."
echo ""
echo "🔗 Direct links to check:"
echo " Dashboard: https://vercel.com/dashboard"
if [ "$PROJECT_ID" != "unknown" ]; then
echo " Project: https://vercel.com/${PROJECT_ID}"
fi
echo ""
echo "⚠️ IMPORTANT: If deployments are not appearing in your dashboard,"
echo " this usually means one of the following:"
echo ""
echo " 1. ❌ Deploy hook is for a DIFFERENT Vercel project"
echo " → Verify the project ID matches: $PROJECT_ID"
echo ""
echo " 2. ❌ You're viewing the WRONG Vercel account/team"
echo " → Make sure you're logged into the correct account"
echo ""
echo " 3. ❌ Deploy hook is for a PREVIEW/BRANCH deployment"
echo " → Check all deployments, not just production"
echo ""
echo " 4. ⚙️ Webhook creates job but Vercel build is failing silently"
echo " → The deployment might be failing before it shows up"
echo ""
echo "🔧 RECOMMENDED SOLUTION:"
echo " Instead of using deploy hooks, use Vercel's GitHub integration"
echo " with an 'Ignored Build Step' to control when builds run."
echo ""
echo " This will show ALL deployments in your dashboard properly."
else
echo "⚠️ Deployment may have been triggered, but response format unexpected"
echo "Check your Vercel dashboard to confirm"
fi
else
echo "❌ Deployment trigger failed with HTTP $HTTP_CODE"
echo "Response: $BODY"
exit 1
fi