Skip to content

Commit 153bac6

Browse files
ci: automatically bump version on master (#69)
* build: replace make with poe * test: mark crypto-dependent tests * ci: bump version on master * docs: update for new release process * ci: rename workflow
1 parent 188ce0d commit 153bac6

16 files changed

+296
-300
lines changed

.github/workflows/build.yaml

-51
This file was deleted.

.github/workflows/ci.yaml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
env:
10+
POETRY_VIRTUALENVS_IN_PROJECT: true
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: actions/setup-python@v2
18+
with:
19+
python-version: 3.8
20+
- run: pip install poetry
21+
- name: Set up cache
22+
uses: actions/cache@v2
23+
with:
24+
path: .venv
25+
key: ${{ runner.os }}-venv-py3.8-${{ hashFiles('**/poetry.lock') }}
26+
- name: Install package
27+
run: poetry install
28+
- name: Run linters
29+
run: poetry run poe lint
30+
31+
test:
32+
needs: lint
33+
runs-on: ${{ matrix.os }}
34+
strategy:
35+
matrix:
36+
os: [ubuntu-latest, macos-latest, windows-latest]
37+
python-version: [3.7, 3.8]
38+
steps:
39+
- uses: actions/checkout@v2
40+
- uses: actions/setup-python@v2
41+
with:
42+
python-version: ${{ matrix.python-version }}
43+
- run: pip install poetry
44+
- name: Set up cache
45+
uses: actions/cache@v2
46+
with:
47+
path: .venv
48+
key: ${{ runner.os }}-venv-py${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
49+
- name: Install package
50+
run: poetry install -E crypto
51+
- name: Run tests
52+
run: poetry run poe test
53+
54+
release:
55+
needs: test
56+
runs-on: ubuntu-latest
57+
if: github.ref == 'refs/heads/master'
58+
steps:
59+
- uses: actions/checkout@v2
60+
- name: Bump version
61+
uses: TriPSs/conventional-changelog-action@v3
62+
id: version
63+
with:
64+
github-token: ${{ secrets.GITHUB_TOKEN }}
65+
git-user-name: "GitHub Actions"
66+
git-user-email: "[email protected]"
67+
version-file: pyproject.toml
68+
version-path: tool.poetry.version
69+
preset: conventionalcommits
70+
output-file: false
71+
- name: Set new commit hash
72+
run: echo "::set-env name=SHA::$(git rev-parse HEAD)"
73+
- name: Create release
74+
uses: actions/create-release@v1
75+
if: ${{ steps.version.outputs.skipped == 'false' }}
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
with:
79+
tag_name: ${{ steps.version.outputs.tag }}
80+
release_name: ${{ steps.version.outputs.tag }}
81+
body: ${{ steps.version.outputs.clean_changelog }}
82+
commitish: ${{ env.SHA }}
83+
- name: Publish to PyPI
84+
if: ${{ steps.version.outputs.skipped == 'false' }}
85+
env:
86+
# https://github.com/python-poetry/poetry/issues/2359
87+
POETRY_HTTP_BASIC_PYPI_USERNAME: __token__
88+
POETRY_HTTP_BASIC_PYPI_PASSWORD: ${{ secrets.PYPI_TOKEN }}
89+
run: |
90+
pip install poetry
91+
poetry publish --build --no-interaction

.github/workflows/release.yaml

-30
This file was deleted.

.gitignore

+19-42
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
## Python
2-
1+
### Python ###
32
# Byte-compiled / optimized / DLL files
43
__pycache__/
54
*.py[cod]
@@ -49,8 +48,10 @@ htmlcov/
4948
nosetests.xml
5049
coverage.xml
5150
*.cover
51+
*.py,cover
5252
.hypothesis/
5353
.pytest_cache/
54+
pytestdebug.log
5455

5556
# Translations
5657
*.mo
@@ -60,6 +61,7 @@ coverage.xml
6061
*.log
6162
local_settings.py
6263
db.sqlite3
64+
db.sqlite3-journal
6365

6466
# Flask stuff:
6567
instance/
@@ -70,6 +72,7 @@ instance/
7072

7173
# Sphinx documentation
7274
docs/_build/
75+
doc/_build/
7376

7477
# PyBuilder
7578
target/
@@ -84,15 +87,25 @@ ipython_config.py
8487
# pyenv
8588
.python-version
8689

87-
# celery beat schedule file
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
98+
__pypackages__/
99+
100+
# Celery stuff
88101
celerybeat-schedule
102+
celerybeat.pid
89103

90104
# SageMath parsed files
91105
*.sage.py
92106

93107
# Environments
94108
.env
95-
.envrc
96109
.venv
97110
env/
98111
venv/
@@ -118,41 +131,5 @@ dmypy.json
118131
# Pyre type checker
119132
.pyre/
120133

121-
122-
## MacOS
123-
124-
# General
125-
.DS_Store
126-
.AppleDouble
127-
.LSOverride
128-
129-
# Icon must end with two \r
130-
Icon
131-
132-
133-
# Thumbnails
134-
._*
135-
136-
# Files that might appear in the root of a volume
137-
.DocumentRevisions-V100
138-
.fseventsd
139-
.Spotlight-V100
140-
.TemporaryItems
141-
.Trashes
142-
.VolumeIcon.icns
143-
.com.apple.timemachine.donotpresent
144-
145-
# Directories potentially created on remote AFP share
146-
.AppleDB
147-
.AppleDesktop
148-
Network Trash Folder
149-
Temporary Items
150-
.apdisk
151-
152-
153-
## Dev
154-
155-
.vscode/*
156-
*.csv
157-
*data.py
158-
.sandbox.py
134+
# pytype static type analyzer
135+
.pytype/

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ repos:
1818
types: [python]
1919
- id: mypy
2020
name: mypy
21-
entry: poetry run mypy
21+
entry: poetry run mypy --ignore-missing-imports
2222
language: system
2323
types: [python]

CONTRIBUTING.md

+9-16
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,30 @@ exit
1717

1818
## Tasks
1919

20-
We use `make` as a general task runner. To see available tasks:
20+
We use [poethepoet](https://github.com/nat-n/poethepoet) as a task runner. To see available tasks:
2121

2222
```console
23-
$ make help
24-
clean Remove build artifacts
25-
help Show this help
26-
lint Run all linters and formatters
27-
release Release new version [usage: release v=major|minor|patch]
28-
test Run unit tests
23+
$ poe --help
24+
...
25+
clean Remove build artifacts
26+
lint Run linters and formatters
27+
test Run tests
2928
```
3029

3130
### Code Quality
3231

3332
To ensure code quality, we use the following tools:
3433

3534
- Formatting: [black](https://black.readthedocs.io/en/stable/) and [isort](https://isort.readthedocs.io/en/latest/)
36-
- Linting: [flake8](http://flake8.pycqa.org/en/latest/)
35+
- Linting: [flake8](http://flake8.pycqa.org/en/latest/) and [mypy](https://mypy.readthedocs.io/en/stable/)
3736
- Testing: [pytest](https://docs.pytest.org/en/latest/)
3837

39-
Our [CI pipeline](.github/workflows/build.yaml) will run these tools on each commit. To run these locally, we recommend [pre-commit](https://pre-commit.com/):
38+
Our [CI pipeline](.github/workflows/ci.yaml) will run these tools on each commit. To run these locally, we recommend [pre-commit](https://pre-commit.com/):
4039

4140
```sh
4241
poetry run pre-commit install
4342
```
4443

4544
### Create Release
4645

47-
Creating a new release is simply bumping the version and creating a corresponding git tag. For example, to create a minor release:
48-
49-
```sh
50-
make release v=minor
51-
```
52-
53-
Our [release action](.github/workflows/release.yaml) will then build and publish to PyPI.
46+
On a commit to master, our [CI pipeline](.github/workflows/ci.yaml) will bump the version (determined by [conventional commits](https://www.conventionalcommits.org/)) and publish a new release to PyPI.

Makefile

-23
This file was deleted.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contxt Python SDK
22

3-
[![build status](https://github.com/ndustrialio/contxt-sdk-python/workflows/build/badge.svg)](https://github.com/ndustrialio/contxt-sdk-python/actions)
3+
[![CI](https://github.com/ndustrialio/contxt-sdk-python/workflows/CI/badge.svg)](https://github.com/ndustrialio/contxt-sdk-python/actions?query=workflow%3ACI)
44
[![pypi version](https://img.shields.io/pypi/v/contxt-sdk.svg)](https://pypi.org/project/contxt-sdk/)
55
![python](https://img.shields.io/badge/python-3.7+-blue.svg)
66

contxt/auth/jwt.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from dataclasses import dataclass, field
33
from typing import Any, Dict, List, Union
44

5-
from jwt import PyJWTError, decode, get_unverified_header
6-
from jwt.algorithms import RSAAlgorithm
5+
from jwt import PyJWTError, algorithms, decode, get_unverified_header
76

87
from ..services import AuthService
98
from ..utils import make_logger
@@ -22,7 +21,7 @@ class TokenValidator:
2221
public_key: Union[str, Dict]
2322
algorithms: List[str] = field(default_factory=lambda: ["RS256"])
2423

25-
def _get_public_key(self, token: str):
24+
def _get_public_key(self, token: str) -> str:
2625
if isinstance(self.public_key, dict):
2726
header = get_unverified_header(token)
2827
return self.public_key[header["kid"]]
@@ -54,7 +53,8 @@ def __init__(self, audience: str) -> None:
5453
audience=audience,
5554
issuer=api.base_url,
5655
public_key={
57-
jwk["kid"]: RSAAlgorithm.from_jwk(json.dumps(jwk)) for jwk in api.get_jwks()["keys"]
56+
jwk["kid"]: algorithms.RSAAlgorithm.from_jwk(json.dumps(jwk))
57+
for jwk in api.get_jwks()["keys"]
5858
},
5959
algorithms=["RS256"],
6060
)

0 commit comments

Comments
 (0)