diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 6a41b011..c1d7583b 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -6,6 +6,14 @@ on: - main - master +permissions: + contents: read + deployments: write + pull-requests: read + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + jobs: lint: name: Lint and format @@ -89,9 +97,14 @@ jobs: working-directory: ./app run: npm test - build: - name: Build + preview-app-v2: + name: Preview App V2 runs-on: ubuntu-latest + environment: + name: preview-app-v2 + url: ${{ steps.deploy.outputs.url }} + env: + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_APP_V2_PROJECT_ID }} steps: - name: Check out repository @@ -100,16 +113,154 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v4 with: - node-version: '24' + node-version: '22' cache: 'npm' cache-dependency-path: package-lock.json - name: Install dependencies run: npm ci - - name: Build design system - run: npm run design-system:build + - name: Install Vercel CLI + run: npm install -g vercel - - name: Build application - working-directory: ./app - run: npm run build + - name: Pull Vercel environment + run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} + + - name: Build + run: vercel build --token=${{ secrets.VERCEL_TOKEN }} + + - name: Create GitHub deployment + uses: chrnorm/deployment-action@v2 + id: deployment + with: + token: ${{ secrets.GITHUB_TOKEN }} + environment: preview-app-v2 + ref: ${{ github.head_ref }} + + - name: Deploy Preview + id: deploy + run: | + url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}) + echo "url=$url" >> $GITHUB_OUTPUT + + - name: Update deployment status + if: always() + uses: chrnorm/deployment-status@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + state: ${{ job.status == 'success' && 'success' || 'failure' }} + environment-url: ${{ steps.deploy.outputs.url }} + + preview-website: + name: Preview Website + runs-on: ubuntu-latest + environment: + name: preview-website + url: ${{ steps.deploy.outputs.url }} + env: + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_WEBSITE_PROJECT_ID }} + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + cache: 'npm' + cache-dependency-path: package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Install Vercel CLI + run: npm install -g vercel + + - name: Pull Vercel environment + run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} + + - name: Build + run: vercel build --token=${{ secrets.VERCEL_TOKEN }} + + - name: Create GitHub deployment + uses: chrnorm/deployment-action@v2 + id: deployment + with: + token: ${{ secrets.GITHUB_TOKEN }} + environment: preview-website + ref: ${{ github.head_ref }} + + - name: Deploy Preview + id: deploy + run: | + url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}) + echo "url=$url" >> $GITHUB_OUTPUT + + - name: Update deployment status + if: always() + uses: chrnorm/deployment-status@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + state: ${{ job.status == 'success' && 'success' || 'failure' }} + environment-url: ${{ steps.deploy.outputs.url }} + + preview-calculator: + name: Preview Calculator + runs-on: ubuntu-latest + environment: + name: preview-calculator + url: ${{ steps.deploy.outputs.url }} + env: + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_CALCULATOR_PROJECT_ID }} + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + cache: 'npm' + cache-dependency-path: package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Install Vercel CLI + run: npm install -g vercel + + - name: Pull Vercel environment + run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} + working-directory: ./calculator + + - name: Build + run: vercel build --token=${{ secrets.VERCEL_TOKEN }} + working-directory: ./calculator + + - name: Create GitHub deployment + uses: chrnorm/deployment-action@v2 + id: deployment + with: + token: ${{ secrets.GITHUB_TOKEN }} + environment: preview-calculator + ref: ${{ github.head_ref }} + + - name: Deploy Preview + id: deploy + run: | + url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}) + echo "url=$url" >> $GITHUB_OUTPUT + working-directory: ./calculator + + - name: Update deployment status + if: always() + uses: chrnorm/deployment-status@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + state: ${{ job.status == 'success' && 'success' || 'failure' }} + environment-url: ${{ steps.deploy.outputs.url }} diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index 66c5b29c..da5fb626 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -1,56 +1,265 @@ -name: Push +name: Deploy Production on: push: - branches: [main] + branches: [master] workflow_dispatch: permissions: contents: read - pages: write - id-token: write + deployments: write + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} concurrency: - group: "pages" + group: production-deploy cancel-in-progress: false jobs: - build: + lint: + name: Lint and format + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '24' + cache: 'npm' + cache-dependency-path: package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Build design system + run: npm run design-system:build + + - name: Check formatting with Prettier + working-directory: ./app + run: npm run prettier + + - name: Run ESLint + working-directory: ./app + run: npm run eslint + + typecheck: + name: Type checking + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '24' + cache: 'npm' + cache-dependency-path: package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Build design system + run: npm run design-system:build + + - name: Run TypeScript type checks + working-directory: ./app + run: npm run typecheck + + test: + name: Tests runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '24' + cache: 'npm' + cache-dependency-path: package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Build design system + run: npm run design-system:build + + - name: Run design system tests + run: npm test --workspace=@policyengine/design-system + + - name: Run app tests + working-directory: ./app + run: npm test + + deploy-app-v2: + name: Deploy App V2 + needs: [lint, typecheck, test] + runs-on: ubuntu-latest + environment: + name: production-app-v2 + url: ${{ steps.deploy.outputs.url }} + env: + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_APP_V2_PROJECT_ID }} + steps: - name: Checkout uses: actions/checkout@v4 - + - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20' + node-version: '22' cache: 'npm' - cache-dependency-path: app/package-lock.json - + - name: Install dependencies - run: cd app && npm ci - + run: npm ci + + - name: Install Vercel CLI + run: npm install -g vercel + + - name: Pull Vercel environment + run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} + - name: Build - run: cd app && npm run build-with-types - env: - BASE_URL: /${{ github.event.repository.name }}/ - - - name: Setup Pages - uses: actions/configure-pages@v5 - - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - with: - path: ./app/dist - - deploy: + run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} + + - name: Create GitHub deployment + uses: chrnorm/deployment-action@v2 + id: deployment + with: + token: ${{ secrets.GITHUB_TOKEN }} + environment: production-app-v2 + + - name: Deploy to Vercel + id: deploy + run: | + url=$(vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}) + echo "url=$url" >> $GITHUB_OUTPUT + + - name: Update deployment status + if: always() + uses: chrnorm/deployment-status@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + state: ${{ job.status == 'success' && 'success' || 'failure' }} + environment-url: ${{ steps.deploy.outputs.url }} + + deploy-website: + name: Deploy Website + needs: [lint, typecheck, test] + runs-on: ubuntu-latest environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} + name: production-website + url: ${{ steps.deploy.outputs.url }} + env: + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_WEBSITE_PROJECT_ID }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Install Vercel CLI + run: npm install -g vercel + + - name: Pull Vercel environment + run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} + + - name: Build + run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} + + - name: Create GitHub deployment + uses: chrnorm/deployment-action@v2 + id: deployment + with: + token: ${{ secrets.GITHUB_TOKEN }} + environment: production-website + + - name: Deploy to Vercel + id: deploy + run: | + url=$(vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}) + echo "url=$url" >> $GITHUB_OUTPUT + + - name: Update deployment status + if: always() + uses: chrnorm/deployment-status@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + state: ${{ job.status == 'success' && 'success' || 'failure' }} + environment-url: ${{ steps.deploy.outputs.url }} + + deploy-calculator: + name: Deploy Calculator + needs: [lint, typecheck, test] runs-on: ubuntu-latest - needs: build + environment: + name: production-calculator + url: ${{ steps.deploy.outputs.url }} + env: + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_CALCULATOR_PROJECT_ID }} + steps: - - name: Deploy to GitHub Pages + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Install Vercel CLI + run: npm install -g vercel + + - name: Pull Vercel environment + run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} + working-directory: ./calculator + + - name: Build + run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} + working-directory: ./calculator + + - name: Create GitHub deployment + uses: chrnorm/deployment-action@v2 id: deployment - uses: actions/deploy-pages@v4 \ No newline at end of file + with: + token: ${{ secrets.GITHUB_TOKEN }} + environment: production-calculator + + - name: Deploy to Vercel + id: deploy + run: | + url=$(vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}) + echo "url=$url" >> $GITHUB_OUTPUT + working-directory: ./calculator + + - name: Update deployment status + if: always() + uses: chrnorm/deployment-status@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + state: ${{ job.status == 'success' && 'success' || 'failure' }} + environment-url: ${{ steps.deploy.outputs.url }} diff --git a/.gitignore b/.gitignore index 6a2198fc..084f4018 100644 --- a/.gitignore +++ b/.gitignore @@ -74,3 +74,4 @@ venv/ .venv .vercel .turbo +.env*.local