diff --git a/.gcloudignore b/.gcloudignore new file mode 100644 index 000000000..f5c1ed746 --- /dev/null +++ b/.gcloudignore @@ -0,0 +1,8 @@ +# This file specifies files that are *not* uploaded to Google Cloud +# Only upload app.yaml and the built dist/ directory + +# Exclude ALL source and config files +* +!app.yaml +!dist/ +!dist/** \ No newline at end of file diff --git a/.github/scripts/build-with-vite.sh b/.github/scripts/build-with-vite.sh new file mode 100755 index 000000000..ad56cf54a --- /dev/null +++ b/.github/scripts/build-with-vite.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +echo "Starting build process with Vite..." +npm run build +echo "Build completed. Contents of dist/:" +ls -la dist/ +echo "Verifying index.html exists:" +test -f dist/index.html && echo "✓ index.html found" || echo "✗ index.html missing" \ No newline at end of file diff --git a/.github/workflows/npm_test.yml b/.github/workflows/npm_test.yaml similarity index 100% rename from .github/workflows/npm_test.yml rename to .github/workflows/npm_test.yaml diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml new file mode 100644 index 000000000..9982fe1ff --- /dev/null +++ b/.github/workflows/pull_request.yaml @@ -0,0 +1,27 @@ +name: Test + +on: + pull_request: + branches: + - '**' + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run tests (includes type checking) + run: npm test + \ No newline at end of file diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml new file mode 100644 index 000000000..d972d329e --- /dev/null +++ b/.github/workflows/push.yaml @@ -0,0 +1,64 @@ +name: Deploy to App Engine + +on: + push: + branches: + - master + +permissions: + id-token: write + contents: read + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run tests (includes type checking) + run: npm test + + deploy: + runs-on: ubuntu-latest + needs: test + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Build application with Vite + run: .github/scripts/build-with-vite.sh + + - name: Authenticate to Google Cloud + uses: google-github-actions/auth@v2 + with: + workload_identity_provider: "projects/83599293185/locations/global/workloadIdentityPools/prod-github-provider/providers/prod-github-provider" + service_account: "workflow-identity-provider@policyengine-app-v2.iam.gserviceaccount.com" + + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v2 + with: + project_id: policyengine-app-v2 + + - name: Deploy to App Engine + run: gcloud app deploy --quiet --project policyengine-app-v2 \ No newline at end of file diff --git a/app.yaml b/app.yaml new file mode 100644 index 000000000..779824dcf --- /dev/null +++ b/app.yaml @@ -0,0 +1,39 @@ +runtime: nodejs20 + +env_variables: + GOOGLE_NODE_RUN_SCRIPTS: "" + +handlers: +# Vite builds assets with hashed filenames in /assets/ +- url: /assets + static_dir: dist/assets + secure: always + expiration: "365d" + +# Common static files +- url: /favicon.ico + static_files: dist/favicon.ico + upload: dist/favicon.ico + secure: always + +- url: /manifest.json + static_files: dist/manifest.json + upload: dist/manifest.json + secure: always + +# Any other static files in dist root +- url: /(.+\.(js|css|png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot))$ + static_files: dist/\1 + upload: dist/(.+\.(js|css|png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot))$ + secure: always + expiration: "365d" + +# Handle React Router - serve index.html for all other routes +- url: /.* + static_files: dist/index.html + upload: dist/index.html + secure: always + +automatic_scaling: + min_instances: 0 + max_instances: 5 \ No newline at end of file diff --git a/package.json b/package.json index 2cbea2eab..fed7b3c90 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "version": "0.0.0", "scripts": { "dev": "vite", - "build": "tsc && vite build", + "build": "vite build", + "build-with-types": "tsc --noEmit && vite build", "preview": "vite preview", "typecheck": "tsc --noEmit", "lint": "npm run eslint && npm run stylelint",