Skip to content

Commit 140cd90

Browse files
committed
chore(maintenance): general maintencance and ci flow
1 parent c65a9a9 commit 140cd90

File tree

12 files changed

+250
-84
lines changed

12 files changed

+250
-84
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,39 @@ on:
55
- 'main'
66
pull_request:
77

8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.head_ref }}
10+
cancel-in-progress: true
11+
812
jobs:
913
build:
14+
name: 🧪 Test & lint
1015
runs-on: ubuntu-latest
1116
strategy:
1217
matrix:
13-
python: [3.6, 3.7, 3.8, 3.9]
18+
python: ["3.7", "3.8", "3.9", "3.10"]
1419
steps:
15-
- uses: actions/checkout@v2
16-
- uses: actions/setup-python@v2
20+
- uses: actions/checkout@v3
21+
fetch-depth: 0 # gives the commit linter access to previous commits
22+
23+
- name: Commit message linter
24+
if: ${{ matrix.python == '3.7' }}
25+
uses: wagoid/commitlint-github-action@v4
26+
27+
- uses: actions/setup-python@v3
1728
with:
1829
python-version: ${{ matrix.python }}
1930

20-
- name: Add pip bin to PATH
21-
run: |
22-
echo "/home/runner/.local/bin" >> $GITHUB_PATH
23-
2431
- name: Install deps with ${{ matrix.python }}
2532
run: pip install ".[test, ci]"
2633

2734
- name: Lint with ${{ matrix.python }}
28-
if: ${{ matrix.python == '3.8' }}
35+
if: ${{ matrix.python == '3.7' }}
2936
run: make lint
3037

3138
- name: Install, test and code coverage with ${{ matrix.python }}
3239
env:
3340
STREAM_KEY: ${{ secrets.STREAM_KEY }}
3441
STREAM_SECRET: ${{ secrets.STREAM_SECRET }}
35-
run: |
36-
python setup.py install
37-
make test
42+
PYTHONPATH: ${{ github.workspace }}
43+
run: make test
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Create release PR
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "The new version number with 'v' prefix. Example: v1.40.1"
8+
required: true
9+
10+
jobs:
11+
init_release:
12+
name: 🚀 Create release PR
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0 # gives the changelog generator access to all previous commits
18+
19+
- name: Update CHANGELOG.md, __pkg__.py and push release branch
20+
env:
21+
VERSION: ${{ github.event.inputs.version }}
22+
run: |
23+
npx --yes standard-version@9.3.2 --release-as "$VERSION" --skip.tag --skip.commit --tag-prefix=v
24+
git config --global user.name 'github-actions'
25+
git config --global user.email 'release@getstream.io'
26+
git checkout -q -b "release-$VERSION"
27+
git commit -am "chore(release): $VERSION"
28+
git push -q -u origin "release-$VERSION"
29+
30+
- name: Get changelog diff
31+
uses: actions/github-script@v5
32+
with:
33+
script: |
34+
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
35+
core.exportVariable('CHANGELOG', get_change_log_diff())
36+
37+
- name: Open pull request
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
run: |
41+
gh pr create \
42+
-t "Release ${{ github.event.inputs.version }}" \
43+
-b "# :rocket: ${{ github.event.inputs.version }}
44+
Make sure to use squash & merge when merging!
45+
Once this is merged, another job will kick off automatically and publish the package.
46+
# :memo: Changelog
47+
${{ env.CHANGELOG }}"

.github/workflows/release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Release
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- main
8+
9+
jobs:
10+
Release:
11+
name: 🚀 Release
12+
if: github.event.pull_request.merged && startsWith(github.head_ref, 'release-')
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
19+
- uses: actions/github-script@v5
20+
with:
21+
script: |
22+
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
23+
core.exportVariable('CHANGELOG', get_change_log_diff())
24+
25+
// Getting the release version from the PR source branch
26+
// Source branch looks like this: release-1.0.0
27+
const version = context.payload.pull_request.head.ref.split('-')[1]
28+
core.exportVariable('VERSION', version)
29+
30+
- uses: actions/setup-python@v3
31+
with:
32+
python-version: "3.10"
33+
34+
- name: Publish to PyPi
35+
env:
36+
TWINE_USERNAME: "__token__"
37+
TWINE_PASSWORD: "${{ secrets.PYPI_TOKEN }}"
38+
run: |
39+
pip install -q twine==3.7.1 wheel==0.37.1
40+
python setup.py sdist bdist_wheel
41+
twine upload --non-interactive dist/*
42+
43+
- name: Create release on GitHub
44+
uses: ncipollo/release-action@v1
45+
with:
46+
body: ${{ env.CHANGELOG }}
47+
tag: ${{ env.VERSION }}
48+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/reviewdog.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: reviewdog
2+
on:
3+
pull_request:
4+
5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.head_ref }}
7+
cancel-in-progress: true
8+
9+
jobs:
10+
reviewdog:
11+
name: 🐶 Reviewdog
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- uses: reviewdog/action-setup@v1
17+
with:
18+
reviewdog_version: latest
19+
20+
- uses: actions/setup-python@v3
21+
with:
22+
python-version: "3.10"
23+
24+
- name: Install deps
25+
run: pip install ".[ci]"
26+
27+
- name: Reviewdog
28+
env:
29+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
run: make reviewdog

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ coverage.xml
5353
# Sphinx documentation
5454
docs/_build/
5555

56+
57+
.python-version
5658
secrets.*sh
5759
.idea
5860
.vscode/

.versionrc.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const pkgUpdater = {
2+
VERSION_REGEX: /__version__ = "(.+)"/,
3+
4+
readVersion: function (contents) {
5+
const version = this.VERSION_REGEX.exec(contents)[1];
6+
return version;
7+
},
8+
9+
writeVersion: function (contents, version) {
10+
return contents.replace(this.VERSION_REGEX.exec(contents)[0], `__version__ = "${version}"`);
11+
}
12+
}
13+
14+
module.exports = {
15+
bumpFiles: [{ filename: './stream/__init__.py', updater: pkgUpdater }],
16+
}

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ lint-fix:
1717
black stream
1818

1919
test: ## Run tests
20-
STREAM_KEY=$(STREAM_KEY) STREAM_SECRET=$(STREAM_SECRET) python setup.py test
20+
STREAM_KEY=$(STREAM_KEY) STREAM_SECRET=$(STREAM_SECRET) pytest stream/tests
2121

2222
check: lint test ## Run linters + tests
23+
24+
reviewdog:
25+
black --check --diff --quiet stream | reviewdog -f=diff -f.diff.strip=0 -filter-mode="diff_context" -name=black -reporter=github-pr-review
26+
flake8 --ignore=E501,W503 stream | reviewdog -f=flake8 -name=flake8 -reporter=github-pr-review

README.md

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
1-
stream-python
2-
=============
1+
# Official Python SDK for [Stream Feeds](https://getstream.io/activity-feeds/)
32

43
[![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)
54

6-
[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.
5+
<p align="center">
6+
<img src="./assets/logo.svg" width="50%" height="50%">
7+
</p>
8+
<p align="center">
9+
Official Python API client for Stream Feeds, a web service for building scalable newsfeeds and activity streams.
10+
<br />
11+
<a href="https://getstream.io/activity-feeds/docs/?language=python"><strong>Explore the docs »</strong></a>
12+
<br />
13+
<br />
14+
<a href="https://github.com/GetStream/stream-django">Django Code Sample</a>
15+
·
16+
<a href="https://github.com/GetStream/stream-python/issues">Report Bug</a>
17+
·
18+
<a href="https://github.com/GetStream/stream-python/issues">Request Feature</a>
19+
</p>
720

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

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

12-
### Installation
25+
You can use this library to access feeds API endpoints server-side.
26+
27+
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/)).
28+
29+
## ⚙️ Installation
1330

14-
#### Install from Pypi
1531

1632
```bash
17-
pip install stream-python
33+
$ pip install stream-python
1834
```
1935

20-
### Full documentation
36+
## 📚 Full documentation
2137

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

24-
### Usage
40+
## ✨ Getting started
2541

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

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

152-
### Contributing
153-
154-
First, make sure you can run the test suite. Tests are run via py.test
155-
156-
```bash
157-
py.test
158-
# with coverage
159-
py.test --cov stream --cov-report html
160-
# against a local API backend
161-
LOCAL=true py.test
162-
```
163-
164-
Install black and flake8
165-
166-
```
167-
pip install .[ci]
168-
```
169-
170-
Install git hooks to avoid pushing invalid code (git commit will run `black` and `flake8`)
171-
172-
### Releasing a new version
173-
174-
In order to release new version you need to be a maintainer on Pypi.
175-
176-
- Update CHANGELOG
177-
- Update the version on setup.py
178-
- Commit and push to Github
179-
- Create a new tag for the version (eg. `v2.9.0`)
180-
- Create a new dist with python `python setup.py sdist`
181-
- Upload the new distributable with twine `twine upload dist/stream-python-VERSION-NAME.tar.gz`
182-
183-
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`
184-
185-
### Copyright and License Information
168+
## ✍️ Contributing
186169

187-
Project is licensed under the [BSD 3-Clause](LICENSE).
170+
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.
188171

189-
## We are hiring!
172+
## 🧑‍💻 We are hiring!
190173

191174
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.
192175
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.

assets/logo.svg

Lines changed: 16 additions & 0 deletions
Loading

scripts/get_changelog_diff.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Here we're trying to parse the latest changes from CHANGELOG.md file.
3+
The changelog looks like this:
4+
5+
## 0.0.3
6+
- Something #3
7+
## 0.0.2
8+
- Something #2
9+
## 0.0.1
10+
- Something #1
11+
12+
In this case we're trying to extract "- Something #3" since that's the latest change.
13+
*/
14+
module.exports = () => {
15+
const fs = require('fs')
16+
17+
changelog = fs.readFileSync('CHANGELOG.md', 'utf8')
18+
releases = changelog.match(/## [?[0-9](.+)/g)
19+
20+
current_release = changelog.indexOf(releases[0])
21+
previous_release = changelog.indexOf(releases[1])
22+
23+
latest_changes = changelog.substr(current_release, previous_release - current_release)
24+
25+
return latest_changes
26+
}

0 commit comments

Comments
 (0)