Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 1m0s
130 lines
5.8 KiB
YAML
130 lines
5.8 KiB
YAML
# FILE: .gitea/workflows/deploy.yml
|
|
#
|
|
# deploy to production which is an ubuntu co-lo server with nginx + postgres
|
|
#
|
|
# 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.
|
|
# (Empty in original, assuming secrets are injected below)
|
|
|
|
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' # Re-enable the cache. If this fails, we will remove it again.
|
|
cache-dependency-path: '**/package-lock.json'
|
|
|
|
# The setup-node action with caching handles installation correctly.
|
|
# If dependencies are not found in cache, it will run 'npm ci' automatically.
|
|
# If they are found, it restores them. This is the standard, reliable way.
|
|
- name: Install Dependencies
|
|
run: npm ci # 'ci' is faster and safer for CI/CD than 'install'.
|
|
|
|
# -----------------------------------------------------------------------
|
|
# ADD THIS NEW STEP HERE
|
|
# -----------------------------------------------------------------------
|
|
- name: Fix Package Scripts for CI
|
|
run: |
|
|
npm pkg set scripts.test:integration="vitest run -c vitest.config.integration.ts"
|
|
npm pkg set scripts.start:server="ts-node --esm server.ts"
|
|
|
|
# Also ensure test files are moved if they haven't been committed yet
|
|
# This prevents the 'Run Unit Tests' step from crashing on integration files
|
|
if [ -f src/services/db.test.ts ]; then
|
|
mv src/services/db.test.ts src/services/db.integration.test.ts
|
|
fi
|
|
if [ -f src/services/shopping-list.test.ts ]; then
|
|
mv src/services/shopping-list.test.ts src/services/shopping-list.integration.test.ts
|
|
fi
|
|
# -----------------------------------------------------------------------
|
|
|
|
# --- NEW DEBUGGING STEPS ---
|
|
- name: Verify Project Structure
|
|
run: |
|
|
echo "--- Current Working Directory ---"
|
|
pwd
|
|
echo "--- Listing Root Directory ---"
|
|
ls -alF
|
|
echo "--- Listing SRC Directory ---"
|
|
ls -alF src
|
|
|
|
- name: Lint TypeScript Code
|
|
run: npm run lint # Run the linter to check for code quality issues.
|
|
continue-on-error: true # Allows the workflow to proceed even if linting fails.
|
|
|
|
- name: Run Unit Tests
|
|
# We override the production DB variables for this step only.
|
|
# The 'global-setup.ts' will use these to connect to the test database,
|
|
# create the schema, and seed data before tests run.
|
|
env:
|
|
DB_HOST: ${{ secrets.DB_HOST }}
|
|
DB_PORT: ${{ secrets.DB_PORT }}
|
|
DB_USER: ${{ secrets.DB_USER }}
|
|
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
|
|
DB_DATABASE: "flyer-crawler-test" # Hardcode the test database name
|
|
DB_NAME: "flyer-crawler-test" # REQUIRED: Used by connection.ts to match the test setup
|
|
run: npm test # Run the test suite against the temporary test database.
|
|
# also Run the test suite to ensure code correctness.
|
|
|
|
- name: Run Integration Tests
|
|
# This step runs tests that require a live backend server.
|
|
env:
|
|
DB_HOST: ${{ secrets.DB_HOST }}
|
|
DB_PORT: ${{ secrets.DB_PORT }}
|
|
DB_USER: ${{ secrets.DB_USER }}
|
|
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
|
|
DB_DATABASE: "flyer-crawler-test"
|
|
DB_NAME: "flyer-crawler-test" # REQUIRED: Used by connection.ts
|
|
JWT_SECRET: "test-secret-for-ci" # Use a fixed secret for CI
|
|
run: npm run test:integration
|
|
|
|
- name: Archive Code Coverage Report
|
|
# This action saves the generated HTML coverage report as a downloadable artifact.
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: code-coverage-report
|
|
path: coverage/
|
|
|
|
# --- 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." |