Skip to content

Commit

Permalink
feat: setup release action (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
qingzhuozhen authored May 31, 2022
1 parent 71832de commit 508364b
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 5 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Publish to PyPI

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

jobs:
authorize:
name: Authorize
runs-on: ubuntu-latest
steps:
- name: ${{ github.actor }} permission check to do a release
uses: "lannonbr/[email protected]"
with:
permission: "write"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-n-publish:
name: Build and publish to PyPI
runs-on: ubuntu-latest
needs: [authorize]
steps:
- name: Checkout for release to PyPI
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python 3.7
uses: actions/setup-python@v3
with:
python-version: 3.7

- name: Run Test
run: python -m unittest discover -s ./tests -p '*_test.py'

- name: Publish distribution PyPI --dry-run
if: ${{ github.event.inputs.dryRun == 'true'}}
run: |
python -m pip install python-semantic-release
semantic-release publish --noop
- name: Publish distribution PyPI
if: ${{ github.event.inputs.dryRun == 'false'}}
run: |
python -m pip install python-semantic-release
git config user.name amplitude-sdk-bot
git config user.email [email protected]
semantic-release publish
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY_USERNAME: __token__
REPOSITORY_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
40 changes: 40 additions & 0 deletions .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish to TestPyPI

on: workflow_dispatch

jobs:
authorize:
name: Authorize
runs-on: ubuntu-latest
steps:
- name: ${{ github.actor }} permission check to do a release
uses: "lannonbr/[email protected]"
with:
permission: "write"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-n-publish:
name: Build and publish to TestPyPI
runs-on: ubuntu-latest
needs: [authorize]
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.7
uses: actions/setup-python@v3
with:
python-version: 3.7

- name: Install dependencies
run: python -m pip install build setuptools wheel twine

- name: Build a binary wheel and a source tarball
run: python -m build --sdist --wheel --outdir dist/ .

- name: Publish distribution Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,59 @@
<br />
</p>

# experiment-python-server
[![PyPI version](https://badge.fury.io/py/amplitude-experiment.svg)](https://badge.fury.io/py/amplitude-experiment)

# Experiment Python SDK
Amplitude Python Server SDK for Experiment.

## Installation
```python
pip install amplitude-experiment
```

## Quick Start
```python
from amplitude_experiment import Experiment, Config, Client, User

# (1) Get your deployment's API key
apiKey = 'YOUR-API-KEY'

# (2) Initialize the experiment client
experiment = Experiment.initialize(api_key)

# (3) Fetch variants for a user
user = User(device_id="abcdefg", user_id="[email protected]", user_properties={
'premium': True
})

# (4) Lookup a flag's variant
#
# To fetch synchronous
variants = experiment.fetch(user)
variant = variants['sdk-ci-test']
if variant:
if variant.value == 'on':
# Flag is on
else:
# Flag is off

# To fetch asynchronous
experiment.fetch_async(user, fetch_callback)

def fetch_callback(user, variants):
variant = variants['sdk-ci-test']
if variant:
if variant.value == 'on':
# Flag is on
else:
# Flag is off


```
## More Information
Please visit our :100:[Developer Center](https://www.docs.developers.amplitude.com/experiment/sdks/python-sdk/) for more instructions on using our the SDK.

See our [Experiment Python SDK Docs](https://amplitude.github.io/experiment-python-server/) for a list and description of all available SDK methods.

## Need Help?
If you have any problems or issues over our SDK, feel free to [create a github issue](https://github.com/amplitude/experiments-python-server/issues/new) or submit a request on [Amplitude Help](https://help.amplitude.com/hc/en-us/requests/new).
17 changes: 14 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
[tool.semantic_release]
version_variable = [
"src/amplitude_experiment/version.py:__version__"
]
major_on_zero = true
branch = "main"
upload_to_PyPI = true
upload_to_release = true
build_command = "pip install build && python -m build"
version_source = "commit"
commit_version_number = true
commit_subject = "chore(release): Bump version to {version}"
commit_message = "chore(release): Bump version to {version}"
commit_author = "amplitude-sdk-bot <[email protected]>"
45 changes: 45 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import sys
from setuptools import setup
import pathlib

here = pathlib.Path(__file__).parent.resolve()
sys.path.insert(0, str(here / 'src'))

version = {}
with open("src/amplitude_experiment/version.py") as fp:
exec(fp.read(), version)

# Get the long description from the README file
long_description = (here / "README.md").read_text(encoding="utf-8")

setup(
name="amplitude-experiment",
version=version['__version__'],
description="The official Amplitude Experiment Python SDK for server-side instrumentation.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/amplitude/experiment-python-server",
author="Amplitude Inc.",
author_email="[email protected]",
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
keywords="amplitude, python, backend",
package_dir={"": "src"},
packages=["amplitude_experiment"],
python_requires=">=3.6, <4",
license='MIT License',
project_urls={
"Bug Reports": "https://github.com/amplitude/experiment-python-server/issues",
"Source": "https://github.com/amplitude/experiment-python-server",
"Developer Doc": "https://www.docs.developers.amplitude.com/experiment/sdks/python-sdk/"
}
)
2 changes: 1 addition & 1 deletion src/amplitude_experiment/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.0"
__version__ = "0.1.0"

0 comments on commit 508364b

Please sign in to comment.