Skip to content

Commit

Permalink
Merge branch 'main' into dn-feat/custom-root
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin committed Mar 13, 2024
2 parents 23fb9f6 + 18479b4 commit a5bbd88
Show file tree
Hide file tree
Showing 139 changed files with 31,722 additions and 24,490 deletions.
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
[
"@babel/transform-react-jsx",
{
"pragma": "Preact.h",
"pragmaFrag": "Preact.Fragment"
"runtime": "automatic",
"importSource": "preact"
}
]
]
Expand Down
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
## Checklist
- [ ] Tests for new code (see [advice on the tests we use](https://github.com/PostHog/posthog-js#tiers-of-testing))
- [ ] Accounted for the impact of any changes across different browsers
- [ ] Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)
20 changes: 20 additions & 0 deletions .github/workflows/bundled-size.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8.x.x

- name: Get pnpm cache directory path
id: pnpm-cache-dir
run: echo "PNPM_STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
id: pnpm-cache
with:
path: ${{ steps.pnpm-cache-dir.outputs.PNPM_STORE_PATH }}
key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-

- name: Install package.json dependencies with pnpm
run: pnpm install --frozen-lockfile

- uses: preactjs/compressed-size-action@v2
with:
build-script: "build-rollup"
Expand Down
55 changes: 44 additions & 11 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- master

jobs:
check-package-version:
Expand Down Expand Up @@ -32,19 +31,35 @@ jobs:
PUBLISHED_VERSION: ${{ needs.check-package-version.outputs.published-version }}
steps:
- name: Checkout the repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}

- uses: pnpm/action-setup@v2
with:
version: 8.x.x

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

- name: Install dependencies
run: yarn --frozen-lockfile
- name: Get pnpm cache directory path
id: pnpm-cache-dir
run: echo "PNPM_STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
id: pnpm-cache
with:
path: |
${{ steps.pnpm-cache-dir.outputs.PNPM_STORE_PATH }}
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-
- name: Install package.json dependencies with pnpm
run: pnpm install --frozen-lockfile

- name: Publish the package in the npm registry
run: npm publish --access public
Expand All @@ -54,12 +69,30 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Create GitHub release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.COMMITTED_VERSION }}
release_name: ${{ env.COMMITTED_VERSION }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# read from the first until the second header in the changelog file
# this assumes the formatting of the file
# and that this workflow is always running for the most recent entry in the file
LAST_CHANGELOG_ENTRY=$(awk -v defText="see CHANGELOG.md" '/^## /{if (flag) exit; flag=1} flag && /^##$/{exit} flag; END{if (!flag) print defText}' CHANGELOG.md)
# the action we used to use was archived, and made it really difficult to create a release with a body
# because the LAST_CHANGELOG_ENTRY contains bash special characters so passing it between steps
# was a pain.
# we can use the github cli to create a release with a body
# all as part of one step
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/posthog/posthog-js/releases \
-f tag_name="v${{ env.COMMITTED_VERSION }}" \
-f target_commitish='main' \
-f name="${{ env.COMMITTED_VERSION }}" \
-f body="$LAST_CHANGELOG_ENTRY" \
-F draft=false \
-F prerelease=false \
-F generate_release_notes=false
create-pull-request:
name: Create main repo PR with new posthog-js version
Expand Down Expand Up @@ -88,7 +121,7 @@ jobs:
id: pnpm-upgrade
run: |
OUTGOING_VERSION=$(jq '.dependencies["posthog-js"]' package.json -r)
echo "::set-output name=outgoing-version::$OUTGOING_VERSION"
echo "outgoing-version=$OUTGOING_VERSION" >> "$GITHUB_OUTPUT"
for i in $(seq 1 $RETRY_TIMES); do
# Retry loop because of npm being _eventually_ consistent
if pnpm upgrade posthog-js@${{ env.COMMITTED_VERSION }}; then
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/label-version-bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ jobs:
)
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
fetch-depth: 0

- uses: pnpm/action-setup@v2
with:
version: 8.x.x

- name: Detect version bump type
id: bump-type
run: |
Expand All @@ -36,7 +40,7 @@ jobs:
if [[ $BUMP_MAJOR_PRESENT == 'true' ]]; then
BUMP_TYPE=major
fi
echo "::set-output name=bump-type::$BUMP_TYPE"
echo "bump-type=$BUMP_TYPE" >> "$GITHUB_OUTPUT"
env:
BUMP_PATCH_PRESENT: ${{ contains(github.event.pull_request.labels.*.name, 'bump patch') }}
BUMP_MINOR_PRESENT: ${{ contains(github.event.pull_request.labels.*.name, 'bump minor') }}
Expand All @@ -48,8 +52,8 @@ jobs:
run: |
OLD_VERSION=$(jq ".version" package.json -r)
NEW_VERSION=$(npx semver $OLD_VERSION -i ${{ steps.bump-type.outputs.bump-type }})
echo "::set-output name=old-version::$OLD_VERSION"
echo "::set-output name=new-version::$NEW_VERSION"
echo "old-version=$OLD_VERSION" >> "$GITHUB_OUTPUT"
echo "new-version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
- name: Update version in package.json
if: steps.bump-type.outputs.bump-type != 'null'
Expand All @@ -66,8 +70,8 @@ jobs:
echo -e "$CHANGELOG_HEADING\n\n$CHANGELOG_POINTS\n\n$(cat CHANGELOG.old.md)" > CHANGELOG.md
rm CHANGELOG.old.md
- name: Update yarn.lock
run: yarn
- name: Update lockfile
run: pnpm i

- name: Commit bump
if: steps.bump-type.outputs.bump-type != 'null'
Expand Down
98 changes: 54 additions & 44 deletions .github/workflows/library-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,88 @@ on:
pull_request:
push:
branches:
- master
- main

jobs:
unit:
name: Unit tests
runs-on: ubuntu-latest
steps:
# Check out the repository
- uses: actions/checkout@v3

# Install Node.js
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
node-version: 18
cache: 'yarn'

# Install your dependencies
- run: yarn install

- run: yarn test
version: 8.x.x
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'
- run: pnpm install
- run: pnpm test:unit

integration:
name: Cypress
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
version: 8.x.x
- uses: actions/setup-node@v4
with:
node-version: 18
cache: 'yarn'
node-version: '18'
- name: Get pnpm cache directory path
id: pnpm-cache-dir
run: echo "PNPM_STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- run: yarn install && yarn build
- name: Get cypress cache directory path
id: cypress-cache-dir
run: echo "CYPRESS_BIN_PATH=$(npx cypress cache path)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
id: pnpm-cache
with:
path: |
${{ steps.pnpm-cache-dir.outputs.PNPM_STORE_PATH }}
${{ steps.cypress-cache-dir.outputs.CYPRESS_BIN_PATH }}
key: ${{ runner.os }}-pnpm-cypress-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-cypress-
- name: Install package.json dependencies with pnpm
run: pnpm install --frozen-lockfile
- run: pnpm build
- name: Cypress run
uses: cypress-io/github-action@v6

functional:
name: Functional tests
runs-on: ubuntu-latest
steps:
# Check out the repository
- uses: actions/checkout@v3

# Install Node.js
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
node-version: 18
cache: 'yarn'

# Install your dependencies
- run: yarn install

- run: yarn jest functional_tests/
version: 8.x.x
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'
- run: pnpm install
- run: pnpm run test:functional

lint:
name: Lint
runs-on: ubuntu-latest
steps:
# Check out the repository
- uses: actions/checkout@v3

# Install Node.js
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
node-version: 18
cache: 'yarn'

# Install your dependencies
- run: yarn install
version: 8.x.x
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'
- run: pnpm install

- run: |
yarn prettier --check
yarn lint
yarn tsc -b
pnpm prettier --check
pnpm lint
pnpm tsc -b
4 changes: 2 additions & 2 deletions .github/workflows/new-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
)
echo "::debug::Filtered PR body to $FILTERED_BODY"
if [[ -z "${FILTERED_BODY//[[:space:]]/}" ]]; then
echo "::set-output name=is-shame-worthy::true"
echo "is-shame-worthy=true" >> "$GITHUB_OUTPUT"
else
echo "::set-output name=is-shame-worthy::false"
echo "is-shame-worthy=false" >> "$GITHUB_OUTPUT"
fi
env:
RAW_BODY: ${{ github.event.pull_request.body }}
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/react.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ jobs:
name: Test with React
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
node-version: 18
cache: 'yarn'
- run: yarn && yarn build && cd react && yarn test
version: 8.x.x
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'
- run: pnpm install && pnpm build && cd react && pnpm test
14 changes: 8 additions & 6 deletions .github/workflows/ssr-es-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ jobs:
name: Cypress
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
node-version: 18
cache: 'yarn'

version: 8.x.x
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'

- run: yarn install && yarn build
- run: pnpm install && pnpm build

- name: Run es-check to check if our bundle is ES5 compatible
run: npx [email protected] es5 dist/{array,module}.js
Expand Down
Loading

0 comments on commit a5bbd88

Please sign in to comment.