Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: nx + pnpm + frontend + storybook + ... #27966

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
a2e4d02
feat(devex): minimal nx setup
mariusandra Jan 22, 2025
0fb3308
Update @posthog/hogvm version in package.json
github-actions[bot] Jan 22, 2025
35b1a08
revert nx/storybook
mariusandra Jan 22, 2025
27c01d0
Merge branch 'master' into nx2
mariusandra Jan 23, 2025
488a372
build frontend with nx in dockerfile
mariusandra Jan 23, 2025
21cd6fb
add project files
mariusandra Jan 24, 2025
8de12fe
always install nx
mariusandra Jan 24, 2025
174048a
Update query snapshots
github-actions[bot] Jan 24, 2025
aa6696a
Update query snapshots
github-actions[bot] Jan 24, 2025
6a0a45d
remove some projecvts
mariusandra Jan 24, 2025
b903a30
Merge branch 'nx2' of github.com:PostHog/posthog into nx2
mariusandra Jan 24, 2025
a406ad8
link to local hogvm
mariusandra Jan 24, 2025
23859ab
serve depends on build
mariusandra Jan 24, 2025
1c79b29
Merge branch 'master' into nx2
mariusandra Jan 24, 2025
d55b840
do not modify package.json for hogvm
mariusandra Jan 24, 2025
0cd3cac
more stuff
mariusandra Jan 24, 2025
4bb7e43
remove nx plugins
mariusandra Jan 24, 2025
a55723a
split python-requiring stl generation
mariusandra Jan 24, 2025
6da5fb5
more deps
mariusandra Jan 24, 2025
c90688f
what about now?
mariusandra Jan 24, 2025
53eb989
cwd
mariusandra Jan 27, 2025
7d685be
Merge branch 'master' into nx2
mariusandra Jan 27, 2025
bb2c600
rename
mariusandra Jan 27, 2025
aebc2f1
install more deps
mariusandra Jan 27, 2025
380e94b
add pnpm workspaces for the 2 packages
mariusandra Jan 27, 2025
46ac92b
fix hog ci
mariusandra Jan 27, 2025
3b7c69a
try as a file
mariusandra Jan 27, 2025
9dc6883
build better
mariusandra Jan 27, 2025
f765507
multiple lockfiles
mariusandra Jan 27, 2025
d79cde4
.
mariusandra Jan 27, 2025
b763e54
sort
mariusandra Jan 27, 2025
670e830
are we a workspaced monorepo again?
mariusandra Jan 28, 2025
026dc0f
docker
mariusandra Jan 28, 2025
c4e138c
more docker
mariusandra Jan 28, 2025
4aa4fbc
build package
mariusandra Jan 28, 2025
60b662e
...
mariusandra Jan 28, 2025
12a87d9
no targets here
mariusandra Jan 28, 2025
35f5328
fetch
mariusandra Jan 28, 2025
d6e4f5e
ignore more modules
mariusandra Jan 28, 2025
04973e8
work pls
mariusandra Jan 28, 2025
0248344
install
mariusandra Jan 28, 2025
e440e8c
deps
mariusandra Jan 28, 2025
e77996d
try this way
mariusandra Jan 28, 2025
5c8579b
revert
mariusandra Jan 28, 2025
71d2846
pnpm nx
mariusandra Jan 28, 2025
7762c40
pnpm nx
mariusandra Jan 28, 2025
c4c87d9
..
mariusandra Jan 28, 2025
636f3b9
top nx
mariusandra Jan 28, 2025
f546521
this should work for now
mariusandra Jan 28, 2025
aebde0b
bin/nx
mariusandra Jan 28, 2025
7b12711
remove temp file
mariusandra Jan 28, 2025
926d94c
split frontend
mariusandra Jan 28, 2025
7bf26e8
eslint
mariusandra Jan 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 42 additions & 36 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
*
!bin
!requirements.txt
!requirements-dev.txt
!posthog
!plugin-server
!staticfiles
!manage.py
!gunicorn.config.py
!babel.config.js
!posthog.json
!package.json
!pnpm-lock.yaml
!webpack.config.js
!playwright.config.ts
!tailwind.config.js
!.devcontainer
!.kearc
!.npmrc
!.storybook
!tsconfig.json
!products
!babel.config.js
!bin
!common/hogvm
!common/plugin_transpiler
!dags
!ee
!frontend/@posthog
!frontend/*.*
!frontend/public
!frontend/src
!frontend/types
!frontend/public
!frontend/*.*
!ee
!.devcontainer
!gunicorn.config.py
!manage.py
!nx.json
!package.json
!patches
!playwright.config.ts
!plugin-server
!plugin-server/.eslintrc.js
!plugin-server/.prettierrc
!plugin-server/package.json
!plugin-server/pnpm-lock.yaml
!plugin-server/tsconfig.json
!plugin-server/tsconfig.eslint.json
!plugin-server/src
!plugin-server/.eslintrc.js
!plugin-server/.prettierrc
!plugin-server/tsconfig.eslint.json
!plugin-server/tsconfig.json
!pnpm-lock.yaml
!pnpm-workspace.yaml
!posthog
!posthog.json
!products
!project.json
!requirements-dev.txt
!requirements.txt
!rust
!share/GeoLite2-City.mmdb
!common/hogvm/python
!unit.json.tpl
!common/plugin_transpiler/src
!common/plugin_transpiler/*.*
!test-runner-jest.config.js
!staticfiles
!tailwind.config.js
!test-runner-jest-environment.js
!patches
!rust
!test-runner-jest.config.js
!tsconfig.json
!unit.json.tpl
!webpack.config.js
common/*/node_modules
common/*/*/node_modules
common/hogvm/typescript/dist
rust/.env
rust/.github
rust/docker
rust/target
rust/cyclotron-node/dist
rust/cyclotron-node/node_modules
rust/cyclotron-node/index.node
!dags
rust/cyclotron-node/node_modules
rust/docker
rust/target
2 changes: 1 addition & 1 deletion .github/actions/run-backend-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ runs:
shell: bash
run: |
cd common/plugin_transpiler
pnpm install
pnpm install --frozen-lockfile --filter @posthog/plugin-transpiler...
pnpm run build

- name: Install Python dependencies
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/ci-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ jobs:
restore-keys: |
${{ runner.os }}-pnpm-cypress-

- name: Install package.json dependencies with pnpm
- name: Build and install frontend build dependencies
if: needs.changes.outputs.shouldTriggerCypress == 'true'
run: pnpm install --frozen-lockfile
run: |
pnpm install --frozen-lockfile --filter @posthog/frontend...
bin/nx deps:build frontend --verbose

- name: Stop/Start stack with Docker Compose
# these are required checks so, we can't skip entire sections
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/ci-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ jobs:
key: ${{ runner.os }}-pnpm-cypress-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-cypress-

- name: Install package.json dependencies with pnpm
- name: Build and install frontend build dependencies
if: needs.changes.outputs.frontend == 'true'
run: pnpm install --frozen-lockfile
run: |
pnpm install --frozen-lockfile --filter @posthog/frontend...
bin/nx deps:build frontend --verbose

- name: Check formatting with prettier
if: needs.changes.outputs.frontend == 'true'
Expand Down Expand Up @@ -151,9 +153,11 @@ jobs:
node-version: 18.12.1
cache: pnpm

- name: Install package.json dependencies with pnpm
- name: Build and install frontend build dependencies
if: needs.changes.outputs.frontend == 'true'
run: pnpm install --frozen-lockfile
run: |
pnpm install --frozen-lockfile --filter @posthog/frontend...
bin/nx deps:build frontend --verbose

- name: Test with Jest
# set maxWorkers or Jest only uses 1 CPU in GitHub Actions
Expand Down
102 changes: 7 additions & 95 deletions .github/workflows/ci-hog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,16 @@ jobs:

- name: Run HogVM TypeScript tests
run: |
cd common/hogvm/typescript
pnpm install --frozen-lockfile
pnpm run test
pnpm install --filter @posthog/hogvm
bin/nx test hogvm-ts --verbose

- name: Run Hog tests
run: |
cd common/hogvm/typescript
pnpm run build
cd ../
pnpm run generate:stl
cd ../../..
bin/nx build hogvm-ts --verbose
cd common/hogvm
./test.sh && git diff --exit-code

check-package-version:
Expand Down Expand Up @@ -191,99 +192,10 @@ jobs:
node-version: 18
registry-url: https://registry.npmjs.org
- name: Install package.json dependencies
run: cd common/hogvm/typescript && pnpm install
run: cd common/hogvm/typescript && pnpm install --filter @posthog/hogvm...
- name: Publish the package in the npm registry
run: cd common/hogvm/typescript && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Sleep 60 seconds to allow npm to update the package
run: sleep 60

update-versions:
name: Update versions in package.json
runs-on: ubuntu-24.04
needs: release-hogvm
if: always() # This ensures the job runs regardless of the result of release-hogvm
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 1
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}

- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Set up Node 18
uses: actions/setup-node@v4
with:
node-version: 18
registry-url: https://registry.npmjs.org

- name: Check for version mismatches
id: check-mismatch
run: |
# Extract committed version
HOGVM_VERSION=$(jq -r '.version' common/hogvm/typescript/package.json)

# Compare dependencies in package.json
MAIN_VERSION=$(jq -r '.dependencies."@posthog/hogvm"' package.json | tr -d '^')
PLUGIN_VERSION=$(jq -r '.dependencies."@posthog/hogvm"' plugin-server/package.json | tr -d '^')

echo "HOGVM_VERSION=$HOGVM_VERSION"
echo "MAIN_VERSION=$MAIN_VERSION"
echo "PLUGIN_VERSION=$PLUGIN_VERSION"

# Set output if mismatches exist
if [[ "$HOGVM_VERSION" != "$MAIN_VERSION" || "$HOGVM_VERSION" != "$PLUGIN_VERSION" ]]; then
echo "mismatch=true" >> "$GITHUB_ENV"
else
echo "mismatch=false" >> "$GITHUB_ENV"
fi

- name: Update package.json versions
if: env.mismatch == 'true'
run: |
VERSION=$(jq ".version" common/hogvm/typescript/package.json -r)

retry_pnpm_install() {
local retries=0
local max_retries=20 # 10 minutes total
local delay=30

while [[ $retries -lt $max_retries ]]; do
echo "Attempting pnpm install (retry $((retries+1))/$max_retries)..."
pnpm install --no-frozen-lockfile && break
echo "Install failed. Retrying in $delay seconds..."
sleep $delay
retries=$((retries + 1))
done

if [[ $retries -eq $max_retries ]]; then
echo "pnpm install failed after $max_retries attempts."
exit 1
fi
}

# Update main package.json
mv package.json package.old.json
jq --indent 4 '.dependencies."@posthog/hogvm" = "^'$VERSION'"' package.old.json > package.json
rm package.old.json
retry_pnpm_install

# Update plugin-server/package.json
cd plugin-server
mv package.json package.old.json
jq --indent 4 '.dependencies."@posthog/hogvm" = "^'$VERSION'"' package.old.json > package.json
rm package.old.json
retry_pnpm_install

- name: Commit updated package.json files
if: env.mismatch == 'true'
uses: EndBug/add-and-commit@v9
with:
add: '["package.json", "pnpm-lock.yaml", "plugin-server/package.json", "plugin-server/pnpm-lock.yaml", "common/hogvm/typescript/package.json"]'
message: 'Update @posthog/hogvm version in package.json'
default_author: github_actions
github_token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
11 changes: 7 additions & 4 deletions .github/workflows/ci-plugin-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
cache: pnpm

- name: Install package.json dependencies with pnpm
run: pnpm install --frozen-lockfile
run: pnpm install --frozen-lockfile --filter @posthog/plugin-server...

- name: Check formatting with prettier
run: pnpm prettier:check
Expand Down Expand Up @@ -165,7 +165,10 @@ jobs:

- name: Install package.json dependencies with pnpm
if: needs.changes.outputs.plugin-server == 'true'
run: cd plugin-server && pnpm i
run: |
cd plugin-server
pnpm install --frozen-lockfile --filter @posthog/plugin-server...
cd .. && bin/nx deps:build plugin-server --verbose

- name: Wait for Clickhouse, Redis & Kafka
if: needs.changes.outputs.plugin-server == 'true'
Expand Down Expand Up @@ -259,8 +262,8 @@ jobs:
if: needs.changes.outputs.plugin-server == 'true'
run: |
cd plugin-server
pnpm install --frozen-lockfile
pnpm build
pnpm install --frozen-lockfile --filter @posthog/plugin-server...
cd .. && bin/nx deps:build plugin-server --verbose

- name: Wait for Clickhouse, Redis & Kafka
if: needs.changes.outputs.plugin-server == 'true'
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/storybook-chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ jobs:
cache: pnpm

- name: Install dependencies and Chromatic
run: pnpm i -D chromatic
run: |
pnpm install --frozen-lockfile --filter @posthog/frontend...
bin/nx deps:build frontend --verbose
pnpm i -D -w chromatic

- name: Publish to Chromatic
uses: chromaui/action@v11
Expand Down Expand Up @@ -114,11 +117,13 @@ jobs:
node-version: 18.12.1
cache: pnpm

- name: Install package.json dependencies with pnpm
run: pnpm install --frozen-lockfile
- name: Build and install frontend build dependencies
run: |
pnpm install --frozen-lockfile --filter @posthog/frontend...
bin/nx deps:build frontend --verbose

- name: Install CI utilities with pnpm
run: pnpm install http-server wait-on
run: pnpm install http-server wait-on -g

- name: Build Storybook
run: pnpm build-storybook --test --quiet # Silence since progress logging results in a massive wall of spam
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ common/plugin_transpiler/dist
*.log
# pyright config (keep this until we have a standardized one)
pyrightconfig.json
.nx/cache
.nx/workspace-data
.parcel-cache

# Max-specific entries
ee/support_sidebar_max/max-venv/
Expand All @@ -86,5 +89,3 @@ temp_test_run_data.json

# ignore all dagster tmp directories that may be created
tmp*/

frontend/@posthog/apps-common/dist/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shared-workspace-lockfile=false
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ posthog/templates/email/*
common/hogvm/typescript/src/stl/bytecode.ts
rust/
livestream/

/.nx/cache
/.nx/workspace-data
Loading