|
| 1 | +name: PostHog Examples - E2E tests |
| 2 | +permissions: |
| 3 | + contents: read |
| 4 | + |
| 5 | +on: |
| 6 | + schedule: |
| 7 | + # Runs nightly at 12am PST (which is 8am UTC) |
| 8 | + - cron: '0 8 * * *' |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + discover: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + examples: ${{ steps.set-examples.outputs.examples }} |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Discover examples with Playwright configs |
| 20 | + id: set-examples |
| 21 | + run: | |
| 22 | + examples=$(find basics -maxdepth 2 -name "playwright.config.ts" -exec dirname {} \; | sed 's|^basics/||' | jq -R -s -c 'split("\n")[:-1]') |
| 23 | + echo "examples=$examples" >> $GITHUB_OUTPUT |
| 24 | + echo "Found examples: $examples" |
| 25 | +
|
| 26 | + test: |
| 27 | + needs: discover |
| 28 | + if: needs.discover.outputs.examples != '[]' |
| 29 | + timeout-minutes: 60 |
| 30 | + runs-on: ubuntu-latest |
| 31 | + strategy: |
| 32 | + fail-fast: false |
| 33 | + matrix: |
| 34 | + example: ${{ fromJson(needs.discover.outputs.examples) }} |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - uses: actions/setup-node@v4 |
| 39 | + with: |
| 40 | + node-version: lts/* |
| 41 | + |
| 42 | + - uses: pnpm/action-setup@v4 |
| 43 | + with: |
| 44 | + version: latest |
| 45 | + |
| 46 | + - name: Install dependencies |
| 47 | + run: | |
| 48 | + cd basics/${{ matrix.example }} |
| 49 | + pnpm install |
| 50 | +
|
| 51 | + - name: Install Playwright Browsers |
| 52 | + run: | |
| 53 | + cd basics/${{ matrix.example }} |
| 54 | + pnpm exec playwright install chromium --with-deps |
| 55 | +
|
| 56 | + - name: Run E2E Playwright tests |
| 57 | + run: | |
| 58 | + cd basics/${{ matrix.example }} |
| 59 | + pnpm run test:e2e |
| 60 | + env: |
| 61 | + NEXT_PUBLIC_POSTHOG_KEY: ${{ vars.NEXT_PUBLIC_POSTHOG_KEY }} |
| 62 | + NEXT_PUBLIC_POSTHOG_HOST: ${{ vars.NEXT_PUBLIC_POSTHOG_HOST }} |
| 63 | + PERSONAL_ACCESS_KEY: ${{ secrets.PERSONAL_ACCESS_KEY }} |
| 64 | + PROJECT_ID: ${{ vars.PROJECT_ID }} |
| 65 | + |
| 66 | + - name: Send failure event to PostHog |
| 67 | + if: failure() |
| 68 | + run: | |
| 69 | + curl -X POST https://webhooks.us.posthog.com/public/webhooks/019a7a81-7961-0000-d3e3-b5f34cc2a32b \ |
| 70 | + -H "Content-Type: application/json" \ |
| 71 | + -d '{ |
| 72 | + "event": "posthog-examples-repo-test-failure", |
| 73 | + "commitSha": "${{ github.sha }}", |
| 74 | + "jobStatus": "${{ job.status }}", |
| 75 | + "commitMessage": "${{ github.event.head_commit.message }}", |
| 76 | + "commitAuthor": "${{ github.event.head_commit.author.name }}", |
| 77 | + "ref": "${{ github.ref }}", |
| 78 | + "workflow": "${{ github.workflow }}", |
| 79 | + "runId": "${{ github.run_id }}", |
| 80 | + "runNumber": "${{ github.run_number }}", |
| 81 | + "jobUrl": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}", |
| 82 | + "matrixExample": "${{ matrix.example }}" |
| 83 | + }' |
| 84 | +
|
| 85 | + - uses: actions/upload-artifact@v4 |
| 86 | + if: always() |
| 87 | + with: |
| 88 | + name: playwright-report-${{ matrix.example }} |
| 89 | + path: basics/${{ matrix.example }}/playwright-report/ |
| 90 | + retention-days: 30 |
| 91 | + |
0 commit comments