Skip to content

Commit

Permalink
fix: update the deploy.yml and build.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
sshivaditya committed Jan 4, 2025
1 parent bb38ea4 commit f6eb70b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
47 changes: 33 additions & 14 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
}
}
}
}
}'
11 changes: 6 additions & 5 deletions functions/issue-scraper.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { Context } from "./types";
import { Context, Env } from "./types";

export const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type",
};

export async function onRequest(ctx: Context): Promise<Response> {
const { request, env } = ctx;
const url = new URL(request.url);


export async function onRequest(ctx: Context, env: Env): Promise<Response> {
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,
});
Expand Down
3 changes: 3 additions & 0 deletions functions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f6eb70b

Please sign in to comment.