Skip to content

Commit

Permalink
chore: env production
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed May 28, 2024
1 parent f4c4851 commit 8b55b75
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

- uses: cloudflare/wrangler-action@v3
with:
command: deploy --env production
# command: deploy --env production
wranglerVersion: '3.57.0'
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
secrets: |
Expand Down
27 changes: 22 additions & 5 deletions deploy/setup_kv_namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,43 @@ interface WranglerConfiguration {
name: string;
env: {
production: {
kv_namespaces: {
kv_namespaces?: {
id: string;
binding: string;
}[];
};
dev: {
kv_namespaces?: {
id: string;
binding: string;
}[];
};
};
kv_namespaces: {
id: string;
binding: string;
}[];
}

function updateWranglerToml(namespaceId: string) {
// Ensure kv_namespaces array exists
if (!wranglerToml.env.production.kv_namespaces) {
wranglerToml.env.production.kv_namespaces = [];
if (!wranglerToml.kv_namespaces) {
wranglerToml.kv_namespaces = [];
}
if (wranglerToml.env.production.kv_namespaces) {
wranglerToml.kv_namespaces = wranglerToml.env.production.kv_namespaces;
delete wranglerToml.env.production.kv_namespaces;
}
if (wranglerToml.env.dev.kv_namespaces) {
delete wranglerToml.env.dev.kv_namespaces;
}

const existingNamespace = wranglerToml.env.production.kv_namespaces.find((o) => o.binding === BINDING_NAME);
const existingNamespace = wranglerToml.kv_namespaces.find((o) => o.binding === BINDING_NAME);
if (existingNamespace) {
existingNamespace.id = namespaceId;
} else {
// Add the new binding
wranglerToml.env.production.kv_namespaces.push({
wranglerToml.kv_namespaces.push({
binding: BINDING_NAME,
id: namespaceId,
});
Expand Down
16 changes: 5 additions & 11 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@ name = "ubiquibot-worker"
main = "src/worker.ts"
compatibility_date = "2023-12-06"

# Prefer this syntax due to a bug in Wrangler: https://github.com/cloudflare/workers-sdk/issues/5634
[env]

[env.dev]

[[env.dev.kv_namespaces]]
binding = "PLUGIN_CHAIN_STATE"
id = "4f7aadc56bef41a7ae2cc8c0582320b3"
binding = "PLUGIN_CHAIN_STATE"
id = "4f7aadc56bef41a7ae2cc8c0582320b3"

[env.production]

[[env.production.kv_namespaces]]
binding = "PLUGIN_CHAIN_STATE"
id = "af612cce0703489d87345e6578496336"

#[[kv_namespaces]]
#binding = "PLUGIN_CHAIN_STATE"
#id = "TO_BE_DEFINED"
binding = "PLUGIN_CHAIN_STATE"
id = "TO_BE_DEFINED"

0 comments on commit 8b55b75

Please sign in to comment.