From 3c8a0a455063273178633201c4ca79564707f54b Mon Sep 17 00:00:00 2001 From: Na'aman Hirschfeld Date: Thu, 30 Nov 2023 18:05:46 +0100 Subject: [PATCH] chore: updated github workflows --- .github/{workflows => actions}/build.yaml | 34 ++------ .github/actions/deploy_firebase.yaml | 79 +++++++++++++++++++ .github/workflows/build-api-gateway.yaml | 7 +- .github/workflows/build-cohere-connector.yaml | 5 +- .../workflows/build-dashboard-backend.yaml | 4 +- .github/workflows/build-openai-connector.yaml | 8 +- .github/workflows/deploy-frontend-preview.yml | 16 ++++ .github/workflows/deploy-frontend.yml | 78 ++---------------- .idea/misc.xml | 1 - 9 files changed, 128 insertions(+), 104 deletions(-) rename .github/{workflows => actions}/build.yaml (74%) create mode 100644 .github/actions/deploy_firebase.yaml create mode 100644 .github/workflows/deploy-frontend-preview.yml diff --git a/.github/workflows/build.yaml b/.github/actions/build.yaml similarity index 74% rename from .github/workflows/build.yaml rename to .github/actions/build.yaml index d690c2f8..07803277 100644 --- a/.github/workflows/build.yaml +++ b/.github/actions/build.yaml @@ -2,44 +2,24 @@ name: 'Build' on: workflow_call: inputs: - service: - required: true - type: string - file_path: - required: true - type: string timeout: required: false type: number default: 5 - gcp_oidc_provider_name: - required: false - type: string - default: github-provider - gcp_project_id: - required: false - type: string - default: basemind-ai-development - gcp_project_number: - required: false - type: string - default: 78794879644 - gcp_service_account_name: - required: false + service: + required: true type: string - default: github-actions - gcp_workload_identity_pool: - required: false + file_path: + required: true type: string - default: dev-pool - gcp_region: - required: false + environment: + required: true type: string - default: europe-west3 jobs: build: runs-on: ubuntu-latest timeout-minutes: ${{ inputs.timeout }} + environment: ${{ inputs.environment }} permissions: contents: 'read' id-token: 'write' diff --git a/.github/actions/deploy_firebase.yaml b/.github/actions/deploy_firebase.yaml new file mode 100644 index 00000000..521f6cf3 --- /dev/null +++ b/.github/actions/deploy_firebase.yaml @@ -0,0 +1,79 @@ +name: 'Firebase Deployment' +on: + workflow_call: + inputs: + timeout: + required: false + type: number + default: 5 + environment: + required: true + type: string + is_preview: + required: true + type: boolean +env: + FIREBASE_CLI_EXPERIMENTS: webframeworks +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: ${{ inputs.timeout }} + environment: ${{ inputs.environment }} + permissions: + checks: write + contents: read + pull-requests: write + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Install Firebase CLI + run: npm install -g firebase-tools + - name: Install PNPM + uses: pnpm/action-setup@v2.4.0 + id: pnpm-install + with: + version: 8 + run_install: false + - name: Setup PNPM Cache + id: pnpm-cache + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + - name: Load Cached Dependencies + uses: actions/cache@v3 + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install Node dependencies + run: pnpm install -r + - name: Create .env File + shell: bash + run: | + echo "NEXT_PUBLIC_FIREBASE_API_KEY=${{ secrets.NEXT_PUBLIC_FIREBASE_API_KEY }}" >> frontend/.env + echo "NEXT_PUBLIC_FIREBASE_APP_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_APP_ID }}" >> frontend/.env + echo "NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=${{ secrets.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN }}" >> frontend/.env + echo "NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID }}" >> frontend/.env + echo "NEXT_PUBLIC_FIREBASE_MESSAGE_SENDER_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_MESSAGE_SENDER_ID }}" >> frontend/.env + echo "NEXT_PUBLIC_FIREBASE_PROJECT_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_PROJECT_ID }}" >> frontend/.env + echo "NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=${{ secrets.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET }}" >> frontend/.env + echo "NEXT_PUBLIC_SEGMENT_WRITE_KEY=${{ secrets.NEXT_PUBLIC_SEGMENT_WRITE_KEY }}" >> frontend/.env + echo "NEXT_PUBLIC_BACKEND_BASE_URL=${{ env.DEVELOPMENT_DASHBOARD_BACKEND_URL }}" >> frontend/.env + - uses: FirebaseExtended/action-hosting-deploy@v0 + if: ${{ inputs.is_preview == false }} + with: + repoToken: ${{ secrets.GITHUB_TOKEN }} + firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }} + projectId: ${{ env.GCP_PROJECT_I }} + channelId: live + - uses: FirebaseExtended/action-hosting-deploy@v0 + if: ${{ inputs.is_preview == true }} + with: + repoToken: ${{ secrets.GITHUB_TOKEN }} + firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }} + projectId: ${{ env.GCP_PROJECT_I }} diff --git a/.github/workflows/build-api-gateway.yaml b/.github/workflows/build-api-gateway.yaml index 9baa537e..a043d45b 100644 --- a/.github/workflows/build-api-gateway.yaml +++ b/.github/workflows/build-api-gateway.yaml @@ -2,7 +2,8 @@ name: 'Build (API-Gateway)' on: push: branches: - - main + - development + - production paths: - 'gen/go/ptesting/**' - 'gen/go/gateway/**' @@ -11,7 +12,9 @@ on: - 'shared/go/**' jobs: build: - uses: ./.github/workflows/build.yaml + uses: ./.github/actions/build.yaml + secrets: inherit with: file_path: ./docker/Dockerfile.go-services service: api-gateway + environment: ${{ github.ref_name }} diff --git a/.github/workflows/build-cohere-connector.yaml b/.github/workflows/build-cohere-connector.yaml index f31788d4..8f215f46 100644 --- a/.github/workflows/build-cohere-connector.yaml +++ b/.github/workflows/build-cohere-connector.yaml @@ -7,9 +7,12 @@ on: - 'gen/ts/cohere/**' - 'services/cohere-connector/**' - 'shared/ts/**' + - 'package.json' jobs: build: - uses: ./.github/workflows/build.yaml + uses: ./.github/actions/build.yaml + secrets: inherit with: file_path: ./docker/Dockerfile.ts-services service: cohere-connector + environment: ${{ github.ref_name }} diff --git a/.github/workflows/build-dashboard-backend.yaml b/.github/workflows/build-dashboard-backend.yaml index c86bed3e..7b6069c7 100644 --- a/.github/workflows/build-dashboard-backend.yaml +++ b/.github/workflows/build-dashboard-backend.yaml @@ -10,7 +10,9 @@ on: - 'shared/go/**' jobs: build: - uses: ./.github/workflows/build.yaml + uses: ./.github/actions/build.yaml + secrets: inherit with: file_path: ./docker/Dockerfile.go-services service: dashboard-backend + environment: ${{ github.ref_name }} diff --git a/.github/workflows/build-openai-connector.yaml b/.github/workflows/build-openai-connector.yaml index 57e28c27..317185a8 100644 --- a/.github/workflows/build-openai-connector.yaml +++ b/.github/workflows/build-openai-connector.yaml @@ -2,14 +2,18 @@ name: 'Build (OpenAI-Connector)' on: push: branches: - - main + - development + - production paths: - 'gen/ts/openai/**' - 'services/openai-connector/**' - 'shared/ts/**' + - 'package.json' jobs: build: - uses: ./.github/workflows/build.yaml + uses: ./.github/actions/build.yaml + secrets: inherit with: file_path: ./docker/Dockerfile.ts-services service: openai-connector + environment: ${{ github.ref_name }} diff --git a/.github/workflows/deploy-frontend-preview.yml b/.github/workflows/deploy-frontend-preview.yml new file mode 100644 index 00000000..e2d49096 --- /dev/null +++ b/.github/workflows/deploy-frontend-preview.yml @@ -0,0 +1,16 @@ +name: Frontend Preview +on: + pull_request: + branches: + - main + paths: + - 'frontend/src/**' + - 'shared/ts/**' + - 'package.json' +jobs: + deploy: + uses: ./.github/actions/deploy_firebase.yaml + secrets: inherit + with: + environment: ${{ github.ref_name }} + is_preview: true diff --git a/.github/workflows/deploy-frontend.yml b/.github/workflows/deploy-frontend.yml index a9b77284..51d332a2 100644 --- a/.github/workflows/deploy-frontend.yml +++ b/.github/workflows/deploy-frontend.yml @@ -1,79 +1,17 @@ name: Deploy (Frontend) on: - pull_request: - branches: - - main - paths: - - 'frontend/src/**' - - 'shared/ts/**' push: branches: - - main + - development + - production paths: - 'frontend/src/**' - 'shared/ts/**' -env: - FIREBASE_CLI_EXPERIMENTS: webframeworks - + - 'package.json' jobs: deploy: - environment: development - runs-on: ubuntu-latest - permissions: - checks: write - contents: read - pull-requests: write - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: 20 - - name: Install Firebase CLI - run: npm install -g firebase-tools - - name: Install PNPM - uses: pnpm/action-setup@v2.4.0 - id: pnpm-install - with: - version: 8 - run_install: false - - name: Setup PNPM Cache - id: pnpm-cache - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - name: Load Cached Dependencies - uses: actions/cache@v3 - with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - name: Install Node dependencies - run: pnpm install -r - - name: Create .env File - shell: bash - run: | - echo "NEXT_PUBLIC_FIREBASE_API_KEY=${{ secrets.NEXT_PUBLIC_FIREBASE_API_KEY }}" >> frontend/.env - echo "NEXT_PUBLIC_FIREBASE_APP_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_APP_ID }}" >> frontend/.env - echo "NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=${{ secrets.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN }}" >> frontend/.env - echo "NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID }}" >> frontend/.env - echo "NEXT_PUBLIC_FIREBASE_MESSAGE_SENDER_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_MESSAGE_SENDER_ID }}" >> frontend/.env - echo "NEXT_PUBLIC_FIREBASE_PROJECT_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_PROJECT_ID }}" >> frontend/.env - echo "NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=${{ secrets.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET }}" >> frontend/.env - echo "NEXT_PUBLIC_SEGMENT_WRITE_KEY=${{ secrets.NEXT_PUBLIC_SEGMENT_WRITE_KEY }}" >> frontend/.env - echo "NEXT_PUBLIC_BACKEND_BASE_URL=${{ env.DEVELOPMENT_DASHBOARD_BACKEND_URL }}" >> frontend/.env - - uses: FirebaseExtended/action-hosting-deploy@v0 - if: github.event_name != 'pull_request' - with: - repoToken: ${{ secrets.GITHUB_TOKEN }} - firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_BASEMIND_AI_DEVELOPMENT }} - channelId: live - projectId: basemind-ai-development - - uses: FirebaseExtended/action-hosting-deploy@v0 - if: github.event_name == 'pull_request' - with: - repoToken: ${{ secrets.GITHUB_TOKEN }} - firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_BASEMIND_AI_DEVELOPMENT }} - projectId: basemind-ai-development + uses: ./.github/actions/deploy_firebase.yaml + secrets: inherit + with: + environment: ${{ github.ref_name }} + is_preview: false diff --git a/.idea/misc.xml b/.idea/misc.xml index 00bafb9f..ec44ff32 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ -