Skip to content
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

Redis.io website examples #2763

Closed
wants to merge 9 commits into from
Closed
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
42 changes: 42 additions & 0 deletions .github/workflows/doctests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Documentation Tests

on:
push:
pull_request:

workflow_dispatch:

permissions:
contents: read

jobs:
doctests:
runs-on: ubuntu-latest
services:
redis-stack:
image: redis/redis-stack-server:latest
options: >-
--health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
ports:
- 6379:6379
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.9
cache: 'pip'
- run: |
sudo apt update
sudo apt install -y redis-tools
- name: lint check
run: |
pip install -r dev_requirements.txt
pip install -r requirements.txt
isort --check-only --diff doctests/*.py
black -l 80 --target-version py39 --check --diff doctests/*.py

- name: run tests
run: |
python setup.py build
python setup.py install
sh doctests/run_examples.sh
31 changes: 31 additions & 0 deletions doctests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Command examples for redis.io

## How to add an example

Create regular python file in the current folder with meaningful name. It makes sense prefix example files with
command category (e.g. string, set, list, hash, etc) to make navigation in the folder easier. Files ending in *.py*
are automatically run by the test suite.

### Special markup

See https://github.com/redis-stack/redis-stack-website#readme for more details.

## How to test examples

Examples are standalone python scripts, committed to the *doctests* directory. These scripts assume that the
```requirements.txt``` and ```dev_requirements.txt``` from this repository have been installed, as per below.

```bash
pip install requirements.txt
pip install dev_requirements.txt
```

Note - the CI process, runs the basic ```black``` and ```isort``` linters against the examples. Assuming
the requirements above have been installed you can run ```black yourfile.py``` and ```isort yourfile.py```
locally to validate the linting, prior to CI.

Just include necessary assertions in the example file and run
```bash
sh doctests/run_examples.sh
```
to test all examples in the current folder.
15 changes: 15 additions & 0 deletions doctests/run_examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh


basepath=`readlink -f $1`
if [ $? -ne 0 ]; then
basepath=`readlink -f $(dirname $0)`
fi
echo "No path specified, using ${basepath}"

set -e
cd ${basepath}
for i in `ls ${basepath}/*.py`; do
redis-cli flushdb
python $i
done
Loading