Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

ci: build hogql-parser-rs from source when it changes (#102526)

Raúl Negrón-Otero620e18f2e16d
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.yml
index 1b8a17ff2954..771638f649c3 100644
--- a/.depot/workflows/ci-backend.yml
+++ b/.depot/workflows/ci-backend.yml
@@ -354,6 +354,7 @@ jobs:
- '!ee/frontend/**' # frontend code under ee/ must not trigger backend
- 'common/__init__.py'
- 'common/hogql_parser/**'
+ - 'rust/hogql/parser/**'
- 'common/hogvm/**'
- 'common/ingestion/**'
- 'common/migration_utils/**'
@@ -450,6 +451,7 @@ jobs:
- '!ee/frontend/**' # frontend code under ee/ must not trigger backend
- 'common/__init__.py'
- 'common/hogql_parser/**'
+ - 'rust/hogql/parser/**'
- 'common/hogvm/**'
- 'common/ingestion/**'
- 'common/migration_utils/**'
@@ -2459,6 +2461,17 @@ jobs:
git fetch --no-tags --prune --depth=1 https://github.com/PostHog/posthog.git master
changed=$(git diff --quiet HEAD FETCH_HEAD -- common/hogql_parser/ && echo "false" || echo "true")
echo "changed=$changed" >> $GITHUB_OUTPUT
+ # A branch that predates the crate has nothing to install.
+ rust_changed=false
+ if [[ -f rust/hogql/parser/pyproject.toml ]]; then
+ crate_version=$(grep -m1 '^version = ' rust/hogql/parser/pyproject.toml | sed -E 's/version = "(.*)"/\1/')
+ # Publishing is a manual step after merge, so master can carry a crate version that
+ # the root pin does not name yet. That version builds from source too.
+ if ! git diff --quiet HEAD FETCH_HEAD -- rust/hogql/parser/ || ! grep -q "\"hogql-parser-rs==$crate_version\"" pyproject.toml; then
+ rust_changed=true
+ fi
+ fi
+ echo "rust_changed=$rust_changed" >> $GITHUB_OUTPUT
# tests would intermittently fail in GH actions
# with exit code 134 _after passing_ all tests
# this appears to fix it
@@ -2515,6 +2528,12 @@ jobs:
sudo ldconfig
cd ..
pip install ./common/hogql_parser
+ - name: Install the working version of hogql-parser-rs
+ if: ${{ needs.changes.outputs.backend == 'true' && steps.hogql-parser-diff.outputs.rust_changed == 'true' }}
+ shell: bash
+ # rust-py is the production parser, so its tests must run against this branch's
+ # crate rather than the version pinned in the root pyproject.toml.
+ run: pip install ./rust/hogql/parser
- name: Set up needed files
shell: bash
run: |
diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml
index 263c81843368..588304f62302 100644
--- a/.github/workflows/ci-backend.yml
+++ b/.github/workflows/ci-backend.yml
@@ -225,6 +225,7 @@ jobs:
- '!ee/frontend/**' # frontend code under ee/ must not trigger backend
- 'common/__init__.py'
- 'common/hogql_parser/**'
+ - 'rust/hogql/parser/**'
- 'common/hogvm/**'
- 'common/ingestion/**'
- 'common/migration_utils/**'
@@ -321,6 +322,7 @@ jobs:
- '!ee/frontend/**' # frontend code under ee/ must not trigger backend
- 'common/__init__.py'
- 'common/hogql_parser/**'
+ - 'rust/hogql/parser/**'
- 'common/hogvm/**'
- 'common/ingestion/**'
- 'common/migration_utils/**'
@@ -3061,6 +3063,17 @@ jobs:
git fetch --no-tags --prune --depth=1 origin master
changed=$(git diff --quiet HEAD origin/master -- common/hogql_parser/ && echo "false" || echo "true")
echo "changed=$changed" >> $GITHUB_OUTPUT
+ # A branch that predates the crate has nothing to install.
+ rust_changed=false
+ if [[ -f rust/hogql/parser/pyproject.toml ]]; then
+ crate_version=$(grep -m1 '^version = ' rust/hogql/parser/pyproject.toml | sed -E 's/version = "(.*)"/\1/')
+ # Publishing is a manual step after merge, so master can carry a crate version that
+ # the root pin does not name yet. That version builds from source too.
+ if ! git diff --quiet HEAD origin/master -- rust/hogql/parser/ || ! grep -q "\"hogql-parser-rs==$crate_version\"" pyproject.toml; then
+ rust_changed=true
+ fi
+ fi
+ echo "rust_changed=$rust_changed" >> $GITHUB_OUTPUT
# tests would intermittently fail in GH actions
# with exit code 134 _after passing_ all tests
@@ -3123,6 +3136,13 @@ jobs:
cd ..
pip install ./common/hogql_parser
+ - name: Install the working version of hogql-parser-rs
+ if: ${{ needs.changes.outputs.backend == 'true' && steps.hogql-parser-diff.outputs.rust_changed == 'true' }}
+ shell: bash
+ # rust-py is the production parser, so its tests must run against this branch's
+ # crate rather than the version pinned in the root pyproject.toml.
+ run: pip install ./rust/hogql/parser
+
- name: Set up needed files
shell: bash
run: |
diff --git a/tools/snob_backend_test_selection_shadow.py b/tools/snob_backend_test_selection_shadow.py
index 1a8df3aa27e1..eaff57330a8a 100755
--- a/tools/snob_backend_test_selection_shadow.py
+++ b/tools/snob_backend_test_selection_shadow.py
@@ -91,9 +91,10 @@ FULL_RUN_PATTERNS = (
"frontend/public/email/",
"rust/feature-flags/src/properties/property_models.rs",
"common/plugin_transpiler/src",
- # C++ parser and HogQL VM: no Python import edge reaches them, but they change
- # what every HogQL query evaluates to.
+ # Both HogQL parsers and the HogQL VM: no Python import edge reaches them, but they
+ # change what every HogQL query evaluates to.
"common/hogql_parser/",
+ "rust/hogql/parser/",
"common/hogvm/",
# Generates frontend/src/products.json, which is a full-run pattern in its own right.
"manifest.tsx",
diff --git a/tools/test_snob_backend_test_selection_shadow.py b/tools/test_snob_backend_test_selection_shadow.py
index d38fd5e8e021..715a1c2cd7d0 100644
--- a/tools/test_snob_backend_test_selection_shadow.py
+++ b/tools/test_snob_backend_test_selection_shadow.py
@@ -295,6 +295,7 @@ class TestSnobBackendTestSelectionShadow(unittest.TestCase):
[
("quarantine_lift", ".test_quarantine.json"),
("hogql_parser_sources", "common/hogql_parser/HogQLParser.cpp"),
+ ("hogql_parser_rs_sources", "rust/hogql/parser/src/lib.rs"),
("hogvm", "common/hogvm/python/execute.py"),
("product_manifest", "products/surveys/manifest.tsx"),
]