From f6eb70bb7c91aa7a6c383b15e96bb0790c952389 Mon Sep 17 00:00:00 2001 From: Shivaditya Shivganesh Date: Fri, 3 Jan 2025 21:30:33 -0500 Subject: [PATCH] fix: update the deploy.yml and build.yml --- .github/workflows/deploy.yml | 47 +++++++++++++++++++++++++----------- functions/issue-scraper.ts | 11 +++++---- functions/types.ts | 3 +++ 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 387c5657..35865e78 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -8,20 +8,6 @@ on: - completed jobs: - write-secrets-to-wrangler: - name: Write secrets to wrangler.toml - runs-on: ubuntu-22.04 - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Write secrets to wrangler.toml - run: | - sed -i 's/VOYAGE_API_KEY = ""/VOYAGEAI_API_KEY = "TEST"/g' wrangler.toml - env: - VOYAGE_API_KEY: ${{ secrets.VOYAGEAI_API_KEY }} - SUPABASE_URL: ${{ secrets.SUPABASE_URL }} - SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }} - deploy-to-cloudflare: name: Automatic Cloudflare Deploy runs-on: ubuntu-22.04 @@ -39,3 +25,36 @@ jobs: commit_sha: ${{ github.event.workflow_run.head_sha }} workflow_run_id: ${{ github.event.workflow_run.id }} statics_directory: "static" + + update_env_secrets_in_cloudflare: + name: Update environment secrets in Cloudflare + runs-on: ubuntu-22.04 + steps: + - name: Update environment secrets in Cloudflare + run: | + REPO_NAME=$(echo "${{ github.event.repository.name }}" | tr '.' '-') + curl -X PUT \ + "https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/${REPO_NAME}/deployment_configs" \ + -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \ + -H "Content-Type: application/json" \ + --data '{ + "deployment_configs": { + "production": { + "env_vars": { + "VOYAGE_API_KEY": { + "value": "${{ secrets.VOYAGEAI_API_KEY }}", + "type": "secret_text" + }, + "SUPABASE_URL": { + "value": "${{ secrets.SUPABASE_URL }}", + "type": "secret_text" + }, + "SUPABASE_ANON_KEY": { + "value": "${{ secrets.SUPABASE_ANON_KEY }}", + "type": "secret_text" + } + } + } + } + }' + diff --git a/functions/issue-scraper.ts b/functions/issue-scraper.ts index a1a58657..b8d7c26d 100644 --- a/functions/issue-scraper.ts +++ b/functions/issue-scraper.ts @@ -1,4 +1,4 @@ -import { Context } from "./types"; +import { Context, Env } from "./types"; export const corsHeaders = { "Access-Control-Allow-Origin": "*", @@ -6,16 +6,17 @@ export const corsHeaders = { "Access-Control-Allow-Headers": "Content-Type", }; -export async function onRequest(ctx: Context): Promise { - const { request, env } = ctx; - const url = new URL(request.url); + +export async function onRequest(ctx: Context, env: Env): Promise { + const { request } = ctx; + const url = new URL(request.url); try { switch (request.method) { case "GET": if (url.searchParams.has("key")) { const key = url.searchParams.get("key") as string; - return new Response("GET request with key: " + key + JSON.stringify(env), { + return new Response("GET request with key: " + key + JSON.stringify(env.SUPABASE_ANON_KEY), { headers: corsHeaders, status: 200, }); diff --git a/functions/types.ts b/functions/types.ts index acafc2e9..47b54d05 100644 --- a/functions/types.ts +++ b/functions/types.ts @@ -2,6 +2,9 @@ import { EventContext, KVNamespace } from "@cloudflare/workers-types"; export interface Env { KVNamespace: KVNamespace; + SUPABASE_URL: string; + SUPABASE_ANON_KEY: string; + VOYAGEAI_API_KEY: string; } export interface POSTRequestBody {