Skip to content

The open alternative to Salesforce, designed for AI.

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.yaml
index 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 database
run: |
npx nx reset:env twenty-server
- # Function to set or update environment variable
set_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; then
sed -i "s|^${var_name}=.*|${var_name}=${var_value}|" "$env_file"
else
echo "${var_name}=${var_value}" >> "$env_file"
@@ -276,13 +277,14 @@ jobs:
- name: Setup main branch database
run: |
npx nx reset:env twenty-server
- # Function to set or update environment variable
set_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; then
sed -i "s|^${var_name}=.*|${var_name}=${var_value}|" "$env_file"
else
echo "${var_name}=${var_value}" >> "$env_file"
diff --git a/.github/workflows/ci-cli.yaml b/.github/workflows/ci-cli.yaml
index 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.test
working-directory: packages/twenty-server
run: |
+ echo "" >> .env.test
echo "IS_BILLING_ENABLED=true" >> .env.test
echo "BILLING_STRIPE_API_KEY=test-api-key" >> .env.test
echo "BILLING_STRIPE_BASE_PLAN_PRODUCT_ID=test-base-plan-product-id" >> .env.test
diff --git a/.github/workflows/ci-front.yaml b/.github/workflows/ci-front.yaml
index 7dd3446ba74..fa0e2562d5c 100644
--- a/.github/workflows/ci-front.yaml
+++ b/.github/workflows/ci-front.yaml
@@ -140,6 +140,7 @@ jobs:
run: |
cd packages/twenty-front
touch .env
+ echo "" >> .env
echo "REACT_APP_SERVER_BASE_URL: $REACT_APP_SERVER_BASE_URL" >> .env
- name: Publish to Chromatic
run: npx nx run twenty-front:chromatic:ci
diff --git a/.github/workflows/ci-server.yaml b/.github/workflows/ci-server.yaml
index 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 tests
run: |
+ echo "" >> .env.test
echo "IS_BILLING_ENABLED=true" >> .env.test
echo "BILLING_STRIPE_API_KEY=test-api-key" >> .env.test
echo "BILLING_STRIPE_BASE_PLAN_PRODUCT_ID=test-base-plan-product-id" >> .env.test
diff --git a/.github/workflows/ci-test-docker-compose.yaml b/.github/workflows/ci-test-docker-compose.yaml
index 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 .env
echo "Generating secrets..."
+ echo "" >> .env
echo "# === Randomly generated secrets ===" >>.env
echo "APP_SECRET=$(openssl rand -base64 32)" >>.env
echo "PGPASSWORD_SUPERUSER=$(openssl rand -hex 16)" >>.env
diff --git a/.github/workflows/preview-env-keepalive.yaml b/.github/workflows/preview-env-keepalive.yaml
index 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/.env
echo "Generating secrets..."
+ echo "" >> packages/twenty-docker/.env
echo "# === Randomly generated secrets ===" >> packages/twenty-docker/.env
echo "APP_SECRET=$(openssl rand -base64 32)" >> packages/twenty-docker/.env
echo "PG_DATABASE_PASSWORD=$(openssl rand -hex 16)" >> packages/twenty-docker/.env
@@ -60,6 +61,7 @@ jobs:
# Update the SERVER_URL with the tunnel URL
echo "Setting SERVER_URL to ${{ steps.expose-tunnel.outputs.tunnel-url }}"
sed -i '/SERVER_URL=/d' .env
+ echo "" >> .env
echo "SERVER_URL=${{ steps.expose-tunnel.outputs.tunnel-url }}" >> .env
# Start the services
diff --git a/packages/twenty-server/.env.example b/packages/twenty-server/.env.example
index 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.test
index 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/ge
AUTH_MICROSOFT_CALLBACK_URL=http://localhost:3000/auth/microsoft/redirect
AUTH_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/twenty
diff --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.ts
new file mode 100644
index 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.ts
index 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);
}
};