From 86e6a1afbbc09040a5f372dd3010c638be9bce84 Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 31 Mar 2024 14:08:30 -0700 Subject: [PATCH 01/14] update extension: work on all *.dhr.wtf sites --- apps/extension/src/content.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/extension/src/content.tsx b/apps/extension/src/content.tsx index 4c194c53..0bc71e07 100644 --- a/apps/extension/src/content.tsx +++ b/apps/extension/src/content.tsx @@ -8,7 +8,7 @@ window.addEventListener('message', (event) => { if ( !( window.location.hostname === 'localhost' || - window.location.hostname === 'anycontext.dhr.wtf' + window.location.hostname.endsWith('dhr.wtf') ) ) { console.log( From db669375e037243678cf357a6d4c876ba8dcfced Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 31 Mar 2024 14:46:45 -0700 Subject: [PATCH 02/14] (ci): extension path mismatch fix --- .github/actions/buildextension/action.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/buildextension/action.yml b/.github/actions/buildextension/action.yml index dc1dc80d..b65953d7 100644 --- a/.github/actions/buildextension/action.yml +++ b/.github/actions/buildextension/action.yml @@ -26,4 +26,4 @@ runs: uses: actions/upload-artifact@v3 with: name: extension-${{ github.sha }} - path: apps/extensions/dist/extension-${{ github.sha }}.zip \ No newline at end of file + path: apps/extension/dist/extension-${{ github.sha }}.zip \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 57168bb0..bdc9d474 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,4 +27,4 @@ jobs: clientID: ${{ secrets.GOOGLE_CLIENT_ID }} clientSecret: ${{ secrets.GOOGLE_CLIENT_SECRET }} clientRefreshToken: ${{ secrets.GOOGLE_REFRESH_TOKEN }} - extensionFile: apps/extension/extension-${{ github.sha }}.zip + extensionFile: apps/extension/dist/extension-${{ github.sha }}.zip From faf4f980af32c0b6af73fe0a6591785b2a7c9535 Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 31 Mar 2024 14:50:31 -0700 Subject: [PATCH 03/14] (ci): conditionally build and deploy --- .github/workflows/build.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 056fca08..653bb11e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,18 +1,27 @@ -name: Build +name: Build and deploy changes on: push: branches: [main] + paths: + - 'apps/web/**' + - 'apps/extension/**' pull_request: branches: [main] + paths: + - 'apps/web/**' + - 'apps/extension/**' jobs: build-extension: + if: contains(github.event.head_commit.modified, 'apps/extension/') || contains(github.event.head_commit.added, 'apps/extension/') || contains(github.event.head_commit.removed, 'apps/extension/') runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: ./.github/actions/buildextension + build-app: + if: contains(github.event.head_commit.modified, 'apps/web/') || contains(github.event.head_commit.added, 'apps/web/') || contains(github.event.head_commit.removed, 'apps/web/') runs-on: ubuntu-latest steps: - name: Checkout repo From 4e1cc8a52fc457f05e908eeae30b309461d8072b Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 31 Mar 2024 15:40:49 -0700 Subject: [PATCH 04/14] added workflow to auto deploy workers --- .github/workflows/build.yml | 18 ++++++++++ apps/cf-ai-backend/.gitignore | 1 - apps/cf-ai-backend/wrangler.toml | 59 ++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 apps/cf-ai-backend/wrangler.toml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 653bb11e..ab8ae98f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,9 +50,27 @@ jobs: - name: Publish to Cloudflare Pages uses: cloudflare/pages-action@v1 + if: github.event_name == 'push' && github.ref == 'refs/heads/main' with: apiToken: ${{ secrets.CF_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} projectName: ${{ secrets.CLOUDFLARE_PROJECT_NAME }} directory: apps/web/.vercel/output/static branch: main + + deploy-cf-worker: + if: contains(github.event.head_commit.modified, 'apps/cf-ai-backend/') || contains(github.event.head_commit.added, 'apps/cf-ai-backend/') || contains(github.event.head_commit.removed, 'apps/cf-ai-backend/') + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Deploy to Cloudflare Workers + uses: cloudflare/wrangler-action@1.2.0 + with: + apiToken: ${{ secrets.CF_API_TOKEN }} + script: wrangler publish + working-directory: apps/cf-ai-backend + env: + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + SECURITY_KEY: ${{ secrets.BACKEND_SECURITY_KEY }} \ No newline at end of file diff --git a/apps/cf-ai-backend/.gitignore b/apps/cf-ai-backend/.gitignore index c51412d9..3b0fe33c 100644 --- a/apps/cf-ai-backend/.gitignore +++ b/apps/cf-ai-backend/.gitignore @@ -1,5 +1,4 @@ # Logs -wrangler.toml logs _.log diff --git a/apps/cf-ai-backend/wrangler.toml b/apps/cf-ai-backend/wrangler.toml new file mode 100644 index 00000000..ce7b0222 --- /dev/null +++ b/apps/cf-ai-backend/wrangler.toml @@ -0,0 +1,59 @@ +name = "cf-ai-backend" +main = "src/index.ts" +compatibility_date = "2024-02-23" + +[[vectorize]] +binding = "VECTORIZE_INDEX" +index_name = "any-vector" + +[ai] +binding = "AI" + + +# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables) +# Note: Use secrets to store sensitive data. +# Docs: https://developers.cloudflare.com/workers/platform/environment-variables +# [vars] +# MY_VARIABLE = "production_value" + +# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs. +# Docs: https://developers.cloudflare.com/workers/runtime-apis/kv +# [[kv_namespaces]] +# binding = "MY_KV_NAMESPACE" +# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + +# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files. +# Docs: https://developers.cloudflare.com/r2/api/workers/workers-api-usage/ +# [[r2_buckets]] +# binding = "MY_BUCKET" +# bucket_name = "my-bucket" + +# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer. +# Docs: https://developers.cloudflare.com/queues/get-started +# [[queues.producers]] +# binding = "MY_QUEUE" +# queue = "my-queue" + +# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them. +# Docs: https://developers.cloudflare.com/queues/get-started +# [[queues.consumers]] +# queue = "my-queue" + +# Bind another Worker service. Use this binding to call another Worker without network overhead. +# Docs: https://developers.cloudflare.com/workers/platform/services +# [[services]] +# binding = "MY_SERVICE" +# service = "my-service" + +# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model. +# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps. +# Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects +# [[durable_objects.bindings]] +# name = "MY_DURABLE_OBJECT" +# class_name = "MyDurableObject" + +# Durable Object migrations. +# Docs: https://developers.cloudflare.com/workers/learning/using-durable-objects#configure-durable-object-classes-with-migrations +# [[migrations]] +# tag = "v1" +# new_classes = ["MyDurableObject"] From c2ba71e9a2543a4cf631cee52238708f33b04357 Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 31 Mar 2024 17:09:17 -0700 Subject: [PATCH 05/14] (ci): update github action to an even better script with auto deploy to cloudflare workers for the ai module --- .github/workflows/build.yml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ab8ae98f..afddbd1f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,15 +6,41 @@ on: paths: - 'apps/web/**' - 'apps/extension/**' + - 'apps/cf-ai-backend/**' pull_request: branches: [main] paths: - 'apps/web/**' - 'apps/extension/**' + - 'apps/cf-ai-backend/**' jobs: + check-modified-paths: + runs-on: ubuntu-latest + outputs: + web_changed: ${{ steps.set-outputs.outputs.web_changed }} + extension_changed: ${{ steps.set-outputs.outputs.extension_changed }} + cf_ai_backend_changed: ${{ steps.set-outputs.outputs.cf_ai_backend_changed }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Check modified paths + id: set-outputs + run: | + echo "Checking modified paths..." + # Custom script to check if specific paths were modified + # You might need to adjust the script based on your requirements + WEB_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep 'apps/web/' && echo 'true' || echo 'false') + EXTENSION_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep 'apps/extension/' && echo 'true' || echo 'false') + CF_AI_BACKEND_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep 'apps/cf-ai-backend/' && echo 'true' || echo 'false') + echo "::set-output name=web_changed::$WEB_CHANGED" + echo "::set-output name=extension_changed::$EXTENSION_CHANGED" + echo "::set-output name=cf_ai_backend_changed::$CF_AI_BACKEND_CHANGED" + build-extension: - if: contains(github.event.head_commit.modified, 'apps/extension/') || contains(github.event.head_commit.added, 'apps/extension/') || contains(github.event.head_commit.removed, 'apps/extension/') + needs: check-modified-paths + if: needs.check-modified-paths.outputs.extension_changed == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 From 27944d3bbb8b0f06a5a11632602eabeff9f45c2b Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 31 Mar 2024 17:10:02 -0700 Subject: [PATCH 06/14] (ci): test changes in ci --- apps/cf-ai-backend/wrangler.toml | 1 - apps/web/README.md | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/cf-ai-backend/wrangler.toml b/apps/cf-ai-backend/wrangler.toml index ce7b0222..9e3ee21b 100644 --- a/apps/cf-ai-backend/wrangler.toml +++ b/apps/cf-ai-backend/wrangler.toml @@ -9,7 +9,6 @@ index_name = "any-vector" [ai] binding = "AI" - # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables) # Note: Use secrets to store sensitive data. # Docs: https://developers.cloudflare.com/workers/platform/environment-variables diff --git a/apps/web/README.md b/apps/web/README.md index 42da305a..c81448e4 100644 --- a/apps/web/README.md +++ b/apps/web/README.md @@ -65,4 +65,4 @@ In order to enable the example: After doing this you can run the `dev` or `preview` script and visit the `/api/hello` route to see the example in action. -Finally, if you also want to see the example work in the deployed application make sure to add a `MY_KV_NAMESPACE` binding to your Pages application in its [dashboard kv bindings settings section](https://dash.cloudflare.com/?to=/:account/pages/view/:pages-project/settings/functions#kv_namespace_bindings_section). After having configured it make sure to re-deploy your application. +Finally, if you also want to see the example work in the deployed application make sure to add a `MY_KV_NAMESPACE` binding to your Pages application in its [dashboard kv bindings settings section](https://dash.cloudflare.com/?to=/:account/pages/view/:pages-project/settings/functions#kv_namespace_bindings_section). After having configured it make sure to re-deploy your application. \ No newline at end of file From 571a6c6e8ac9f4251b0c9e2f073a5e8a1a4ca159 Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 31 Mar 2024 17:17:40 -0700 Subject: [PATCH 07/14] (ci): update ci --- .github/workflows/build.yml | 38 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index afddbd1f..8f492b53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build and deploy changes +name: Build and Deploy Changes on: push: @@ -15,39 +15,31 @@ on: - 'apps/cf-ai-backend/**' jobs: - check-modified-paths: + prepare: runs-on: ubuntu-latest outputs: - web_changed: ${{ steps.set-outputs.outputs.web_changed }} - extension_changed: ${{ steps.set-outputs.outputs.extension_changed }} - cf_ai_backend_changed: ${{ steps.set-outputs.outputs.cf_ai_backend_changed }} + web_changed: ${{ steps.set_outputs.outputs.web_changed }} + extension_changed: ${{ steps.set_outputs.outputs.extension_changed }} + cf_ai_backend_changed: ${{ steps.set_outputs.outputs.cf_ai_backend_changed }} steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Check modified paths - id: set-outputs + - uses: actions/checkout@v3 + - name: Set Outputs + id: set_outputs run: | - echo "Checking modified paths..." - # Custom script to check if specific paths were modified - # You might need to adjust the script based on your requirements - WEB_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep 'apps/web/' && echo 'true' || echo 'false') - EXTENSION_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep 'apps/extension/' && echo 'true' || echo 'false') - CF_AI_BACKEND_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep 'apps/cf-ai-backend/' && echo 'true' || echo 'false') - echo "::set-output name=web_changed::$WEB_CHANGED" - echo "::set-output name=extension_changed::$EXTENSION_CHANGED" - echo "::set-output name=cf_ai_backend_changed::$CF_AI_BACKEND_CHANGED" + echo "web_changed=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -q 'apps/web/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT + echo "extension_changed=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -q 'apps/extension/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT + echo "cf_ai_backend_changed=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -q 'apps/cf-ai-backend/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT build-extension: needs: check-modified-paths - if: needs.check-modified-paths.outputs.extension_changed == 'true' + if: needs.prepare.outputs.extension_changed == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: ./.github/actions/buildextension build-app: - if: contains(github.event.head_commit.modified, 'apps/web/') || contains(github.event.head_commit.added, 'apps/web/') || contains(github.event.head_commit.removed, 'apps/web/') + if: needs.prepare.outputs.web_changed == 'true' runs-on: ubuntu-latest steps: - name: Checkout repo @@ -85,7 +77,7 @@ jobs: branch: main deploy-cf-worker: - if: contains(github.event.head_commit.modified, 'apps/cf-ai-backend/') || contains(github.event.head_commit.added, 'apps/cf-ai-backend/') || contains(github.event.head_commit.removed, 'apps/cf-ai-backend/') + if: needs.prepare.outputs.cf_ai_backend_changed == 'true' runs-on: ubuntu-latest steps: - name: Checkout repo @@ -99,4 +91,4 @@ jobs: working-directory: apps/cf-ai-backend env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - SECURITY_KEY: ${{ secrets.BACKEND_SECURITY_KEY }} \ No newline at end of file + SECURITY_KEY: ${{ secrets.BACKEND_SECURITY_KEY }} From 3ccbd7c33b705cfa58ecd7873b8214ed9e0c8a3f Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 31 Mar 2024 17:18:15 -0700 Subject: [PATCH 08/14] (ci): testing CI changes again --- apps/cf-ai-backend/wrangler.toml | 1 + apps/extension/README.md | 2 +- apps/web/README.md | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/cf-ai-backend/wrangler.toml b/apps/cf-ai-backend/wrangler.toml index 9e3ee21b..ce7b0222 100644 --- a/apps/cf-ai-backend/wrangler.toml +++ b/apps/cf-ai-backend/wrangler.toml @@ -9,6 +9,7 @@ index_name = "any-vector" [ai] binding = "AI" + # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables) # Note: Use secrets to store sensitive data. # Docs: https://developers.cloudflare.com/workers/platform/environment-variables diff --git a/apps/extension/README.md b/apps/extension/README.md index 0d6babed..ec38fd32 100644 --- a/apps/extension/README.md +++ b/apps/extension/README.md @@ -27,4 +27,4 @@ export default { - Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` - Optionally add `plugin:@typescript-eslint/stylistic-type-checked` -- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list +- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list \ No newline at end of file diff --git a/apps/web/README.md b/apps/web/README.md index c81448e4..42da305a 100644 --- a/apps/web/README.md +++ b/apps/web/README.md @@ -65,4 +65,4 @@ In order to enable the example: After doing this you can run the `dev` or `preview` script and visit the `/api/hello` route to see the example in action. -Finally, if you also want to see the example work in the deployed application make sure to add a `MY_KV_NAMESPACE` binding to your Pages application in its [dashboard kv bindings settings section](https://dash.cloudflare.com/?to=/:account/pages/view/:pages-project/settings/functions#kv_namespace_bindings_section). After having configured it make sure to re-deploy your application. \ No newline at end of file +Finally, if you also want to see the example work in the deployed application make sure to add a `MY_KV_NAMESPACE` binding to your Pages application in its [dashboard kv bindings settings section](https://dash.cloudflare.com/?to=/:account/pages/view/:pages-project/settings/functions#kv_namespace_bindings_section). After having configured it make sure to re-deploy your application. From 0c8fd4000a69bdb6e9a2834e31c4134ccf05e3f0 Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 31 Mar 2024 17:19:38 -0700 Subject: [PATCH 09/14] (ci): update CI again --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8f492b53..b2bb67a9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,7 +31,7 @@ jobs: echo "cf_ai_backend_changed=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -q 'apps/cf-ai-backend/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT build-extension: - needs: check-modified-paths + needs: prepare if: needs.prepare.outputs.extension_changed == 'true' runs-on: ubuntu-latest steps: @@ -39,6 +39,7 @@ jobs: - uses: ./.github/actions/buildextension build-app: + needs: prepare if: needs.prepare.outputs.web_changed == 'true' runs-on: ubuntu-latest steps: @@ -77,6 +78,7 @@ jobs: branch: main deploy-cf-worker: + needs: prepare if: needs.prepare.outputs.cf_ai_backend_changed == 'true' runs-on: ubuntu-latest steps: From 561c0b01d21b8556cd200ab211ecd49e9d86c427 Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 31 Mar 2024 17:21:36 -0700 Subject: [PATCH 10/14] (ci): update CI again --- apps/cf-ai-backend/wrangler.toml | 1 - apps/extension/README.md | 3 ++- apps/web/wrangler.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/cf-ai-backend/wrangler.toml b/apps/cf-ai-backend/wrangler.toml index ce7b0222..9e3ee21b 100644 --- a/apps/cf-ai-backend/wrangler.toml +++ b/apps/cf-ai-backend/wrangler.toml @@ -9,7 +9,6 @@ index_name = "any-vector" [ai] binding = "AI" - # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables) # Note: Use secrets to store sensitive data. # Docs: https://developers.cloudflare.com/workers/platform/environment-variables diff --git a/apps/extension/README.md b/apps/extension/README.md index ec38fd32..7619225f 100644 --- a/apps/extension/README.md +++ b/apps/extension/README.md @@ -27,4 +27,5 @@ export default { - Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` - Optionally add `plugin:@typescript-eslint/stylistic-type-checked` -- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list \ No newline at end of file +- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list + \ No newline at end of file diff --git a/apps/web/wrangler.toml b/apps/web/wrangler.toml index 6630b0d0..12619fdb 100644 --- a/apps/web/wrangler.toml +++ b/apps/web/wrangler.toml @@ -9,4 +9,4 @@ index_name = "anycontext-idx" [[d1_databases]] binding = "DATABASE" database_name = "dev-d1-anycontext" -database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" \ No newline at end of file +database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" From dbba7c31ac354146ddfa5dc901e1e5586b542fc5 Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 31 Mar 2024 17:24:18 -0700 Subject: [PATCH 11/14] update CI and test --- .github/workflows/build.yml | 38 ++++++++++++++++++++++++++++--------- apps/web/wrangler.toml | 2 +- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b2bb67a9..26989559 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,18 +18,38 @@ jobs: prepare: runs-on: ubuntu-latest outputs: - web_changed: ${{ steps.set_outputs.outputs.web_changed }} - extension_changed: ${{ steps.set_outputs.outputs.extension_changed }} - cf_ai_backend_changed: ${{ steps.set_outputs.outputs.cf_ai_backend_changed }} + web_changed: ${{ steps.detect_changes.outputs.web_changed }} + extension_changed: ${{ steps.detect_changes.outputs.extension_changed }} + cf_ai_backend_changed: ${{ steps.detect_changes.outputs.cf_ai_backend_changed }} steps: - uses: actions/checkout@v3 - - name: Set Outputs - id: set_outputs + - name: Fetching all history for all tags and branches + run: git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* + - name: Detect Changes + id: detect_changes run: | - echo "web_changed=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -q 'apps/web/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT - echo "extension_changed=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -q 'apps/extension/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT - echo "cf_ai_backend_changed=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -q 'apps/cf-ai-backend/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT - + WEB_CHANGED="false" + EXTENSION_CHANGED="false" + CF_AI_BACKEND_CHANGED="false" + if [ "${{ github.event_name }}" = "push" ]; then + DIFF_REF="${{ github.event.before }} ${{ github.sha }}" + else + DIFF_REF="${{ github.base_ref }}...${{ github.head_ref }}" + fi + if git diff --name-only $DIFF_REF | grep -q 'apps/web/'; then + WEB_CHANGED="true" + fi + if git diff --name-only $DIFF_REF | grep -q 'apps/extension/'; then + EXTENSION_CHANGED="true" + fi + if git diff --name-only $DIFF_REF | grep -q 'apps/cf-ai-backend/'; then + CF_AI_BACKEND_CHANGED="true" + fi + echo "web_changed=$WEB_CHANGED" >> $GITHUB_OUTPUT + echo "extension_changed=$EXTENSION_CHANGED" >> $GITHUB_OUTPUT + echo "cf_ai_backend_changed=$CF_AI_BACKEND_CHANGED" >> $GITHUB_OUTPUT + echo "Differences detected: WEB=$WEB_CHANGED, EXTENSION=$EXTENSION_CHANGED, CF_AI_BACKEND=$CF_AI_BACKEND_CHANGED" + build-extension: needs: prepare if: needs.prepare.outputs.extension_changed == 'true' diff --git a/apps/web/wrangler.toml b/apps/web/wrangler.toml index 12619fdb..6630b0d0 100644 --- a/apps/web/wrangler.toml +++ b/apps/web/wrangler.toml @@ -9,4 +9,4 @@ index_name = "anycontext-idx" [[d1_databases]] binding = "DATABASE" database_name = "dev-d1-anycontext" -database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" +database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" \ No newline at end of file From 24a5bed1b4864d28a0062ad5fd43c41f0e380bdc Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 31 Mar 2024 17:26:47 -0700 Subject: [PATCH 12/14] build checks --- .github/workflows/build.yml | 41 ------------------------------------- apps/web/README.md | 2 +- apps/web/wrangler.toml | 2 +- 3 files changed, 2 insertions(+), 43 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 26989559..1e1ca656 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,52 +15,13 @@ on: - 'apps/cf-ai-backend/**' jobs: - prepare: - runs-on: ubuntu-latest - outputs: - web_changed: ${{ steps.detect_changes.outputs.web_changed }} - extension_changed: ${{ steps.detect_changes.outputs.extension_changed }} - cf_ai_backend_changed: ${{ steps.detect_changes.outputs.cf_ai_backend_changed }} - steps: - - uses: actions/checkout@v3 - - name: Fetching all history for all tags and branches - run: git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* - - name: Detect Changes - id: detect_changes - run: | - WEB_CHANGED="false" - EXTENSION_CHANGED="false" - CF_AI_BACKEND_CHANGED="false" - if [ "${{ github.event_name }}" = "push" ]; then - DIFF_REF="${{ github.event.before }} ${{ github.sha }}" - else - DIFF_REF="${{ github.base_ref }}...${{ github.head_ref }}" - fi - if git diff --name-only $DIFF_REF | grep -q 'apps/web/'; then - WEB_CHANGED="true" - fi - if git diff --name-only $DIFF_REF | grep -q 'apps/extension/'; then - EXTENSION_CHANGED="true" - fi - if git diff --name-only $DIFF_REF | grep -q 'apps/cf-ai-backend/'; then - CF_AI_BACKEND_CHANGED="true" - fi - echo "web_changed=$WEB_CHANGED" >> $GITHUB_OUTPUT - echo "extension_changed=$EXTENSION_CHANGED" >> $GITHUB_OUTPUT - echo "cf_ai_backend_changed=$CF_AI_BACKEND_CHANGED" >> $GITHUB_OUTPUT - echo "Differences detected: WEB=$WEB_CHANGED, EXTENSION=$EXTENSION_CHANGED, CF_AI_BACKEND=$CF_AI_BACKEND_CHANGED" - build-extension: - needs: prepare - if: needs.prepare.outputs.extension_changed == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: ./.github/actions/buildextension build-app: - needs: prepare - if: needs.prepare.outputs.web_changed == 'true' runs-on: ubuntu-latest steps: - name: Checkout repo @@ -98,8 +59,6 @@ jobs: branch: main deploy-cf-worker: - needs: prepare - if: needs.prepare.outputs.cf_ai_backend_changed == 'true' runs-on: ubuntu-latest steps: - name: Checkout repo diff --git a/apps/web/README.md b/apps/web/README.md index 42da305a..c81448e4 100644 --- a/apps/web/README.md +++ b/apps/web/README.md @@ -65,4 +65,4 @@ In order to enable the example: After doing this you can run the `dev` or `preview` script and visit the `/api/hello` route to see the example in action. -Finally, if you also want to see the example work in the deployed application make sure to add a `MY_KV_NAMESPACE` binding to your Pages application in its [dashboard kv bindings settings section](https://dash.cloudflare.com/?to=/:account/pages/view/:pages-project/settings/functions#kv_namespace_bindings_section). After having configured it make sure to re-deploy your application. +Finally, if you also want to see the example work in the deployed application make sure to add a `MY_KV_NAMESPACE` binding to your Pages application in its [dashboard kv bindings settings section](https://dash.cloudflare.com/?to=/:account/pages/view/:pages-project/settings/functions#kv_namespace_bindings_section). After having configured it make sure to re-deploy your application. \ No newline at end of file diff --git a/apps/web/wrangler.toml b/apps/web/wrangler.toml index 6630b0d0..12619fdb 100644 --- a/apps/web/wrangler.toml +++ b/apps/web/wrangler.toml @@ -9,4 +9,4 @@ index_name = "anycontext-idx" [[d1_databases]] binding = "DATABASE" database_name = "dev-d1-anycontext" -database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" \ No newline at end of file +database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" From 5409435eeb74d3b8fcb35baa9153c6d1ca93b996 Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 31 Mar 2024 17:28:52 -0700 Subject: [PATCH 13/14] final - fix deploy-cf-worker --- .github/workflows/build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1e1ca656..7bb76c17 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -68,8 +68,7 @@ jobs: uses: cloudflare/wrangler-action@1.2.0 with: apiToken: ${{ secrets.CF_API_TOKEN }} - script: wrangler publish - working-directory: apps/cf-ai-backend + workingDirectory: apps/cf-ai-backend env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} SECURITY_KEY: ${{ secrets.BACKEND_SECURITY_KEY }} From 136925b2baa898394b5b9fda446a661c40d8c5b1 Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 31 Mar 2024 17:47:57 -0700 Subject: [PATCH 14/14] update .github --- .github/workflows/build.yml | 26 +++++++++++++------------- apps/web/example.wrangler.toml | 18 ------------------ 2 files changed, 13 insertions(+), 31 deletions(-) delete mode 100644 apps/web/example.wrangler.toml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7bb76c17..c99080ec 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -58,17 +58,17 @@ jobs: directory: apps/web/.vercel/output/static branch: main - deploy-cf-worker: - runs-on: ubuntu-latest - steps: - - name: Checkout repo - uses: actions/checkout@v3 + # deploy-cf-worker: + # runs-on: ubuntu-latest + # steps: + # - name: Checkout repo + # uses: actions/checkout@v3 - - name: Deploy to Cloudflare Workers - uses: cloudflare/wrangler-action@1.2.0 - with: - apiToken: ${{ secrets.CF_API_TOKEN }} - workingDirectory: apps/cf-ai-backend - env: - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - SECURITY_KEY: ${{ secrets.BACKEND_SECURITY_KEY }} + # - name: Deploy to Cloudflare Workers + # uses: cloudflare/wrangler-action@1.2.0 + # with: + # apiToken: ${{ secrets.CF_API_TOKEN }} + # workingDirectory: apps/cf-ai-backend + # env: + # OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + # SECURITY_KEY: ${{ secrets.BACKEND_SECURITY_KEY }} diff --git a/apps/web/example.wrangler.toml b/apps/web/example.wrangler.toml deleted file mode 100644 index 688d8137..00000000 --- a/apps/web/example.wrangler.toml +++ /dev/null @@ -1,18 +0,0 @@ -name = "web" -compatibility_date = "2024-03-29" -compatibility_flags = ["nodejs_compat"] - -[[vectorize]] -binding = "VECTORIZE_INDEX" -index_name = "anycontext-idx" - -[[d1_databases]] -binding = "DATABASE" -database_name = "dev-d1-anycontext" - -[vars] -GOOGLE_CLIENT_ID="-" -GOOGLE_CLIENT_SECRET="-" -NEXTAUTH_SECRET="sec" -NEXTAUTH_URL="http://localhost:3000" -BACKEND_SECURITY_KEY="XP1FNh+rTYghq2TmrFbMLCCBy+eBAvi8iuoMuV9zDUc="