diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2786e80 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - uses: pnpm/action-setup@v2 + with: + version: 8 + + - name: Install dependencies + run: pnpm install + + - name: Typecheck API + working-directory: ./apps/api + run: pnpm typecheck + + - name: Test + run: pnpm test \ No newline at end of file diff --git a/.github/workflows/deploy-api.yml b/.github/workflows/deploy-api.yml new file mode 100644 index 0000000..f31505b --- /dev/null +++ b/.github/workflows/deploy-api.yml @@ -0,0 +1,55 @@ +name: Deploy API + +on: + workflow_call: + inputs: + environment: + description: "GitHub environment name" + required: true + type: string + sst-stage: + description: "SST deployment stage" + required: true + type: string + +permissions: + id-token: write + contents: read + packages: read + +jobs: + deploy-api: + runs-on: ubuntu-latest + environment: ${{ inputs.environment }} + # Concurrency group name ensures concurrent workflow runs wait for any in-progress job to finish + concurrency: + group: api-${{ inputs.environment }}-${{ github.ref }} + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + with: + version: 8 + - uses: actions/setup-node@v4 + with: + node-version: '20' + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ vars.ROLE_TO_ASSUME }} + aws-region: ${{ vars.AWS_REGION }} + + - name: Deploy API + working-directory: ./apps/api + run: pnpm sst deploy --stage ${{ inputs.sst-stage }} + env: + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + DATABASE_URL: ${{ secrets.DATABASE_URL }} + SG_CARS_TRENDS_API_TOKEN: ${{ secrets.SG_CARS_TRENDS_API_TOKEN }} + UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_REDIS_REST_TOKEN }} + UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }} + FEATURE_FLAG_RATE_LIMIT: ${{ vars.FEATURE_FLAG_RATE_LIMIT }} \ No newline at end of file diff --git a/.github/workflows/deploy-trigger.yml b/.github/workflows/deploy-trigger.yml new file mode 100644 index 0000000..e19de80 --- /dev/null +++ b/.github/workflows/deploy-trigger.yml @@ -0,0 +1,38 @@ +name: Deploy Trigger.dev + +on: + workflow_call: + inputs: + environment: + description: "GitHub environment name" + required: true + type: string + +permissions: + contents: read + packages: read + +jobs: + deploy-trigger: + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + environment: ${{ inputs.environment }} + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + with: + version: 8 + - uses: actions/setup-node@v4 + with: + node-version: '20' + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - name: Deploy Trigger.dev + working-directory: ./apps/updater + run: pnpm trigger:deploy + env: + TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/deploy-updater.yml b/.github/workflows/deploy-updater.yml new file mode 100644 index 0000000..809b0f4 --- /dev/null +++ b/.github/workflows/deploy-updater.yml @@ -0,0 +1,61 @@ +name: Deploy Updater + +on: + workflow_call: + inputs: + environment: + description: "GitHub environment name" + required: true + type: string + sst-stage: + description: "SST deployment stage" + required: true + type: string + +permissions: + id-token: write + contents: read + packages: read + +jobs: + deploy-updater: + runs-on: ubuntu-latest + environment: ${{ inputs.environment }} + # Concurrency group name ensures concurrent workflow runs wait for any in-progress job to finish + concurrency: + group: updater-${{ inputs.environment }}-${{ github.ref }} + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + with: + version: 8 + - uses: actions/setup-node@v4 + with: + node-version: '20' + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-region: ${{ vars.AWS_REGION }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + + - name: Run Drizzle Migrations + working-directory: ./apps/updater + run: pnpm migrate + env: + DATABASE_URL: ${{ secrets.DATABASE_URL }} + + - name: Deploy Updater + working-directory: ./apps/updater + run: pnpm sst deploy --stage ${{ inputs.sst-stage }} + env: + UPDATER_API_TOKEN: ${{ secrets.UPDATER_API_TOKEN }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + DATABASE_URL: ${{ secrets.DATABASE_URL }} + UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }} + UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_REDIS_REST_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 0000000..d5cc20f --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,27 @@ +name: Deploy (Dev) + +on: + push: + branches-ignore: + - "main" + - "release/**" + +permissions: + id-token: write + contents: read + packages: read + +jobs: + deploy-api: + uses: ./.github/workflows/deploy-api.yml + with: + environment: Development + sst-stage: dev + secrets: inherit + + deploy-updater: + uses: ./.github/workflows/deploy-updater.yml + with: + environment: Development + sst-stage: dev + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml new file mode 100644 index 0000000..4a34d9f --- /dev/null +++ b/.github/workflows/prod.yml @@ -0,0 +1,31 @@ +name: Deploy (Production) + +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + - "v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+" + +permissions: + id-token: write + contents: read + packages: read + +jobs: + deploy-api: + uses: ./.github/workflows/deploy-api.yml + with: + environment: Production + sst-stage: prod + secrets: inherit + + deploy-updater: + uses: ./.github/workflows/deploy-updater.yml + with: + environment: Production + sst-stage: prod + secrets: inherit + + deploy-trigger: + uses: ./.github/workflows/deploy-trigger.yml + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml new file mode 100644 index 0000000..6813d3a --- /dev/null +++ b/.github/workflows/staging.yml @@ -0,0 +1,50 @@ +name: Deploy (Staging) + +on: + push: + branches: + - "main" + - "release/**" + tags-ignore: + - "*" + +permissions: + id-token: write + contents: read + packages: read + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + with: + version: 8 + - uses: actions/setup-node@v4 + with: + node-version: '20' + cache: "pnpm" + - name: Install dependencies + run: pnpm install + - name: Typecheck API + working-directory: ./apps/api + run: pnpm typecheck + - name: Run tests + run: pnpm test + + deploy-api: + needs: test + uses: ./.github/workflows/deploy-api.yml + with: + environment: Staging + sst-stage: staging + secrets: inherit + + deploy-updater: + needs: test + uses: ./.github/workflows/deploy-updater.yml + with: + environment: Staging + sst-stage: staging + secrets: inherit \ No newline at end of file diff --git a/apps/api/.github/workflows/sst.deploy.yml b/apps/api/.github/workflows/sst.deploy.yml deleted file mode 100644 index 900f434..0000000 --- a/apps/api/.github/workflows/sst.deploy.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: SST Deploy - -on: - workflow_call: - inputs: - environment: - description: "GitHub environment name" - required: true - type: string - sst-stage: - description: "SST deployment stage" - required: true - type: string - secrets: - CLOUDFLARE_API_TOKEN: - required: true - DATABASE_URL: - required: true - SG_CARS_TRENDS_API_TOKEN: - required: true - UPSTASH_REDIS_REST_TOKEN: - required: true - UPSTASH_REDIS_REST_URL: - required: true - -permissions: - id-token: write - contents: read - packages: read - -jobs: - sst-deploy: - runs-on: ubuntu-latest - environment: ${{ inputs.environment }} - env: - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - DATABASE_URL: ${{ secrets.DATABASE_URL }} - SG_CARS_TRENDS_API_TOKEN: ${{ secrets.SG_CARS_TRENDS_API_TOKEN }} - UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_REDIS_REST_TOKEN }} - UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }} - FEATURE_FLAG_RATE_LIMIT: ${{ vars.FEATURE_FLAG_RATE_LIMIT }} - - # Concurrency group name ensures concurrent workflow runs wait for any in-progress job to finish - concurrency: - group: merge-${{ github.ref }} - - steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 - with: - version: latest - - uses: actions/setup-node@v4 - with: - node-version: latest - cache: "pnpm" - - name: Install dependencies - run: | - echo "//npm.pkg.github.com/:_authToken=${{ secrets.GH_TOKEN }}" >> .npmrc # Add auth token to .npmrc - pnpm install - - uses: aws-actions/configure-aws-credentials@v4 - with: - role-to-assume: ${{ vars.ROLE_TO_ASSUME }} - aws-region: ${{ vars.AWS_REGION }} -# - name: Deploy app -# run: | -# pnpm sst deploy --stage ${{ inputs.sst-stage }} diff --git a/apps/api/.github/workflows/sst.dev.yml b/apps/api/.github/workflows/sst.dev.yml deleted file mode 100644 index 64ee134..0000000 --- a/apps/api/.github/workflows/sst.dev.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Deployment (Dev) - -on: - push: - branches-ignore: - - "main" - - "release/**" - -permissions: - id-token: write - contents: read - packages: read - -jobs: - dev: - uses: ./.github/workflows/sst.deploy.yml - with: - environment: Development - sst-stage: dev - secrets: inherit diff --git a/apps/api/.github/workflows/sst.prod.yml b/apps/api/.github/workflows/sst.prod.yml deleted file mode 100644 index 2b352df..0000000 --- a/apps/api/.github/workflows/sst.prod.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Deployment (Prod) - -on: - push: - tags: - - "v[0-9]+.[0-9]+.[0-9]+" - - "v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+" - -permissions: - id-token: write - contents: read - packages: read - -jobs: - prod: - uses: ./.github/workflows/sst.deploy.yml - with: - environment: Production - sst-stage: prod - secrets: inherit diff --git a/apps/api/.github/workflows/sst.staging.yml b/apps/api/.github/workflows/sst.staging.yml deleted file mode 100644 index 271bcd2..0000000 --- a/apps/api/.github/workflows/sst.staging.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Deployment (Staging) - -on: - push: - branches: - - "main" - - "release/**" - tags-ignore: - - "*" - -permissions: - id-token: write - contents: read - packages: read - -jobs: - staging: - uses: ./.github/workflows/sst.deploy.yml - with: - environment: Staging - sst-stage: staging - secrets: inherit diff --git a/apps/api/package.json b/apps/api/package.json index cc78fa4..b59da29 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -11,7 +11,8 @@ "deploy": "sst deploy", "remove": "sst remove", "console": "sst console", - "typecheck": "tsc --noEmit" + "typecheck": "tsc --noEmit", + "lint": "biome check ." }, "dependencies": { "@hono/zod-validator": "^0.4.2", diff --git a/apps/updater/.github/workflows/sst.deploy.yml b/apps/updater/.github/workflows/sst.deploy.yml deleted file mode 100644 index aab30a6..0000000 --- a/apps/updater/.github/workflows/sst.deploy.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: SST Deploy - -on: - workflow_call: - inputs: - environment: - required: true - type: string - sst-stage: - required: true - type: string - secrets: - UPDATER_API_TOKEN: - required: true - CLOUDFLARE_API_TOKEN: - required: true - DATABASE_URL: - required: true - UPSTASH_REDIS_REST_URL: - required: true - UPSTASH_REDIS_REST_TOKEN: - required: true - AWS_ACCESS_KEY_ID: - required: true - AWS_SECRET_ACCESS_KEY: - required: true - -jobs: - sst-deploy: - runs-on: ubuntu-latest - environment: ${{ inputs.environment }} - env: - UPDATER_API_TOKEN: ${{ secrets.UPDATER_API_TOKEN }} - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - DATABASE_URL: ${{ secrets.DATABASE_URL }} - UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }} - UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_REDIS_REST_TOKEN }} - - # Concurrency group name ensures concurrent workflow runs wait for any in-progress job to finish - concurrency: - group: merge-${{ github.ref }} - - permissions: - id-token: write - contents: read - packages: read - - steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 - with: - version: latest - - uses: actions/setup-node@v4 - with: - node-version: latest - cache: 'pnpm' - - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-region: ${{ vars.AWS_REGION }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - - name: Install dependencies - run: | - pnpm install - - name: Run Drizzle Migrations - run: | - pnpm migrate - - name: Deploy - run: | - pnpm sst deploy --stage ${{ inputs.sst-stage }} diff --git a/apps/updater/.github/workflows/sst.prod.yml b/apps/updater/.github/workflows/sst.prod.yml deleted file mode 100644 index bcef34e..0000000 --- a/apps/updater/.github/workflows/sst.prod.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Deployment (Production) - -on: - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' - - 'v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+' - -permissions: - id-token: write - contents: read - packages: read - -jobs: - deploy: - uses: ./.github/workflows/sst.deploy.yml - with: - environment: Production - sst-stage: prod - secrets: inherit diff --git a/apps/updater/.github/workflows/sst.staging.yml b/apps/updater/.github/workflows/sst.staging.yml deleted file mode 100644 index aac3631..0000000 --- a/apps/updater/.github/workflows/sst.staging.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Deployment (Staging) - -on: - push: - branches: - - '*' - tags-ignore: - - '*' - -permissions: - id-token: write - contents: read - packages: read - -jobs: - test: - runs-on: ubuntu-latest - environment: Staging - steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Setup pnpm - uses: pnpm/action-setup@v4 - with: - version: latest - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: latest - cache: 'pnpm' - - name: Install dependencies - run: | - pnpm install - - name: Run tests - run: pnpm test - - deploy: - needs: test - uses: ./.github/workflows/sst.deploy.yml - with: - environment: Staging - sst-stage: staging - secrets: inherit diff --git a/apps/updater/.github/workflows/trigger-deploy.yml b/apps/updater/.github/workflows/trigger-deploy.yml deleted file mode 100644 index 79c5323..0000000 --- a/apps/updater/.github/workflows/trigger-deploy.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Deploy to Trigger.dev (Production) - -on: - push: - tags: - - "v[0-9]+.[0-9]+.[0-9]+" - - "v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+" - -permissions: - packages: read - -jobs: - deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 - with: - version: latest - - name: Use Node.js 20.x - uses: actions/setup-node@v4 - with: - node-version: "20.x" - cache: "pnpm" - - name: Install dependencies - run: | - pnpm install - - name: 🚀 Deploy Trigger.dev - env: - TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }} - run: | - pnpm trigger:deploy diff --git a/apps/updater/package.json b/apps/updater/package.json index db584e7..c3a3112 100644 --- a/apps/updater/package.json +++ b/apps/updater/package.json @@ -8,7 +8,8 @@ "test:coverage": "vitest run --coverage", "migrate": "drizzle-kit migrate", "trigger:dev": "trigger dev", - "trigger:deploy": "trigger deploy" + "trigger:deploy": "trigger deploy", + "lint": "biome check ." }, "author": "Ru Chern Chong ", "license": "MIT", diff --git a/packages/schema/package.json b/packages/schema/package.json index 7f5d48e..f38a671 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -4,7 +4,8 @@ "private": true, "main": "src/index.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"No tests\" && exit 0", + "lint": "biome check ." }, "author": "Ru Chern Chong ", "license": "MIT",