From 553dd5bfbfe0f1c090d69913d07b434df4f6db58 Mon Sep 17 00:00:00 2001 From: Ben White Date: Thu, 23 Nov 2023 10:46:27 +0100 Subject: [PATCH 1/9] Added ability to import code from ee folder --- ee/frontend/exports.ts | 13 +++++++++++++ frontend/@posthog/ee/exports.ts | 7 +++++++ frontend/@posthog/ee/types.ts | 5 +++++ tsconfig.json | 3 ++- 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 ee/frontend/exports.ts create mode 100644 frontend/@posthog/ee/exports.ts create mode 100644 frontend/@posthog/ee/types.ts diff --git a/ee/frontend/exports.ts b/ee/frontend/exports.ts new file mode 100644 index 0000000000000..29d80016d730c --- /dev/null +++ b/ee/frontend/exports.ts @@ -0,0 +1,13 @@ +import { PostHogEE } from '@posthog/ee/types' + +const myTestCode = (): void => { + // eslint-disable-next-line no-console + console.log('it works!') +} + +const postHogEE: PostHogEE = { + enabled: true, + myTestCode, +} + +export default postHogEE diff --git a/frontend/@posthog/ee/exports.ts b/frontend/@posthog/ee/exports.ts new file mode 100644 index 0000000000000..96d7dc5a5e93d --- /dev/null +++ b/frontend/@posthog/ee/exports.ts @@ -0,0 +1,7 @@ +import { PostHogEE } from './types' + +const posthogEE: PostHogEE = { + enabled: false, +} + +export default posthogEE diff --git a/frontend/@posthog/ee/types.ts b/frontend/@posthog/ee/types.ts new file mode 100644 index 0000000000000..7270631c7c78f --- /dev/null +++ b/frontend/@posthog/ee/types.ts @@ -0,0 +1,5 @@ +// NOTE: All exported items from the EE module _must_ be optionally defined to ensure we work well with FOSS +export type PostHogEE = { + enabled: boolean + myTestCode?: () => void +} diff --git a/tsconfig.json b/tsconfig.json index d00e7af6a118b..ef6815e5be0d8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,7 @@ "@posthog/lemon-ui": ["@posthog/lemon-ui/src/index"], "@posthog/lemon-ui/*": ["@posthog/lemon-ui/src/*"], "storybook/*": ["../.storybook/*"], + "@posthog/ee/exports": ["../ee/exports", "@posthog/ee/exports"], "~/*": ["src/*"], "public/*": ["public/*"] }, @@ -33,7 +34,7 @@ "suppressImplicitAnyIndexErrors": true, // Index objects by number "lib": ["dom", "es2019"] }, - "include": ["frontend/**/*", ".storybook/**/*"], + "include": ["frontend/**/*", ".storybook/**/*", "ee/frontend/**/*"], "exclude": ["frontend/dist/**/*"], "ts-node": { "compilerOptions": { From c7bc1252edf2f91a56bff47586aa052757604a95 Mon Sep 17 00:00:00 2001 From: Ben White Date: Thu, 23 Nov 2023 11:02:39 +0100 Subject: [PATCH 2/9] Added ee testing --- .github/workflows/ci-frontend.yml | 6 ++++++ frontend/src/test/ee.test.ts | 14 ++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 frontend/src/test/ee.test.ts diff --git a/.github/workflows/ci-frontend.yml b/.github/workflows/ci-frontend.yml index 2ea70218bd608..1fc1717f84b62 100644 --- a/.github/workflows/ci-frontend.yml +++ b/.github/workflows/ci-frontend.yml @@ -123,12 +123,17 @@ jobs: # If one test fails, still run the others fail-fast: false matrix: + segment: ['FOSS', 'EE'] chunk: [1, 2, 3] steps: # we need at least one thing to run to make sure we include everything for required jobs - uses: actions/checkout@v3 + - name: Remove ee + if: needs.changes.outputs.frontend == 'true' && matrix.segment == 'FOSS' + run: rm -rf ee + - name: Install pnpm if: needs.changes.outputs.frontend == 'true' uses: pnpm/action-setup@v2 @@ -152,3 +157,4 @@ jobs: if: needs.changes.outputs.frontend == 'true' env: NODE_OPTIONS: --max-old-space-size=6144 + TEST_SEGMENT: ${{ matrix.segment }} diff --git a/frontend/src/test/ee.test.ts b/frontend/src/test/ee.test.ts new file mode 100644 index 0000000000000..017863f6069c9 --- /dev/null +++ b/frontend/src/test/ee.test.ts @@ -0,0 +1,14 @@ +export const ifEeIt = process.env.TEST_SEGMENT !== 'FOSS' ? it : it.skip +export const ifFossIt = process.env.TEST_SEGMENT !== 'EE' ? it : it.skip + +import posthogEE from '@posthog/ee/exports' + +describe('ee importing', () => { + ifEeIt('should import actual ee code', () => { + expect(posthogEE.enabled).toBe(true) + }) + + ifFossIt('should import actual ee code', () => { + expect(posthogEE.enabled).toBe(false) + }) +}) From 9d01b19fede41587fef838fbd3cfc057c137427d Mon Sep 17 00:00:00 2001 From: Ben White Date: Thu, 23 Nov 2023 11:17:31 +0100 Subject: [PATCH 3/9] Fixes --- .github/workflows/ci-frontend.yml | 1 - frontend/src/{test => lib}/ee.test.ts | 7 +++++-- frontend/src/scenes/App.tsx | 3 +++ jest.config.ts | 1 + webpack.config.js | 4 ++++ 5 files changed, 13 insertions(+), 3 deletions(-) rename frontend/src/{test => lib}/ee.test.ts (60%) diff --git a/.github/workflows/ci-frontend.yml b/.github/workflows/ci-frontend.yml index 1fc1717f84b62..f2ac861953499 100644 --- a/.github/workflows/ci-frontend.yml +++ b/.github/workflows/ci-frontend.yml @@ -157,4 +157,3 @@ jobs: if: needs.changes.outputs.frontend == 'true' env: NODE_OPTIONS: --max-old-space-size=6144 - TEST_SEGMENT: ${{ matrix.segment }} diff --git a/frontend/src/test/ee.test.ts b/frontend/src/lib/ee.test.ts similarity index 60% rename from frontend/src/test/ee.test.ts rename to frontend/src/lib/ee.test.ts index 017863f6069c9..e5cddf9ec2436 100644 --- a/frontend/src/test/ee.test.ts +++ b/frontend/src/lib/ee.test.ts @@ -1,5 +1,8 @@ -export const ifEeIt = process.env.TEST_SEGMENT !== 'FOSS' ? it : it.skip -export const ifFossIt = process.env.TEST_SEGMENT !== 'EE' ? it : it.skip +import fs from 'fs' + +const eeFolderExists = fs.existsSync('ee/frontend/exports.ts') +export const ifEeIt = eeFolderExists ? it : it.skip +export const ifFossIt = !eeFolderExists ? it : it.skip import posthogEE from '@posthog/ee/exports' diff --git a/frontend/src/scenes/App.tsx b/frontend/src/scenes/App.tsx index 1bc924fbc7bfc..b374789ba3393 100644 --- a/frontend/src/scenes/App.tsx +++ b/frontend/src/scenes/App.tsx @@ -1,3 +1,4 @@ +import posthogEE from '@posthog/ee/exports' import { actions, BindLogic, connect, events, kea, path, reducers, selectors, useMountedLogic, useValues } from 'kea' import { FEATURE_FLAGS } from 'lib/constants' import { ToastCloseButton } from 'lib/lemon-ui/lemonToast' @@ -26,6 +27,8 @@ import type { appLogicType } from './AppType' import { preflightLogic } from './PreflightCheck/preflightLogic' import { teamLogic } from './teamLogic' +console.log(posthogEE) + export const appLogic = kea([ path(['scenes', 'App']), connect([teamLogic, organizationLogic, frontendAppsLogic, inAppPromptLogic, actionsModel, cohortsModel]), diff --git a/jest.config.ts b/jest.config.ts index 54aa39875ab00..3ff4eeff1d470 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -89,6 +89,7 @@ const config: Config = { '^~/(.*)$': '/$1', '^@posthog/lemon-ui(|/.*)$': '/../@posthog/lemon-ui/src/$1', '^@posthog/apps-common(|/.*)$': '/../@posthog/apps-common/src/$1', + '^@posthog/ee/exports': ['/../../ee/frontend/exports', '/../@posthog/ee/exports'], '^lib/(.*)$': '/lib/$1', '^scenes/(.*)$': '/scenes/$1', '^antd/es/(.*)$': 'antd/lib/$1', diff --git a/webpack.config.js b/webpack.config.js index afa086a96c11c..aef12b7ab0c4b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -56,6 +56,10 @@ function createEntry(entry) { scenes: path.resolve(__dirname, 'frontend', 'src', 'scenes'), '@posthog/apps-common': path.resolve(__dirname, 'frontend', '@posthog', 'apps-common', 'src'), '@posthog/lemon-ui': path.resolve(__dirname, 'frontend', '@posthog', 'lemon-ui', 'src'), + '@posthog/ee/exports': [ + path.resolve(__dirname, 'ee', 'frontend', 'exports'), + path.resolve(__dirname, 'frontend', '@posthog', 'ee', 'exports'), + ], storybook: path.resolve(__dirname, '.storybook'), types: path.resolve(__dirname, 'frontend', 'types'), public: path.resolve(__dirname, 'frontend', 'public'), From abd12740d2f0c32703e5e921276ecae949ef731b Mon Sep 17 00:00:00 2001 From: Ben White Date: Thu, 23 Nov 2023 11:51:29 +0100 Subject: [PATCH 4/9] Fixes --- .github/workflows/ci-frontend.yml | 2 +- frontend/src/lib/ee.test.ts | 4 ++-- frontend/src/scenes/App.tsx | 3 --- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-frontend.yml b/.github/workflows/ci-frontend.yml index f2ac861953499..bce550ae1114f 100644 --- a/.github/workflows/ci-frontend.yml +++ b/.github/workflows/ci-frontend.yml @@ -117,7 +117,7 @@ jobs: jest: runs-on: ubuntu-latest needs: changes - name: Jest test (${{ matrix.chunk }}) + name: Jest test (${{ matrix.segment }} - ${{ matrix.chunk }}) strategy: # If one test fails, still run the others diff --git a/frontend/src/lib/ee.test.ts b/frontend/src/lib/ee.test.ts index e5cddf9ec2436..1dddd991cb8a9 100644 --- a/frontend/src/lib/ee.test.ts +++ b/frontend/src/lib/ee.test.ts @@ -8,10 +8,10 @@ import posthogEE from '@posthog/ee/exports' describe('ee importing', () => { ifEeIt('should import actual ee code', () => { - expect(posthogEE.enabled).toBe(true) + expect(posthogEE.enabled).toBe(false) }) ifFossIt('should import actual ee code', () => { - expect(posthogEE.enabled).toBe(false) + expect(posthogEE.enabled).toBe(true) }) }) diff --git a/frontend/src/scenes/App.tsx b/frontend/src/scenes/App.tsx index b374789ba3393..1bc924fbc7bfc 100644 --- a/frontend/src/scenes/App.tsx +++ b/frontend/src/scenes/App.tsx @@ -1,4 +1,3 @@ -import posthogEE from '@posthog/ee/exports' import { actions, BindLogic, connect, events, kea, path, reducers, selectors, useMountedLogic, useValues } from 'kea' import { FEATURE_FLAGS } from 'lib/constants' import { ToastCloseButton } from 'lib/lemon-ui/lemonToast' @@ -27,8 +26,6 @@ import type { appLogicType } from './AppType' import { preflightLogic } from './PreflightCheck/preflightLogic' import { teamLogic } from './teamLogic' -console.log(posthogEE) - export const appLogic = kea([ path(['scenes', 'App']), connect([teamLogic, organizationLogic, frontendAppsLogic, inAppPromptLogic, actionsModel, cohortsModel]), From 537a52dd088413b7b363ce6cd5b550f0692ad8f1 Mon Sep 17 00:00:00 2001 From: Ben White Date: Thu, 23 Nov 2023 11:51:59 +0100 Subject: [PATCH 5/9] Fix tests --- frontend/src/lib/ee.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/ee.test.ts b/frontend/src/lib/ee.test.ts index 1dddd991cb8a9..e5cddf9ec2436 100644 --- a/frontend/src/lib/ee.test.ts +++ b/frontend/src/lib/ee.test.ts @@ -8,10 +8,10 @@ import posthogEE from '@posthog/ee/exports' describe('ee importing', () => { ifEeIt('should import actual ee code', () => { - expect(posthogEE.enabled).toBe(false) + expect(posthogEE.enabled).toBe(true) }) ifFossIt('should import actual ee code', () => { - expect(posthogEE.enabled).toBe(true) + expect(posthogEE.enabled).toBe(false) }) }) From 768705fa131dfcdd4b0826aa2c4bad1ad6b844a2 Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Thu, 23 Nov 2023 15:17:48 +0000 Subject: [PATCH 6/9] trigger front end CI when ee/frontend path changes --- .github/workflows/ci-frontend.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-frontend.yml b/.github/workflows/ci-frontend.yml index bce550ae1114f..ae403132640b5 100644 --- a/.github/workflows/ci-frontend.yml +++ b/.github/workflows/ci-frontend.yml @@ -35,6 +35,7 @@ jobs: # NOTE: we are at risk of missing a dependency here. - 'bin/**' - 'frontend/**' + - 'ee/frontend/** # Make sure we run if someone is explicitly change the workflow - .github/workflows/ci-frontend.yml # various JS config files From 706c59764c70ab80aa9d7cd0e90a7c2e5a17eab1 Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Thu, 23 Nov 2023 15:19:41 +0000 Subject: [PATCH 7/9] add a comment --- .github/workflows/ci-backend.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml index 4e09f52eda7b6..bec279609e086 100644 --- a/.github/workflows/ci-backend.yml +++ b/.github/workflows/ci-backend.yml @@ -60,6 +60,7 @@ jobs: # NOTE: we are at risk of missing a dependency here. We could make # the dependencies more clear if we separated the backend/frontend # code completely + # really we should ignore ee/frontend/** but dorny doesn't support that - 'ee/**/*' - 'posthog/**/*' - 'bin/*.py' From 2a8c1768b0091c72e0b097f361eb910eb019b47e Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Thu, 23 Nov 2023 15:21:09 +0000 Subject: [PATCH 8/9] Fix --- .github/workflows/ci-frontend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-frontend.yml b/.github/workflows/ci-frontend.yml index ae403132640b5..c586598152fd6 100644 --- a/.github/workflows/ci-frontend.yml +++ b/.github/workflows/ci-frontend.yml @@ -35,7 +35,7 @@ jobs: # NOTE: we are at risk of missing a dependency here. - 'bin/**' - 'frontend/**' - - 'ee/frontend/** + - 'ee/frontend/**' # Make sure we run if someone is explicitly change the workflow - .github/workflows/ci-frontend.yml # various JS config files From 109542bfd03b7c7ce5e03ff9ba320b7cf882364f Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Thu, 23 Nov 2023 15:27:13 +0000 Subject: [PATCH 9/9] does it secretly support exclusion --- .github/workflows/ci-backend.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml index bec279609e086..a346ec59367a7 100644 --- a/.github/workflows/ci-backend.yml +++ b/.github/workflows/ci-backend.yml @@ -62,6 +62,7 @@ jobs: # code completely # really we should ignore ee/frontend/** but dorny doesn't support that - 'ee/**/*' + - '!ee/frontend/**' - 'posthog/**/*' - 'bin/*.py' - requirements.txt