Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f4e8d78
test workflow
jooohhn Sep 4, 2020
a1f6cd1
fix macOS
jooohhn Sep 8, 2020
70bf41e
npx semantic-release-cli setup
jooohhn Sep 14, 2020
7d23929
release workflow
jooohhn Sep 14, 2020
b25ead8
change test.yml name
jooohhn Sep 14, 2020
c379cec
adjust for fork
jooohhn Sep 14, 2020
8e129de
fix release.config.js
jooohhn Sep 14, 2020
e1dd717
add make test to release.yml
jooohhn Sep 14, 2020
c456441
disable fail-fast
jooohhn Sep 14, 2020
48e3c44
disable macOS tests
jooohhn Sep 14, 2020
1d500da
fix semantic-release config commonjs
jooohhn Sep 14, 2020
908f3e5
chore(release-pipeline): add husky/commitizen precommit hook
jooohhn Sep 15, 2020
4eacdb9
chore(build-pipeline): add commitlint
jooohhn Sep 15, 2020
9493b22
test: disable flaky snippet tests
jooohhn Sep 18, 2020
c4f64c2
remove commit message check for PR bot
jooohhn Sep 18, 2020
82daca8
build: add scripts/deployjs.py
jooohhn Sep 18, 2020
80e87ab
build: update deployjs to boto3
jooohhn Sep 18, 2020
bba5de3
build: deployjs.py -> deploy_s3.py
jooohhn Sep 18, 2020
1c6ed8d
ci: add semantic-release to release.yml
jooohhn Sep 18, 2020
60c319c
chore: add notice not to edit
jooohhn Sep 18, 2020
4bfafe6
docs: update CONTRIBUTING.md
jooohhn Sep 18, 2020
f02abab
docs: Add PR template
jooohhn Sep 18, 2020
15f057f
ci: re-enable tests in release.yml
jooohhn Sep 18, 2020
49eea5d
ci: remove placeholder release branch
jooohhn Sep 18, 2020
a37f4e6
ci: remove placeholder --dry-run
jooohhn Sep 18, 2020
c81c61f
Comment disabled test
jooohhn Sep 18, 2020
7476c74
remove personal
jooohhn Sep 18, 2020
1db12c3
ci: test workflwo dispatch
jooohhn Sep 21, 2020
065454f
ci: manual release
jooohhn Sep 21, 2020
b9df815
Update CHANGELOG.md
jooohhn Sep 21, 2020
5e54c76
ci: change branch
jooohhn Sep 21, 2020
bdb0177
docs: add amplitude internal
jooohhn Sep 21, 2020
537c67d
docs: update contributing
jooohhn Sep 21, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!---
Thanks for contributing to the Amplitude JavaScript SDK! 🎉

Please fill out the following sections to help us quickly review your pull request.
--->
### Summary

<!-- What does the PR do? -->

### Checklist

* [ ] Does your PR title have the correct [title format](../CONTRIBUTING.md#pr-commit-title-conventions)
* [ ] Does your PR have a breaking change?
19 changes: 19 additions & 0 deletions .github/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Validate the PR title, and ignore the commits
titleOnly: true

# By default types specified in commitizen/conventional-commit-types is used.
# See: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json
# You can override the valid types

types:
- feat
- fix
- perf
- docs
- test
- refactor
- style
- build
- ci
- chore
- revert
77 changes: 77 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Release

on:
workflow_dispatch:
inputs:
dryRun:
description: 'Do a dry run instead of real release'
required: true
default: 'true'

jobs:
authorize:
name: Authorize
runs-on: ubuntu-18.04
steps:
- name: ${{ github.actor }} permission check to do a release
uses: octokit/request-action@v2.0.0
with:
route: GET /repos/:repository/collaborators/${{ github.actor }}
repository: ${{ github.repository }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

release:
name: Release
runs-on: ubuntu-18.04
needs: [authorize]
steps:
- name: Checkout
uses: actions/checkout@v1

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8.x'
- name: Install boto3 for deployjs.python
run: pip install boto3==1.14.63

- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 10.x

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Run tests
run: make test

- name: Release --dry-run # Uses release.config.js
if: ${{ github.event.inputs.dryRun == 'true'}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
run: npx semantic-release --dry-run

- name: Release # Uses release.config.js
if: ${{ github.event.inputs.dryRun == 'false'}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
run: npx semantic-release
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test

on: [push, pull_request]

jobs:
build:
strategy:
fail-fast: false
matrix:
node-version: [10.x, 12.x, 14.x]
# os: [macos-10.14, ubuntu-18.04] @TODO See if MacOS test can be fixed
os: [ubuntu-18.04]
runs-on: ${{ matrix.os }}

steps:
- name: Check out Git repository
uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: yarn install
run: |
yarn install --frozen-lockfile

- name: Build and run tests
run: |
make test
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### As of September 21, 2020 CHANGELOG.md is no longer manually updated. Please check the [releases page](https://github.com/amplitude/Amplitude-JavaScript/releases) for up to date changes.

### 7.1.1 (August 26, 2020)
* Fix an issue with detection of whether or not cookies are enabled on a device

Expand Down
44 changes: 44 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Contributing to the Amplitude SDK for JavaScript

🎉 Thanks for your interest in contributing! 🎉

## Ramping Up

### Intro

- There are three ways for SDK to be loaded
- Standard NPM package
- Snippet in `<script>` tag
Expand All @@ -11,6 +14,7 @@
- Chek out the [Amplitude Instrumentation Explorer]((https://chrome.google.com/webstore/detail/amplitude-instrumentation/acehfjhnmhbmgkedjmjlobpgdicnhkbp)) to help logging events during development

### Architecture

- `index.js` is the main entrypoint of SDK
- Stubbed methods are used when client imports via `<script>` snippet
- Allows app to not be blocked while real JS SDK is loaded in
Expand All @@ -24,10 +28,50 @@
- only applicable to snippet import

### Setting Up Development

- Cloning, installing, and building
```
git clone git@github.com:amplitude/Amplitude-JavaScript.git
cd Amplitude-JavaScript
make # Runs tests and generate builds
yarn dev # Start development utility. Open localhost:9000 in your browser to access
```

### PR Commit Title Conventions

PR titles should follow [conventional commit standards](https://www.conventionalcommits.org/en/v1.0.0/). A [probot app](https://github.com/zeke/semantic-pull-requests) checks for this when a PR is opened. This helps automate the [release](#release) process.

#### Commit Types ([related to release conditions](#release))

- **Special Case**: Any commit with `BREAKING CHANGES` in the body: Creates major release
- `feat(<optional scope>)`: New features (minimum minor release)
- `fix(<optional scope>)`: Bug fixes (minimum patch release)
- `perf(<optional scope>)`: Performance improvement
- `docs(<optional scope>)`: Documentation updates
- `test(<optional scope>)`: Test updates
- `refactor(<optional scope>)`: Code change that neither fixes a bug nor adds a feature
- `style(<optional scope>)`: Code style changes (e.g. formatting, commas, semi-colons)
- `build(<optional scope>)`: Changes that affect the build system or external dependencies (e.g. Yarn, Npm)
- `ci(<optional scope>)`: Changes to our CI configuration files and scripts
- `chore(<optional scope>)`: Other changes that don't modify src or test files
- `revert(<optional scope>)`: Revert commit

### Release [Amplitude Internal]

Releases are managed by [semantic-release](https://github.com/semantic-release/semantic-release). It is a tool that will scan commits since the last release, determine the next [semantic version number](https://semver.org/), publish, and create changelogs.

#### Release Conditions [Amplitude Internal]

- `BREAKING CHANGES` in the body will do a major release
```
feat(cookies): Create new cookie format

BREAKING CHANGES: Breaks old cookie format
```
- Else `feat` in title will do a `minor` release
`feat(cookies): some changes`
- Else `fix` or `perf` in title will do a `patch` release
`fix: null check bug`
- Else no release
`docs: update website`

3 changes: 2 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ module.exports = function(config) {
'**/*.js': ['sourcemap']
},
frameworks: ['mocha', 'chai'],
files: ['amplitude-snippet.min.js', 'build/snippet-tests.js', 'build/tests.js'],
// files: ['amplitude-snippet.min.js', 'build/snippet-tests.js', 'build/tests.js'], @TODO: Fix flaky build/snippet-tests.js and re-enable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove this commented code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO leave it as a todo until we can fix then re-enable the flaky snippet tests

files: ['amplitude-snippet.min.js', 'build/tests.js'],
reporters: ['mocha', 'saucelabs'],
port: 9876, // karma web server port
colors: true,
Expand Down
18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"analytics",
"amplitude"
],
"repository": "git://github.com/amplitude/amplitude-javascript.git",
"repository": {
"type": "git",
"url": "https://github.com/amplitude/amplitude-javascript.git"
},
"main": "amplitude.umd.js",
"react-native": "amplitude.native.js",
"dependencies": {
Expand All @@ -23,6 +26,8 @@
"@babel/plugin-transform-runtime": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/runtime": "^7.3.4",
"@semantic-release/exec": "^5.0.0",
"@semantic-release/git": "^9.0.0",
"chai": "^4.1.2",
"date-fns": "^1.30.1",
"express": "^4.16.2",
Expand Down Expand Up @@ -50,6 +55,7 @@
"rollup-plugin-node-resolve": "^4.0.1",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-uglify": "^6.0.2",
"semantic-release": "^17.1.1",
"sinon": "^7.0.0",
"uglify-js": "^2.0.0"
},
Expand All @@ -62,6 +68,14 @@
"docs:build": "cd website/ && yarn build",
"docs:serve": "cd website/ && yarn serve",
"docs:deploy": "cd website/ && yarn deploy",
"docs:swizzle": "cd website/ && yarn swizzle"
"docs:swizzle": "cd website/ && yarn swizzle",
"semantic-release": "semantic-release"
},
"bugs": {
"url": "https://github.com/amplitude/amplitude-javascript/issues"
},
"homepage": "https://github.com/amplitude/amplitude-javascript#readme",
"directories": {
"test": "test"
}
}
29 changes: 29 additions & 0 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
"branches": ["master"],
"plugins": [
["@semantic-release/commit-analyzer", {
"preset": "angular",
"parserOpts": {
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
}
}],
["@semantic-release/release-notes-generator", {
"preset": "angular",
}],
["@semantic-release/npm", {
"npmPublish": true,
}],
["@semantic-release/exec", {
"prepareCmd": "make release",
"publishCmd": "python scripts/deployjs.py --version ${nextRelease.version}",
"failCmd": "npm unpublish amplitude-js@${nextRelease.version}"
}],
["@semantic-release/github", {
"assets": "amplitude*.js"
}],
["@semantic-release/git", {
"assets": ["package.json", "src/amplitude-snippet.js"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}],
],
}
73 changes: 73 additions & 0 deletions scripts/deploy_s3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import argparse
import os
import sys
from boto3 import Session
from botocore.exceptions import ClientError

unzipped_args = {
'ContentType': 'application/javascript',
'CacheControl': 'max-age=31536000',
'ACL': 'public-read',
}
zipped_args = {
'ContentType': 'application/javascript',
'CacheControl': 'max-age=31536000',
'ContentEncoding': 'gzip',
'ACL': 'public-read',
}

def check_exists(key):
try:
key.load()
except ClientError as e:
if e.response['Error']['Code'] == '404':
return False
else:
return True

def upload(bucket, file, args):
bucket.upload_file(
os.path.join('dist', file),
os.path.join('libs', file),
ExtraArgs=args,
)

def main():
parser = argparse.ArgumentParser()
parser.add_argument('--version', '-v', required=True,
help='Version to deploy')
args = parser.parse_args()
s3 = Session(
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID'),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY'),
region_name=os.environ.get('AWS_REGION'),
).resource('s3')
bucket = s3.Bucket(os.environ.get('S3_BUCKET_NAME'))

files = [
f'amplitude-{args.version}.js',
f'amplitude-{args.version}-min.js',
f'amplitude-{args.version}.umd.js',
f'amplitude-{args.version}-min.umd.js'
]
for file in files:
if check_exists(s3.Object(os.environ.get('S3_BUCKET_NAME'), os.path.join('libs', file))):
sys.exit(f'ERROR: {file} already exists and shouldn\'t be republished. Consider releasing a new version')
print(f'Uploading {file}')
upload(bucket, file, unzipped_args)

gz_files = [
f'amplitude-{args.version}-min.gz.js',
f'amplitude-{args.version}-min.umd.gz.js'
]
for file in gz_files:
if check_exists(s3.Object(os.environ.get('S3_BUCKET_NAME'), file)):
sys.exit(f'{file} already exists!')
print(f'Uploading {file}')
upload(bucket, file, zipped_args)

print(f'Success: S3 upload completed. Example: https://cdn.amplitude.com/libs/amplitude-{args.version}.js')
return 0

if __name__ == '__main__':
sys.exit(main())
2 changes: 2 additions & 0 deletions src/amplitude-snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
var amplitude = window.amplitude || {'_q':[],'_iq':{}};
var as = document.createElement('script');
as.type = 'text/javascript';
// Don't edit as.integrity, it is tracked by semantic-release-bot during releases
as.integrity = 'sha384-+EOJUyXoWkQo2G0XTc+u2DOlZkrMUcc5yOqCuE2XHRnytSyqpFQSbgFZAlGmjpLI';
as.crossOrigin = 'anonymous';
as.async = true;
// Don't edit as.src, it is tracked by semantic-release-bot during releases
as.src = 'https://cdn.amplitude.com/libs/amplitude-7.1.1-min.gz.js';
as.onload = function() {if(!window.amplitude.runQueuedFunctions) {console.log('[Amplitude] Error: could not load SDK');}};
var s = document.getElementsByTagName('script')[0];
Expand Down
Loading