All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 19s
103 lines
4.9 KiB
YAML
103 lines
4.9 KiB
YAML
# FILE: .gitea/workflows/deploy.yml
|
|
#
|
|
# note to AI - the order in this file matters - also, minor changes to this file can have big impacts and is easy to break
|
|
name: Deploy to Web Server flyer-crawler.projectium.com
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main # This pipeline runs only on a push to the 'main' branch.
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: projectium.com # This job runs on your self-hosted Gitea runner.
|
|
|
|
# Environment variables are used to pass secrets and configuration to the steps below.
|
|
# These must be configured as secrets in your Gitea repository settings.
|
|
env:
|
|
# Public keys needed for the React build process.
|
|
REACT_APP_SUPABASE_URL: ${{ secrets.REACT_APP_SUPABASE_URL }}
|
|
REACT_APP_SUPABASE_ANON_KEY: ${{ secrets.REACT_APP_SUPABASE_ANON_KEY }}
|
|
# Supabase token for non-interactive CLI authentication.
|
|
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
|
|
# The project ID for linking the Supabase CLI.
|
|
SUPABASE_PROJECT_ID: ${{ secrets.SUPABASE_PROJECT_ID }}
|
|
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v3
|
|
|
|
# Add this NEW STEP FOR DEBUGGING
|
|
- name: Show Git REF
|
|
run: |
|
|
echo "Gitea ref: ${{ gitea.ref }}"
|
|
echo "Gitea ref_name: ${{ gitea.ref_name }}" # often more useful (e.g., 'main' or 'my-feature-branch')
|
|
echo "Gitea ref_type: ${{ gitea.ref_type }}" # 'branch' or 'tag'
|
|
echo "Gitea SHA: ${{ gitea.sha }}"
|
|
echo "Triggering actor: ${{ gitea.actor }}"
|
|
echo "Repository: ${{ gitea.repository }}"
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: '20'
|
|
cache: 'npm' # Cache npm dependencies to speed up subsequent builds.
|
|
# Use a glob pattern to find the lock file, making the path more resilient.
|
|
cache-dependency-path: '**/package-lock.json'
|
|
|
|
- name: Install Dependencies
|
|
run: npm ci # 'ci' is faster and safer for CI/CD than 'install'.
|
|
|
|
# --- Backend Deployment ---
|
|
- name: Deploy Supabase Edge Functions
|
|
# Pass the access token as an environment variable directly to this step
|
|
# This ensures the Supabase CLI can authenticate.
|
|
env:
|
|
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
|
|
run: |
|
|
echo "Deploying Edge Functions to Supabase project: ${{ env.SUPABASE_PROJECT_ID }}"
|
|
# The SUPABASE_ACCESS_TOKEN env var handles login automatically.
|
|
# The --project-ref flag links the CLI to your project.
|
|
npm exec -- supabase functions deploy system-check --project-ref ${{ env.SUPABASE_PROJECT_ID }}
|
|
npm exec -- supabase functions deploy delete-user --project-ref ${{ env.SUPABASE_PROJECT_ID }}
|
|
npm exec -- supabase functions deploy seed-database --project-ref ${{ env.SUPABASE_PROJECT_ID }}
|
|
|
|
# Debug step: Verify environment variables are present before build
|
|
- name: Debug Environment Variables
|
|
# This step now contains comprehensive checks to validate the secret.
|
|
env:
|
|
# We map the Gitea secret to a temporary env var for shell access.
|
|
DEBUG_SECRET: ${{ secrets.VITE_GOOGLE_GENAI_API_KEY }}
|
|
run: |
|
|
echo "--- Running Comprehensive Secret Debug ---"
|
|
echo "Step 1: Check via 'if' condition:"
|
|
if [ "${{ secrets.VITE_GOOGLE_GENAI_API_KEY != '' }}" == "true" ]; then
|
|
echo " ✅ SUCCESS: The 'if' condition sees the secret is NOT empty."
|
|
else
|
|
echo " ❌ FAILURE: The 'if' condition sees the secret IS EMPTY."
|
|
fi
|
|
echo "Step 2: Check via shell variable:"
|
|
if [ -n "$DEBUG_SECRET" ]; then
|
|
echo " ✅ SUCCESS: The shell variable \$DEBUG_SECRET is NOT empty."
|
|
else
|
|
echo " ❌ FAILURE: The shell variable \$DEBUG_SECRET is EMPTY."
|
|
fi
|
|
echo "--- End of Debug ---"
|
|
|
|
# --- Frontend Deployment ---
|
|
- name: Build React Application
|
|
# We set the environment variable directly in the command line for this step.
|
|
# This maps the Gitea secret to the environment variable the application expects.
|
|
run: VITE_API_KEY=${{ secrets.VITE_GOOGLE_GENAI_API_KEY }} npm run build
|
|
|
|
- name: Deploy Frontend via Local Copy
|
|
run: |
|
|
echo "Deploying frontend files to local web server path..."
|
|
# Ensure the destination directory exists before copying.
|
|
mkdir -p "/var/www/flyer-crawler.projectium.com"
|
|
# Use rsync to efficiently copy files from the 'dist' output to the web server directory.
|
|
# The '--delete' flag removes old files from the destination, ensuring a clean deployment.
|
|
# We exclude '.env.local' to prevent deleting the server-specific environment file.
|
|
rsync -avz --delete --exclude '.env.local' dist/ "/var/www/flyer-crawler.projectium.com"
|
|
echo "Local deployment complete."
|