The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix: Make CI .env manipulation robust against missing trailing newlines (#15189)
Félix Malfait5375a478db1a
diff --git a/.github/workflows/ci-breaking-changes.yaml b/.github/workflows/ci-breaking-changes.yamlindex 471fd465a96..fc86c7782b7 100644--- a/.github/workflows/ci-breaking-changes.yaml+++ b/.github/workflows/ci-breaking-changes.yaml@@ -124,13 +124,14 @@ jobs:- name: Setup current branch databaserun: |npx nx reset:env twenty-server- # Function to set or update environment variableset_env_var() {local var_name="$1"local var_value="$2"local env_file="packages/twenty-server/.env"- if grep -q "^${var_name}=" "$env_file"; then+ echo "" >> "$env_file"++ if grep -q "^${var_name}=" "$env_file" 2>/dev/null; thensed -i "s|^${var_name}=.*|${var_name}=${var_value}|" "$env_file"elseecho "${var_name}=${var_value}" >> "$env_file"@@ -276,13 +277,14 @@ jobs:- name: Setup main branch databaserun: |npx nx reset:env twenty-server- # Function to set or update environment variableset_env_var() {local var_name="$1"local var_value="$2"local env_file="packages/twenty-server/.env"- if grep -q "^${var_name}=" "$env_file"; then+ echo "" >> "$env_file"++ if grep -q "^${var_name}=" "$env_file" 2>/dev/null; thensed -i "s|^${var_name}=.*|${var_name}=${var_value}|" "$env_file"elseecho "${var_name}=${var_value}" >> "$env_file"diff --git a/.github/workflows/ci-cli.yaml b/.github/workflows/ci-cli.yamlindex 021dfef2ab4..78af7591978 100644--- a/.github/workflows/ci-cli.yaml+++ b/.github/workflows/ci-cli.yaml@@ -81,6 +81,7 @@ jobs:- name: Server / Append billing config to .env.testworking-directory: packages/twenty-serverrun: |+ echo "" >> .env.testecho "IS_BILLING_ENABLED=true" >> .env.testecho "BILLING_STRIPE_API_KEY=test-api-key" >> .env.testecho "BILLING_STRIPE_BASE_PLAN_PRODUCT_ID=test-base-plan-product-id" >> .env.testdiff --git a/.github/workflows/ci-front.yaml b/.github/workflows/ci-front.yamlindex 7dd3446ba74..fa0e2562d5c 100644--- a/.github/workflows/ci-front.yaml+++ b/.github/workflows/ci-front.yaml@@ -140,6 +140,7 @@ jobs:run: |cd packages/twenty-fronttouch .env+ echo "" >> .envecho "REACT_APP_SERVER_BASE_URL: $REACT_APP_SERVER_BASE_URL" >> .env- name: Publish to Chromaticrun: npx nx run twenty-front:chromatic:cidiff --git a/.github/workflows/ci-server.yaml b/.github/workflows/ci-server.yamlindex 9a23426e39d..ae8354ed0c0 100644--- a/.github/workflows/ci-server.yaml+++ b/.github/workflows/ci-server.yaml@@ -218,6 +218,7 @@ jobs:uses: ./.github/workflows/actions/yarn-install- name: Update .env.test for integrations testsrun: |+ echo "" >> .env.testecho "IS_BILLING_ENABLED=true" >> .env.testecho "BILLING_STRIPE_API_KEY=test-api-key" >> .env.testecho "BILLING_STRIPE_BASE_PLAN_PRODUCT_ID=test-base-plan-product-id" >> .env.testdiff --git a/.github/workflows/ci-test-docker-compose.yaml b/.github/workflows/ci-test-docker-compose.yamlindex 1c7683fd345..b56f7c0d7eb 100644--- a/.github/workflows/ci-test-docker-compose.yaml+++ b/.github/workflows/ci-test-docker-compose.yaml@@ -33,6 +33,7 @@ jobs:echo "Setting up .env file..."cp .env.example .envecho "Generating secrets..."+ echo "" >> .envecho "# === Randomly generated secrets ===" >>.envecho "APP_SECRET=$(openssl rand -base64 32)" >>.envecho "PGPASSWORD_SUPERUSER=$(openssl rand -hex 16)" >>.envdiff --git a/.github/workflows/preview-env-keepalive.yaml b/.github/workflows/preview-env-keepalive.yamlindex be3bd88eb0d..fbe2d507e84 100644--- a/.github/workflows/preview-env-keepalive.yaml+++ b/.github/workflows/preview-env-keepalive.yaml@@ -37,6 +37,7 @@ jobs:cp packages/twenty-docker/.env.example packages/twenty-docker/.envecho "Generating secrets..."+ echo "" >> packages/twenty-docker/.envecho "# === Randomly generated secrets ===" >> packages/twenty-docker/.envecho "APP_SECRET=$(openssl rand -base64 32)" >> packages/twenty-docker/.envecho "PG_DATABASE_PASSWORD=$(openssl rand -hex 16)" >> packages/twenty-docker/.env@@ -60,6 +61,7 @@ jobs:# Update the SERVER_URL with the tunnel URLecho "Setting SERVER_URL to ${{ steps.expose-tunnel.outputs.tunnel-url }}"sed -i '/SERVER_URL=/d' .env+ echo "" >> .envecho "SERVER_URL=${{ steps.expose-tunnel.outputs.tunnel-url }}" >> .env# Start the servicesdiff --git a/packages/twenty-server/.env.example b/packages/twenty-server/.env.exampleindex 59f019fdf38..b1d077d2079 100644--- a/packages/twenty-server/.env.example+++ b/packages/twenty-server/.env.example@@ -78,4 +78,5 @@ FRONTEND_URL=http://localhost:3001# CLOUDFLARE_WEBHOOK_SECRET=# IS_CONFIG_VARIABLES_IN_DB_ENABLED=false# ANALYTICS_ENABLED=-# CLICKHOUSE_URL=http://default:clickhousePassword@localhost:8123/twenty\ No newline at end of file+# CLICKHOUSE_URL=http://default:clickhousePassword@localhost:8123/twenty+diff --git a/packages/twenty-server/.env.test b/packages/twenty-server/.env.testindex a672bd9dc3f..00e72259f0a 100644--- a/packages/twenty-server/.env.test+++ b/packages/twenty-server/.env.test@@ -23,4 +23,4 @@ MESSAGING_PROVIDER_GMAIL_CALLBACK_URL=http://localhost:3000/auth/google-gmail/geAUTH_MICROSOFT_CALLBACK_URL=http://localhost:3000/auth/microsoft/redirectAUTH_MICROSOFT_APIS_CALLBACK_URL=http://localhost:3000/auth/microsoft-apis/get-access-token-CLICKHOUSE_URL=http://default:clickhousePassword@localhost:8123/twenty\ No newline at end of file+CLICKHOUSE_URL=http://default:clickhousePassword@localhost:8123/twentydiff --git a/packages/twenty-server/src/engine/workspace-manager/dev-seeder/core/billing/utils/seed-billing-customers.util.ts b/packages/twenty-server/src/engine/workspace-manager/dev-seeder/core/billing/utils/seed-billing-customers.util.tsnew file mode 100644index 00000000000..426fe8017c4--- /dev/null+++ b/packages/twenty-server/src/engine/workspace-manager/dev-seeder/core/billing/utils/seed-billing-customers.util.ts@@ -0,0 +1,22 @@+import { type DataSource } from 'typeorm';++const tableName = 'billingCustomer';++export const seedBillingCustomers = async (+ dataSource: DataSource,+ schemaName: string,+ workspaceId: string,+) => {+ await dataSource+ .createQueryBuilder()+ .insert()+ .into(`${schemaName}.${tableName}`, ['workspaceId', 'stripeCustomerId'])+ .orIgnore()+ .values([+ {+ workspaceId,+ stripeCustomerId: 'cus_default0',+ },+ ])+ .execute();+};diff --git a/packages/twenty-server/src/engine/workspace-manager/dev-seeder/core/utils/seed-core-schema.util.ts b/packages/twenty-server/src/engine/workspace-manager/dev-seeder/core/utils/seed-core-schema.util.tsindex 11327b97db1..2fac8d7d170 100644--- a/packages/twenty-server/src/engine/workspace-manager/dev-seeder/core/utils/seed-core-schema.util.ts+++ b/packages/twenty-server/src/engine/workspace-manager/dev-seeder/core/utils/seed-core-schema.util.ts@@ -1,5 +1,6 @@import { type DataSource } from 'typeorm';+import { seedBillingCustomers } from 'src/engine/workspace-manager/dev-seeder/core/billing/utils/seed-billing-customers.util';import { seedBillingSubscriptions } from 'src/engine/workspace-manager/dev-seeder/core/billing/utils/seed-billing-subscriptions.util';import { seedAgents } from 'src/engine/workspace-manager/dev-seeder/core/utils/seed-agents.util';import { seedApiKeys } from 'src/engine/workspace-manager/dev-seeder/core/utils/seed-api-keys.util';@@ -43,6 +44,7 @@ export const seedCoreSchema = async ({}if (seedBilling) {+ await seedBillingCustomers(dataSource, schemaName, workspaceId);await seedBillingSubscriptions(dataSource, schemaName, workspaceId);}};