feat(flags): add fresh option to feature flag methods
#9889
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Library checks | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| unit: | |
| name: Unit tests | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup environment | |
| uses: ./.github/actions/setup | |
| - run: pnpm test:unit | |
| integration: | |
| name: Playwright E2E tests | |
| runs-on: depot-ubuntu-latest-8 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup environment | |
| uses: ./.github/actions/setup | |
| with: | |
| build: false | |
| - uses: ./.github/actions/is-affected | |
| id: is-affected | |
| with: | |
| package-name: posthog-js | |
| - name: Build package | |
| run: pnpm build | |
| if: steps.is-affected.outputs.is-affected == 'true' | |
| - name: Install Playwright Browsers | |
| if: steps.is-affected.outputs.is-affected == 'true' | |
| run: pnpm exec playwright install --with-deps | |
| working-directory: packages/browser | |
| - name: Run Playwright tests | |
| if: steps.is-affected.outputs.is-affected == 'true' | |
| run: pnpm exec playwright test --workers=5 | |
| working-directory: packages/browser | |
| - uses: actions/upload-artifact@v4 | |
| if: ${{ !cancelled() && steps.is-affected.outputs.is-affected == 'true' }} | |
| with: | |
| name: playwright-report | |
| path: packages/browser/playwright-report/ | |
| retention-days: 30 | |
| compat: | |
| name: Backward compatibility tests | |
| runs-on: depot-ubuntu-latest-8 | |
| if: github.event_name == 'pull_request' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup environment | |
| uses: ./.github/actions/setup | |
| with: | |
| build: false | |
| - uses: ./.github/actions/is-affected | |
| id: is-affected | |
| with: | |
| package-name: posthog-js | |
| - name: Build package | |
| run: pnpm build | |
| if: steps.is-affected.outputs.is-affected == 'true' | |
| - name: Install Playwright Browsers | |
| if: steps.is-affected.outputs.is-affected == 'true' | |
| run: pnpm exec playwright install --with-deps chromium | |
| working-directory: packages/browser | |
| - name: Run backward compatibility tests | |
| id: compat-tests | |
| if: steps.is-affected.outputs.is-affected == 'true' | |
| continue-on-error: true | |
| run: | | |
| pnpm exec playwright test --config playwright.config.compat.ts --project chromium-compat --workers=5 --reporter=json > compat-results.json 2>&1 || true | |
| cat compat-results.json | |
| working-directory: packages/browser | |
| - name: Process compat test results | |
| if: steps.is-affected.outputs.is-affected == 'true' | |
| id: process-results | |
| working-directory: packages/browser | |
| run: | | |
| if [ ! -f compat-results.json ]; then | |
| echo "has_failures=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| # Extract failed tests | |
| FAILED_TESTS=$(cat compat-results.json | jq -r ' | |
| .suites[]?.suites[]?.specs[]? | | |
| select(.tests[]?.results[]?.status == "failed") | | |
| "- `\(.title)`" | |
| ' 2>/dev/null || echo "") | |
| if [ -z "$FAILED_TESTS" ]; then | |
| echo "has_failures=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_failures=true" >> $GITHUB_OUTPUT | |
| # Store failed tests for the comment | |
| EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) | |
| echo "failed_tests<<$EOF" >> $GITHUB_OUTPUT | |
| echo "$FAILED_TESTS" >> $GITHUB_OUTPUT | |
| echo "$EOF" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Find existing compat comment | |
| if: steps.process-results.outputs.has_failures == 'true' | |
| uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4.0.0 | |
| id: find-comment | |
| with: | |
| issue-number: ${{ github.event.pull_request.number }} | |
| comment-author: 'github-actions[bot]' | |
| body-includes: '<!-- compat-test-results -->' | |
| - name: Create or update compat comment | |
| if: steps.process-results.outputs.has_failures == 'true' | |
| uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 | |
| with: | |
| comment-id: ${{ steps.find-comment.outputs.comment-id }} | |
| issue-number: ${{ github.event.pull_request.number }} | |
| edit-mode: replace | |
| body: | | |
| <!-- compat-test-results --> | |
| ## ⚠️ Backward Compatibility Test Results | |
| Some tests failed when running **newly built extensions** against the **currently published NPM version** of `array.js`. | |
| This is **informational only** - it may indicate: | |
| - 🆕 A new feature that requires the new array.js (expected, not breaking) | |
| - ⚠️ A breaking change that affects users with cached old versions (needs investigation) | |
| ### Failed Tests | |
| ${{ steps.process-results.outputs.failed_tests }} | |
| <details> | |
| <summary>What does this mean?</summary> | |
| Users load `array.js` (the core library) which then lazy-loads extensions like web-vitals, surveys, etc. If a user has an old cached `array.js` but gets new extensions, these tests check if things still work. | |
| - If failures are for **new features** → Expected, the new feature just won't work until they get the new array.js | |
| - If failures are for **existing features** → This could break existing functionality for users with cached versions | |
| </details> | |
| <details> | |
| <summary>How to skip a test for older versions</summary> | |
| If the failure is expected (new feature not available in older versions), add it to `packages/browser/playwright/compat-skips.ts`: | |
| ```typescript | |
| export const compatSkips = [ | |
| { | |
| range: '<1.335.0', | |
| test: 'web_vitals_attribution: true includes attribution data', | |
| reason: 'web_vitals_attribution option added in #2953', | |
| }, | |
| ] | |
| ``` | |
| **You must provide a reason** explaining why this skip is acceptable. | |
| </details> | |
| - name: Delete compat comment if tests pass | |
| if: steps.process-results.outputs.has_failures == 'false' && steps.is-affected.outputs.is-affected == 'true' | |
| uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4.0.0 | |
| id: find-passing-comment | |
| with: | |
| issue-number: ${{ github.event.pull_request.number }} | |
| comment-author: 'github-actions[bot]' | |
| body-includes: '<!-- compat-test-results -->' | |
| - name: Remove outdated comment | |
| if: steps.find-passing-comment.outputs.comment-id != '' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.issues.deleteComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: ${{ steps.find-passing-comment.outputs.comment-id }} | |
| }) | |
| - uses: actions/upload-artifact@v4 | |
| if: ${{ !cancelled() && steps.is-affected.outputs.is-affected == 'true' }} | |
| with: | |
| name: playwright-compat-report | |
| path: packages/browser/playwright-report/ | |
| retention-days: 30 | |
| functional: | |
| name: Functional tests | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup environment | |
| uses: ./.github/actions/setup | |
| with: | |
| build: true | |
| - run: pnpm test:functional | |
| lint: | |
| name: Lint | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup environment | |
| uses: ./.github/actions/setup | |
| - name: Lint all packages | |
| run: pnpm lint | |
| - name: Lint playground files | |
| run: pnpm lint:playground | |
| write-mangled-property-names: | |
| name: Write mangled property names | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup environment | |
| uses: ./.github/actions/setup | |
| with: | |
| build: false | |
| - name: Build posthog-js | |
| run: pnpm exec turbo --filter=posthog-js build | |
| env: | |
| WRITE_MANGLED_PROPERTIES: 1 | |
| - run: git diff --exit-code # fail if e.g. the mangled properties list has changed, see rollup.config.js |