Skip to content

Commit

Permalink
Merge branch 'master' into fix-interval-filter-logic
Browse files Browse the repository at this point in the history
# Conflicts:
#	frontend/src/lib/components/IntervalFilter/intervalFilterLogic.ts
  • Loading branch information
thmsobrmlr committed Oct 29, 2023
2 parents 41d382a + ec095f3 commit 31ccf57
Show file tree
Hide file tree
Showing 1,576 changed files with 67,231 additions and 21,418 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MAPLIBRE_STYLE_URL=https://api.example.com/style.json?key=mykey
20 changes: 18 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ module.exports = {
react: {
version: 'detect',
},
'import/resolver': {
node: {
paths: ['eslint-rules'], // Add the directory containing your custom rules
extensions: ['.js', '.jsx', '.ts', '.tsx'], // Ensure ESLint resolves both JS and TS files
},
},
},
extends: [
'eslint:recommended',
Expand All @@ -37,7 +43,7 @@ module.exports = {
ecmaVersion: 2018,
sourceType: 'module',
},
plugins: ['prettier', 'react', 'cypress', '@typescript-eslint', 'no-only-tests', 'jest', 'compat'],
plugins: ['prettier', 'react', 'cypress', '@typescript-eslint', 'no-only-tests', 'jest', 'compat', 'posthog'],
rules: {
'no-console': ['error', { allow: ['warn', 'error'] }],
'no-debugger': 'error',
Expand Down Expand Up @@ -91,7 +97,7 @@ module.exports = {
],
},
],
'react/forbid-elements': [
'posthog/warn-elements': [
1,
{
forbid: [
Expand Down Expand Up @@ -236,6 +242,16 @@ module.exports = {
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: 'eslint-rules/**/*',
extends: ['eslint:recommended'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
env: {
node: true,
},
},
],
reportUnusedDisableDirectives: true,
}
14 changes: 10 additions & 4 deletions .github/actions/build-n-cache-image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ inputs:
actions-id-token-request-url:
required: true
description: "ACTIONS_ID_TOKEN_REQUEST_URL, issued by GitHub when permission 'id-token' is set to 'write'"
load:
save:
required: false
default: 'false'
description: Whether to load the image into local Docker after building it
description: Whether to save the image in the Depot ephemeral registry after building it

outputs:
tag:
description: The tag of the image that was built
value: ${{ steps.emit.outputs.tag }}
build-id:
description: The ID of the build
value: ${{ steps.build.outputs.build-id }}
unit-build-id:
description: The ID of the unit build
value: ${{ steps.build-unit.outputs.build-id }}

runs:
using: 'composite'
Expand All @@ -30,10 +36,10 @@ runs:
uses: depot/build-push-action@v1
with:
buildx-fallback: false # buildx is so slow it's better to just fail
load: ${{ inputs.load }}
tags: ${{ steps.emit.outputs.tag }}
platforms: linux/amd64,linux/arm64
build-args: COMMIT_HASH=${{ github.sha }}
save: ${{ inputs.save }}
env:
ACTIONS_ID_TOKEN_REQUEST_URL: ${{ inputs.actions-id-token-request-url }}

Expand All @@ -42,10 +48,10 @@ runs:
uses: depot/build-push-action@v1
with:
buildx-fallback: false # buildx is so slow it's better to just fail
load: ${{ inputs.load }}
file: production-unit.Dockerfile
tags: ${{ steps.emit.outputs.tag }}
platforms: linux/amd64
build-args: COMMIT_HASH=${{ github.sha }}
save: ${{ inputs.save }}
env:
ACTIONS_ID_TOKEN_REQUEST_URL: ${{ inputs.actions-id-token-request-url }}
4 changes: 2 additions & 2 deletions .github/actions/run-backend-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ runs:
# changed (requirements.txt has the already-published version)
run: |
sudo apt-get install libboost-all-dev unzip cmake curl uuid pkg-config
curl https://www.antlr.org/download/antlr4-cpp-runtime-4.13.0-source.zip --output antlr4-source.zip
curl https://www.antlr.org/download/antlr4-cpp-runtime-4.13.1-source.zip --output antlr4-source.zip
# Check that the downloaded archive is the expected runtime - a security measure
anltr_known_md5sum="ff214b65fb02e150b4f515d7983bca92"
anltr_known_md5sum="c875c148991aacd043f733827644a76f"
antlr_found_ms5sum="$(md5sum antlr4-source.zip | cut -d' ' -f1)"
if [[ "$anltr_known_md5sum" != "$antlr_found_ms5sum" ]]; then
echo "Unexpected MD5 sum of antlr4-source.zip!"
Expand Down
28 changes: 17 additions & 11 deletions .github/workflows/build-hogql-parser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,47 @@ concurrency:
jobs:
check-version:
name: Check version legitimacy
if: github.repository == 'PostHog/posthog'
runs-on: ubuntu-22.04
outputs:
parser_any_changed: ${{ steps.changed-files-yaml.outputs.parser_any_changed }}
parser-release-needed: ${{ steps.version.outputs.parser-release-needed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetching all for comparison since last push (not just last commit)

- name: Check if hogql_parser/ has changed
id: changed-files-yaml
id: changed-files
uses: tj-actions/changed-files@v39
with:
since_last_remote_commit: true
files_yaml: |
parser:
- hogql_parser/**
- name: Notify about release needed
if: steps.changed-files-yaml.outputs.parser_any_changed == 'true'
- name: Check if version was bumped
shell: bash
id: version
run: |
published=$(curl -fSsl https://pypi.org/pypi/hogql-parser/json | jq -r '.info.version')
local=$(python hogql_parser/setup.py --version)
# TODO: Only comment if no comment alraedy exists for $local
if [[ "$published" == "$local" ]]; then
MESSAGE_BODY="It looks like the code of `hogql-parser` has changed since last push, but its version stayed the same at $local. 👀\nMake sure to resolve this in `hogql_parser/setup.py` before merging!"
curl -s -u posthog-bot:${{ secrets.POSTHOG_BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }} -X POST -d "{ \"body\": \"$MESSAGE_BODY\" }" "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
parser_release_needed='false'
if [[ ${{ steps.changed-files.outputs.parser_any_changed }} == 'true' ]]; then
published=$(curl -fSsl https://pypi.org/pypi/hogql-parser/json | jq -r '.info.version')
local=$(python hogql_parser/setup.py --version)
if [[ "$published" != "$local" ]]; then
parser_release_needed='true'
else
message_body="It looks like the code of \`hogql-parser\` has changed since last push, but its version stayed the same at $local. 👀\nMake sure to resolve this in \`hogql_parser/setup.py\` before merging!"
curl -s -u posthog-bot:${{ secrets.POSTHOG_BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }} -X POST -d "{ \"body\": \"$message_body\" }" "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
fi
fi
echo "::set-output name=parser-release-needed::$parser_release_needed"
build-wheels:
name: Build wheels on ${{ matrix.os }}
needs: check-version
runs-on: ${{ matrix.os }}
timeout-minutes: 30
if: ${{ needs.check-version.outputs.parser_any_changed == 'true' }}
if: ${{ needs.check-version.outputs.parser-release-needed == 'true' }}
strategy:
matrix:
# As of October 2023, GitHub doesn't have ARM Actions runners… and ARM emulation is insanely slow
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:
- name: Check formatting
run: |
black --exclude posthog/hogql/grammar --check .
black --exclude posthog/hogql/grammar --check --diff .
- name: Check static typing
run: |
Expand Down Expand Up @@ -159,7 +159,7 @@ jobs:
env:
# Installing a version of ANTLR compatible with what's in Homebrew as of October 2023 (version 4.13),
# as apt-get is quite out of date. The same version must be set in hogql_parser/pyproject.toml
ANTLR_VERSION: '4.13.0'
ANTLR_VERSION: '4.13.1'

check-migrations:
needs: changes
Expand Down Expand Up @@ -272,9 +272,9 @@ jobs:
# Also skip for persons-on-events runs, as we want to ignore snapshots diverging there
if: ${{ github.repository == 'PostHog/posthog' && needs.changes.outputs.backend == 'true' && !matrix.person-on-events }}
with:
add: '["ee", "posthog/clickhouse/test/__snapshots__", "posthog/api/test/__snapshots__", "posthog/test/__snapshots__", "posthog/queries/", "posthog/migrations", "posthog/tasks", "posthog/hogql/"]'
add: '["ee", "./**/*.ambr", "posthog/queries/", "posthog/migrations", "posthog/tasks", "posthog/hogql/"]'
message: 'Update query snapshots'
pull: --rebase --autostash # Make sure we're up to date with other segments' updates
pull: --rebase --autostash # Make sure we're up-to-date with other segments' updates
default_author: github_actions
github_token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}

Expand Down
31 changes: 20 additions & 11 deletions .github/workflows/ci-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,21 @@ jobs:
permissions:
contents: read
id-token: write # allow issuing OIDC tokens for this workflow run
outputs:
tag: ${{ steps.build.outputs.tag }}
build-id: ${{ steps.build.outputs.build-id }}
unit-build-id: ${{ steps.build.outputs.unit-build-id }}
steps:
- name: Checkout
if: needs.changes.outputs.shouldTriggerCypress == 'true'
uses: actions/checkout@v3
- name: Get Docker image cached in Depot
- name: Build the Docker image with Depot
if: needs.changes.outputs.shouldTriggerCypress == 'true'
# Build the container image in preparation for the E2E tests
uses: ./.github/actions/build-n-cache-image
id: build
with:
save: true
actions-id-token-request-url: ${{ env.ACTIONS_ID_TOKEN_REQUEST_URL }}

cypress:
Expand Down Expand Up @@ -157,17 +163,20 @@ jobs:
if: needs.changes.outputs.shouldTriggerCypress == 'true'
run: ./bin/check_kafka_clickhouse_up

- name: Install Depot CLI
if: needs.changes.outputs.shouldTriggerCypress == 'true'
uses: depot/setup-action@v1

- name: Get Docker image cached in Depot
if: needs.changes.outputs.shouldTriggerCypress == 'true'
# We don't actually build the image here, because we use Depot, which acts as our cross-workflow cache.
# The build is first initiated in container-images-ci.yml, so by the time this runs, some layers already
# are cached, and the in-flight builds overall are deduplicated. According to Depot folks, this applies
# even if the builds _start_ concurrently! In short, only one build per commit push is ever executed.
uses: ./.github/actions/build-n-cache-image
id: docker-build
uses: depot/pull-action@v1
with:
actions-id-token-request-url: ${{ env.ACTIONS_ID_TOKEN_REQUEST_URL }}
load: true
# Use the production.Dockerfile image:
# build-id: ${{ needs.container.outputs.build-id }}
# Use the production-unit.Dockerfile image:
build-id: ${{ needs.container.outputs.unit-build-id }}
tags: |
${{ needs.container.outputs.tag }}
- name: Write .env # This step intentionally has no if, so that GH always considers the action as having run
run: |
Expand Down Expand Up @@ -199,8 +208,8 @@ jobs:
run: |
mkdir -p /tmp/logs
echo "Starting PostHog using the container image ${{ steps.docker-build.outputs.tag }}"
DOCKER_RUN="docker run --rm --network host --add-host kafka:127.0.0.1 --env-file .env ${{ steps.docker-build.outputs.tag }}"
echo "Starting PostHog using the container image ${{ needs.container.outputs.tag }}"
DOCKER_RUN="docker run --rm --network host --add-host kafka:127.0.0.1 --env-file .env ${{ needs.container.outputs.tag }}"
$DOCKER_RUN ./bin/migrate
$DOCKER_RUN python manage.py setup_dev
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci-plugin-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ jobs:
CLICKHOUSE_DATABASE: 'posthog_test'
KAFKA_HOSTS: 'kafka:9092'
DATABASE_URL: 'postgres://posthog:posthog@localhost:5432/posthog'
RELOAD_PLUGIN_JITTER_MAX_MS: 0
POE_EMBRACE_JOIN_FOR_TEAMS: ${{matrix.POE_EMBRACE_JOIN_FOR_TEAMS}}

steps:
Expand Down
20 changes: 17 additions & 3 deletions .github/workflows/storybook-chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,15 @@ jobs:

- name: Serve Storybook in the background
run: |
pnpm exec http-server storybook-static --port 6006 --silent &
pnpm wait-on http://127.0.0.1:6006 --timeout 60 # Wait for the server to be ready
retries=3
while [ $retries -gt 0 ]; do
pnpm exec http-server storybook-static --port 6006 --silent &
if pnpm wait-on http://127.0.0.1:6006 --timeout 60; then
break
fi
retries=$((retries-1))
echo "Failed to serve Storybook, retrying... ($retries retries left)"
done
- name: Run @storybook/test-runner
env:
Expand All @@ -139,7 +146,14 @@ jobs:
# Update snapshots for PRs on the main repo, verify on forks, which don't have access to PostHog Bot
VARIANT: ${{ github.event.pull_request.head.repo.full_name == github.repository && 'update' || 'verify' }}
run: |
pnpm test:visual-regression:stories:ci:$VARIANT --browsers ${{ matrix.browser }} --shard ${{ matrix.shard }}/$SHARD_COUNT
retries=3
while [ $retries -gt 0 ]; do
if pnpm test:visual-regression:stories:ci:$VARIANT --browsers ${{ matrix.browser }} --shard ${{ matrix.shard }}/$SHARD_COUNT; then
break
fi
retries=$((retries-1))
echo "Failed @storybook/test-runner, retrying... ($retries retries left)"
done
- name: Run @playwright/test (legacy, Chromium-only)
if: matrix.browser == 'chromium' && matrix.shard == 1
Expand Down
20 changes: 0 additions & 20 deletions .storybook/decorators/with3000.tsx

This file was deleted.

14 changes: 10 additions & 4 deletions .storybook/decorators/withFeatureFlags.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { useFeatureFlags } from '~/mocks/browser'
import type { DecoratorFn } from '@storybook/react'
import { setFeatureFlags } from '~/mocks/browser'
import type { Decorator } from '@storybook/react'

declare module '@storybook/types' {
interface Parameters {
featureFlags?: string[]
}
}

/** Global story decorator that allows setting feature flags.
*
Expand All @@ -13,9 +19,9 @@ import type { DecoratorFn } from '@storybook/react'
* } as ComponentMeta<typeof MyComponent>
* ```
*/
export const withFeatureFlags: DecoratorFn = (Story, { parameters }) => {
export const withFeatureFlags: Decorator = (Story, { parameters }) => {
if (parameters.featureFlags) {
useFeatureFlags(parameters.featureFlags)
setFeatureFlags(parameters.featureFlags)
}

return <Story />
Expand Down
4 changes: 2 additions & 2 deletions .storybook/decorators/withKea/withKea.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { DecoratorFn } from '@storybook/react'
import type { Decorator } from '@storybook/react'
import { useAvailableFeatures } from '~/mocks/features'

import { KeaStory } from './kea-story'

export const withKea: DecoratorFn = (Story) => {
export const withKea: Decorator = (Story) => {
// Reset enabled enterprise features. Overwrite this line within your stories.
useAvailableFeatures([])
return (
Expand Down
10 changes: 8 additions & 2 deletions .storybook/decorators/withMockDate.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import type { DecoratorFn } from '@storybook/react'
import type { Decorator } from '@storybook/react'
import MockDate from 'mockdate'

declare module '@storybook/types' {
interface Parameters {
mockDate?: string | number | Date
}
}

/** Global story decorator that allows mocking of dates.
*
* ```ts
Expand All @@ -13,7 +19,7 @@ import MockDate from 'mockdate'
* } as ComponentMeta<typeof MyComponent>
* ```
*/
export const withMockDate: DecoratorFn = (Story, { parameters }) => {
export const withMockDate: Decorator = (Story, { parameters }) => {
if (parameters.mockDate) {
MockDate.set(parameters.mockDate)
} else {
Expand Down
4 changes: 2 additions & 2 deletions .storybook/decorators/withSnapshotsDisabled.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DecoratorFn } from '@storybook/react'
import { Decorator } from '@storybook/react'
import { inStorybookTestRunner } from 'lib/utils'

/** Workaround for https://github.com/storybookjs/test-runner/issues/74 */
// TODO: Smoke-test all the stories by removing this decorator, once all the stories pass
export const withSnapshotsDisabled: DecoratorFn = (Story, { parameters }) => {
export const withSnapshotsDisabled: Decorator = (Story, { parameters }) => {
if (parameters?.testOptions?.skip && inStorybookTestRunner()) {
return <>Disabled for Test Runner</>
}
Expand Down
Loading

0 comments on commit 31ccf57

Please sign in to comment.