Skip to content

Commit b19d6fb

Browse files
authored
redisgears tox (#20)
1 parent fd97df8 commit b19d6fb

File tree

12 files changed

+404
-56
lines changed

12 files changed

+404
-56
lines changed

.circleci/circle_requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
poetry>=1.1.6
2+
tox>=3.23.1

.circleci/config.yml

Lines changed: 142 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,163 @@
33
# Check https://circleci.com/docs/2.0/language-python/ for more details
44
#
55
version: 2.1
6-
jobs:
7-
build_and_test:
8-
docker:
9-
- image: 'ubuntu:bionic'
6+
commands:
7+
8+
abort_for_docs:
109
steps:
1110
- run:
12-
name: installations
13-
command: apt-get -qq update; apt-get install -y ca-certificates wget build-essential git python-pip
14-
- run:
15-
name: Redis_5_upgrade
16-
command: cd ..; git clone https://github.com/antirez/redis.git; cd ./redis; git fetch; git checkout 6.0.9; make; make install
11+
name: Avoid tests for docs
12+
command: |
13+
if [[ $CIRCLE_BRANCH == *docs ]]; then
14+
echo "Identifies as documents PR, no testing required"
15+
circleci step halt
16+
fi
17+
18+
abort_for_noci:
19+
steps:
1720
- run:
18-
name: download_RedisGears
19-
command: cd ..; wget http://redismodules.s3.amazonaws.com/redisgears/snapshots/redisgears.linux-bionic-x64.master.zip; apt-get install -y unzip; unzip redisgears.linux-bionic-x64.master.zip
21+
name: Ignore CI for specific branches
22+
command: |
23+
if [[ $CIRCLE_BRANCH == *noci ]]; then
24+
echo "Identifies as actively ignoring CI, no testing required."
25+
circleci step halt
26+
fi
27+
28+
29+
early_return_for_forked_pull_requests:
30+
description: >-
31+
If this build is from a fork, stop executing the current job and return success.
32+
This is useful to avoid steps that will fail due to missing credentials.
33+
steps:
2034
- run:
21-
name: download_RedisGears_deps
22-
command: cd ..; wget http://redismodules.s3.amazonaws.com/redisgears/snapshots/redisgears-python.linux-bionic-x64.master.tgz; mkdir -p /var/opt/redislabs/modules/rg/; cd /var/opt/redislabs/modules/rg/; tar -xvf /root/redisgears-python.linux-bionic-x64.master.tgz
35+
name: Early return if this build is from a forked PR
36+
command: |
37+
if [[ -n "$CIRCLE_PR_NUMBER" ]]; then
38+
echo "Nothing to do for forked PRs, so marking this step successful"
39+
circleci step halt
40+
fi
41+
42+
# build_and_test:
43+
# docker:
44+
# - image: 'ubuntu:bionic'
45+
# steps:
46+
# - run:
47+
# name: installations
48+
# command: apt-get -qq update; apt-get install -y ca-certificates wget build-essential git python-pip
49+
# - run:
50+
# name: Redis_5_upgrade
51+
# command: cd ..; git clone https://github.com/antirez/redis.git; cd ./redis; git fetch; git checkout 6.0.9; make; make install
52+
# - run:
53+
# name: download_RedisGears
54+
# command: cd ..; wget http://redismodules.s3.amazonaws.com/redisgears/snapshots/redisgears.linux-bionic-x64.master.zip; apt-get install -y unzip; unzip redisgears.linux-bionic-x64.master.zip
55+
# - run:
56+
# name: download_RedisGears_deps
57+
# command: cd ..; wget http://redismodules.s3.amazonaws.com/redisgears/snapshots/redisgears-python.linux-bionic-x64.master.tgz; mkdir -p /var/opt/redislabs/modules/rg/; cd /var/opt/redislabs/modules/rg/; tar -xvf /root/redisgears-python.linux-bionic-x64.master.tgz
58+
# - checkout
59+
# - run:
60+
# name: install_redisgears_py_to_RedisGears_virtual_env
61+
# command: /var/opt/redislabs/modules/rg/python3_99.99.99/bin/python3 setup.py install
62+
# - run:
63+
# name: install RLTest
64+
# command: /var/opt/redislabs/modules/rg/python3_99.99.99/bin/python3 -m pip install git+https://github.com/Grokzen/redis-py-cluster.git@master git+https://github.com/RedisLabsModules/RLTest.git
65+
# - run:
66+
# name: run_tests
67+
# command: /var/opt/redislabs/modules/rg/python3_99.99.99/bin/python3 -m RLTest --module ../redisgears.so --module-args "Plugin /var/opt/redislabs/modules/rg/plugin/gears_python.so"
68+
69+
#workflows:
70+
# version: 2
71+
# commit:
72+
# jobs:
73+
# - build_and_test
74+
# nightly:
75+
# triggers:
76+
# - schedule:
77+
# cron: "0 0 * * *"
78+
# filters:
79+
# branches:
80+
# only:
81+
# - master
82+
# jobs:
83+
# - build_and_test
84+
85+
build_and_test:
86+
steps:
2387
- checkout
88+
- restore_cache: # Download and cache dependencies
89+
keys:
90+
- v1-dependencies-{{ checksum "pyproject.toml" }}
91+
# fallback to using the latest cache if no exact match is found
92+
- v1-dependencies-
93+
2494
- run:
25-
name: install_redisgears_py_to_RedisGears_virtual_env
26-
command: /var/opt/redislabs/modules/rg/python3_99.99.99/bin/python3 setup.py install
95+
name: install tox dependencies
96+
command: |
97+
/var/opt/redislabs/modules/rg/python3_99.99.99/bin/python3 -m pip install -r .circleci/circle_requirements.txt
98+
2799
- run:
28-
name: install RLTest
29-
command: /var/opt/redislabs/modules/rg/python3_99.99.99/bin/python3 -m pip install git+https://github.com/Grokzen/redis-py-cluster.git@master git+https://github.com/RedisLabsModules/RLTest.git
100+
name: build sdist and wheels
101+
command: |
102+
/var/opt/redislabs/modules/rg/python3_99.99.99/bin/python3 -m poetry build
103+
104+
# - run:
105+
# name: lint
106+
# command: |
107+
# /var/opt/redislabs/modules/rg/python3_99.99.99/bin/python3 -m tox -e linters
108+
#
30109
- run:
31-
name: run_tests
32-
command: /var/opt/redislabs/modules/rg/python3_99.99.99/bin/python3 -m RLTest --module ../redisgears.so --module-args "Plugin /var/opt/redislabs/modules/rg/plugin/gears_python.so"
110+
name: run tests
111+
command:
112+
/var/opt/redislabs/modules/rg/python3_99.99.99/bin/python3 -m tox -e tests
113+
114+
- save_cache:
115+
paths:
116+
- ./.tox
117+
- ~/.cache/pip
118+
key: v1-dependencies-{{ checksum "pyproject.toml" }}
119+
120+
jobs:
121+
build:
122+
docker:
123+
- image: redislabs/redisgears:edge
124+
125+
steps:
126+
- build_and_test
127+
- store_artifacts:
128+
path: test-reports
129+
destination: test-reports
130+
131+
nightly:
132+
docker:
133+
- image: redislabs/redisgears:edge
134+
steps:
135+
- build_and_test
136+
- dockerize
137+
138+
on-any-branch: &on-any-branch
139+
filters:
140+
branches:
141+
only:
142+
- /.*/
143+
tags:
144+
ignore: /.*/
145+
146+
on-master: &on-master
147+
filters:
148+
branches:
149+
only:
150+
- master
33151

34152
workflows:
35153
version: 2
36154
commit:
37155
jobs:
38-
- build_and_test
156+
- build:
157+
<<: *on-any-branch
158+
39159
nightly:
40160
triggers:
41161
- schedule:
42162
cron: "0 0 * * *"
43-
filters:
44-
branches:
45-
only:
46-
- master
163+
<<: *on-master
47164
jobs:
48-
- build_and_test
165+
- build

.github/release-drafter-config.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name-template: 'Version $NEXT_PATCH_VERSION'
2+
tag-template: 'v$NEXT_PATCH_VERSION'
3+
categories:
4+
- title: '🚀Features'
5+
labels:
6+
- 'feature'
7+
- 'enhancement'
8+
- title: 'Bug Fixes'
9+
labels:
10+
- 'fix'
11+
- 'bugfix'
12+
- 'bug'
13+
- title: 'Maintenance'
14+
label: 'chore'
15+
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
16+
exclude-labels:
17+
- 'skip-changelog'
18+
template: |
19+
## Changes
20+
21+
$CHANGES

.github/workflows/check-pypi.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
name: Check if required secrets are set to publish to Pypi
3+
4+
on: push
5+
6+
jobs:
7+
checksecret:
8+
name: check if PYPI_TOKEN and TESTPYPI_TOKEN are set in github secrets
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check PYPI_TOKEN
12+
env:
13+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
14+
run: |
15+
if ${{ env.PYPI_TOKEN == '' }} ; then
16+
echo "PYPI_TOKEN secret is not set"
17+
exit 1
18+
fi
19+
- name: Check TESTPYPI_TOKEN
20+
env:
21+
TESTPYPI_TOKEN: ${{ secrets.TESTPYPI_TOKEN }}
22+
run: |
23+
if ${{ env.TESTPYPI_TOKEN == '' }} ; then
24+
echo "TESTPYPI_TOKEN secret is not set"
25+
exit 1
26+
fi
27+
28+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ master ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ master ]
20+
schedule:
21+
- cron: '19 13 * * 1'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
language: [ 'python' ]
32+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
33+
# Learn more:
34+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v2
39+
40+
# Initializes the CodeQL tools for scanning.
41+
- name: Initialize CodeQL
42+
uses: github/codeql-action/init@v1
43+
with:
44+
languages: ${{ matrix.language }}
45+
# If you wish to specify custom queries, you can do so here or in a config file.
46+
# By default, queries listed here will override any specified in a config file.
47+
# Prefix the list here with "+" to use these queries and those in the config file.
48+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
49+
50+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
51+
# If this step fails, then you should remove it and run the build manually (see below)
52+
- name: Autobuild
53+
uses: github/codeql-action/autobuild@v1
54+
55+
# ℹ️ Command-line programs to run using the OS shell.
56+
# 📚 https://git.io/JvXDl
57+
58+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
59+
# and modify them (or add more) to build your code if your project
60+
# uses a compiled language
61+
62+
#- run: |
63+
# make bootstrap
64+
# make release
65+
66+
- name: Perform CodeQL Analysis
67+
uses: github/codeql-action/analyze@v1

.github/workflows/publish-pypi.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Publish Pypi
2+
on:
3+
release:
4+
types: [ published ]
5+
6+
jobs:
7+
pytest:
8+
name: Publish to PyPi
9+
runs-on: ubuntu-latest
10+
env:
11+
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
12+
steps:
13+
- uses: actions/checkout@master
14+
- name: Set up Python 3.7
15+
uses: actions/setup-python@v1
16+
with:
17+
python-version: 3.7
18+
19+
- name: Install Poetry
20+
uses: dschep/install-poetry-action@v1.3
21+
22+
- name: Cache Poetry virtualenv
23+
uses: actions/cache@v1
24+
id: cache
25+
with:
26+
path: ~/.virtualenvs
27+
key: poetry-${{ hashFiles('**/poetry.lock') }}
28+
restore-keys: |
29+
poetry-${{ hashFiles('**/poetry.lock') }}
30+
31+
- name: Set Poetry config
32+
run: |
33+
poetry config virtualenvs.in-project false
34+
poetry config virtualenvs.path ~/.virtualenvs
35+
36+
- name: Install Dependencies
37+
run: poetry install
38+
if: steps.cache.outputs.cache-hit != 'true'
39+
40+
- name: Publish to PyPI
41+
if: github.event_name == 'release'
42+
run: |
43+
poetry publish -u __token__ -p ${{ secrets.PYPI_TOKEN }} --build
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Release Drafter
2+
3+
on:
4+
push:
5+
# branches to consider in the event; optional, defaults to all
6+
branches:
7+
- master
8+
9+
jobs:
10+
update_release_draft:
11+
runs-on: ubuntu-latest
12+
steps:
13+
# Drafts your next Release notes as Pull Requests are merged into "master"
14+
- uses: release-drafter/release-drafter@v5
15+
with:
16+
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
17+
config-name: release-drafter-config.yml
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![GitHub issues](https://img.shields.io/github/release/RedisGears/redisgears-py.svg)](https://github.com/RedisGears/redisgears-py/releases/latest)
55
[![Codecov](https://codecov.io/gh/RedisGears/redisgears-py/branch/master/graph/badge.svg)](https://codecov.io/gh/RedisGears/redisgears-py)
66
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/RedisGears/redisgears-py.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/RedisGears/redisgears-py/context:python)
7+
[![Known Vulnerabilities](https://snyk.io/test/github/RedisJSON/redisjson-py/badge.svg?targetFile=pyproject.toml)](https://snyk.io/test/github/RedisJSON/redisjson-py?targetFile=pyproject.toml)
78

89
# redisgears-py
910
[![Forum](https://img.shields.io/badge/Forum-RedisGears-blue)](https://forum.redislabs.com/c/modules/redisgears)
@@ -39,3 +40,16 @@ for r in res[0]:
3940
pip install git+https://github.com/RedisGears/redisgears-py.git
4041
```
4142
Notice that the library also need to be installed in RedisGears virtual env.
43+
44+
## Developing
45+
46+
1. Create a virtualenv to manage your python dependencies, and ensure it's active.
47+
```virtualenv -v venv```
48+
2. Install [pypoetry](https://python-poetry.org/) to manage your dependencies.
49+
```pip install poetry```
50+
3. Install dependencies.
51+
```poetry install```
52+
53+
[tox](https://tox.readthedocs.io/en/latest/) runs all tests as its default target. Running *tox* by itself will run unit tests. Ensure you have a running redis, with the module loaded.
54+
55+

0 commit comments

Comments
 (0)