Skip to content

chore(maintenance): general maintencance and ci flow #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 18 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,40 @@ on:
- 'main'
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
build:
name: 🧪 Test & lint
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.6, 3.7, 3.8, 3.9]
python: ["3.7", "3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
with:
python-version: ${{ matrix.python }}
fetch-depth: 0 # gives the commit linter access to previous commits

- name: Commit message linter
if: ${{ matrix.python == '3.7' }}
uses: wagoid/commitlint-github-action@v4

- name: Add pip bin to PATH
run: |
echo "/home/runner/.local/bin" >> $GITHUB_PATH
- uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python }}

- name: Install deps with ${{ matrix.python }}
run: pip install ".[test, ci]"

- name: Lint with ${{ matrix.python }}
if: ${{ matrix.python == '3.8' }}
if: ${{ matrix.python == '3.7' }}
run: make lint

- name: Install, test and code coverage with ${{ matrix.python }}
env:
STREAM_KEY: ${{ secrets.STREAM_KEY }}
STREAM_SECRET: ${{ secrets.STREAM_SECRET }}
run: |
python setup.py install
make test
PYTHONPATH: ${{ github.workspace }}
run: make test
47 changes: 47 additions & 0 deletions .github/workflows/initiate_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Create release PR

on:
workflow_dispatch:
inputs:
version:
description: "The new version number with 'v' prefix. Example: v1.40.1"
required: true

jobs:
init_release:
name: 🚀 Create release PR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # gives the changelog generator access to all previous commits

- name: Update CHANGELOG.md, __pkg__.py and push release branch
env:
VERSION: ${{ github.event.inputs.version }}
run: |
npx --yes standard-version@9.3.2 --release-as "$VERSION" --skip.tag --skip.commit --tag-prefix=v
git config --global user.name 'github-actions'
git config --global user.email 'release@getstream.io'
git checkout -q -b "release-$VERSION"
git commit -am "chore(release): $VERSION"
git push -q -u origin "release-$VERSION"

- name: Get changelog diff
uses: actions/github-script@v5
with:
script: |
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
core.exportVariable('CHANGELOG', get_change_log_diff())

- name: Open pull request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create \
-t "chore(release): ${{ github.event.inputs.version }}" \
-b "# :rocket: ${{ github.event.inputs.version }}
Make sure to use squash & merge when merging!
Once this is merged, another job will kick off automatically and publish the package.
# :memo: Changelog
${{ env.CHANGELOG }}"
48 changes: 48 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Release

on:
pull_request:
types: [closed]
branches:
- main

jobs:
Release:
name: 🚀 Release
if: github.event.pull_request.merged && startsWith(github.head_ref, 'release-')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/github-script@v5
with:
script: |
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
core.exportVariable('CHANGELOG', get_change_log_diff())

// Getting the release version from the PR source branch
// Source branch looks like this: release-1.0.0
const version = context.payload.pull_request.head.ref.split('-')[1]
core.exportVariable('VERSION', version)

- uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Publish to PyPi
env:
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: "${{ secrets.PYPI_TOKEN }}"
run: |
pip install -q twine==3.7.1 wheel==0.37.1
python setup.py sdist bdist_wheel
twine upload --non-interactive dist/*

- name: Create release on GitHub
uses: ncipollo/release-action@v1
with:
body: ${{ env.CHANGELOG }}
tag: ${{ env.VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
30 changes: 30 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: reviewdog
on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
reviewdog:
name: 🐶 Reviewdog
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest

- uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install deps
run: pip install ".[ci]"

- name: Reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: make reviewdog
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ coverage.xml
# Sphinx documentation
docs/_build/


.python-version
secrets.*sh
.idea
.vscode/
Expand Down
16 changes: 16 additions & 0 deletions .versionrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const pkgUpdater = {
VERSION_REGEX: /__version__ = "(.+)"/,

readVersion: function (contents) {
const version = this.VERSION_REGEX.exec(contents)[1];
return version;
},

writeVersion: function (contents, version) {
return contents.replace(this.VERSION_REGEX.exec(contents)[0], `__version__ = "${version}"`);
}
}

module.exports = {
bumpFiles: [{ filename: './stream/__init__.py', updater: pkgUpdater }],
}
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ lint-fix:
black stream

test: ## Run tests
STREAM_KEY=$(STREAM_KEY) STREAM_SECRET=$(STREAM_SECRET) python setup.py test
STREAM_KEY=$(STREAM_KEY) STREAM_SECRET=$(STREAM_SECRET) pytest stream/tests

check: lint test ## Run linters + tests

reviewdog:
black --check --diff --quiet stream | reviewdog -f=diff -f.diff.strip=0 -filter-mode="diff_context" -name=black -reporter=github-pr-review
flake8 --ignore=E501,W503 stream | reviewdog -f=flake8 -name=flake8 -reporter=github-pr-review
75 changes: 29 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
stream-python
=============
# Official Python SDK for [Stream Feeds](https://getstream.io/activity-feeds/)

[![build](https://github.com/GetStream/stream-python/workflows/build/badge.svg)](https://github.com/GetStream/stream-python/actions) [![PyPI version](https://badge.fury.io/py/stream-python.svg)](http://badge.fury.io/py/stream-python) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/stream-python.svg)

[stream-python](https://github.com/GetStream/stream-python) is the official Python client for [Stream](https://getstream.io/), a web service for building scalable newsfeeds and activity streams.
<p align="center">
<img src="./assets/logo.svg" width="50%" height="50%">
</p>
<p align="center">
Official Python API client for Stream Feeds, a web service for building scalable newsfeeds and activity streams.
<br />
<a href="https://getstream.io/activity-feeds/docs/?language=python"><strong>Explore the docs »</strong></a>
<br />
<br />
<a href="https://github.com/GetStream/stream-django">Django Code Sample</a>
·
<a href="https://github.com/GetStream/stream-python/issues">Report Bug</a>
·
<a href="https://github.com/GetStream/stream-python/issues">Request Feature</a>
</p>

Note there is also a higher level [Django - Stream integration](https://github.com/getstream/stream-django) library which hooks into the Django ORM.
## 📝 About Stream

You can sign up for a Stream account at https://getstream.io/get_started.
You can sign up for a Stream account at our [Get Started](https://getstream.io/get_started/) page.

### Installation
You can use this library to access feeds API endpoints server-side.

For the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries ([docs](https://getstream.io/activity-feeds/)).

## ⚙️ Installation

#### Install from Pypi

```bash
pip install stream-python
$ pip install stream-python
```

### Full documentation
## 📚 Full documentation

Documentation for this Python client are available at the [Stream website](https://getstream.io/docs/?language=python).

### Usage
## ✨ Getting started

```python
import datetime
Expand Down Expand Up @@ -149,44 +165,11 @@ redirect_url = client.create_redirect_url('http://google.com/', 'user_id', event

[JS client](http://github.com/getstream/stream-js).

### Contributing

First, make sure you can run the test suite. Tests are run via py.test

```bash
py.test
# with coverage
py.test --cov stream --cov-report html
# against a local API backend
LOCAL=true py.test
```

Install black and flake8

```
pip install .[ci]
```

Install git hooks to avoid pushing invalid code (git commit will run `black` and `flake8`)

### Releasing a new version

In order to release new version you need to be a maintainer on Pypi.

- Update CHANGELOG
- Update the version on setup.py
- Commit and push to Github
- Create a new tag for the version (eg. `v2.9.0`)
- Create a new dist with python `python setup.py sdist`
- Upload the new distributable with twine `twine upload dist/stream-python-VERSION-NAME.tar.gz`

If unsure you can also test using the Pypi test servers `twine upload --repository-url https://test.pypi.org/legacy/ dist/stream-python-VERSION-NAME.tar.gz`

### Copyright and License Information
## ✍️ Contributing

Project is licensed under the [BSD 3-Clause](LICENSE).
We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our [Contributor License Agreement (CLA)](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) first. See our [license file](./LICENSE) for more details.

## We are hiring!
## 🧑‍💻 We are hiring!

We've recently closed a [$38 million Series B funding round](https://techcrunch.com/2021/03/04/stream-raises-38m-as-its-chat-and-activity-feed-apis-power-communications-for-1b-users/) and we keep actively growing.
Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world.
Expand Down
16 changes: 16 additions & 0 deletions assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions scripts/get_changelog_diff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Here we're trying to parse the latest changes from CHANGELOG.md file.
The changelog looks like this:

## 0.0.3
- Something #3
## 0.0.2
- Something #2
## 0.0.1
- Something #1

In this case we're trying to extract "- Something #3" since that's the latest change.
*/
module.exports = () => {
const fs = require('fs')

changelog = fs.readFileSync('CHANGELOG.md', 'utf8')
releases = changelog.match(/## [?[0-9](.+)/g)

current_release = changelog.indexOf(releases[0])
previous_release = changelog.indexOf(releases[1])

latest_changes = changelog.substr(current_release, previous_release - current_release)

return latest_changes
}
Loading