Skip to content

Commit

Permalink
Introduces basic tests and updates the dependency installation process (
Browse files Browse the repository at this point in the history
#39)

* Create basic tests

* Manage dependencies with poetry

* Update CI for lint

* Update .gitignore

* Drop supports for EOL Python 3.7

* Update lint.sh

* Add options for installing development dependencies in install.sh

* Fix lint

* Update CI for lint

* Use loose comparsion for vermin

* Make sure tmux will run with TERM=screen-256color

* Add docker related files to run the tests

* Create tests.sh

* Create CI for running tests

* Update tests.sh

* Add CI for building

* Update job name
  • Loading branch information
lebr0nli authored May 18, 2024
1 parent 97d98d8 commit fb48256
Show file tree
Hide file tree
Showing 16 changed files with 721 additions and 13 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
__pycache__
.venv
.gdb_history
.DS_Store
.mypy_cache
.ruff_cache
gdbinit-gep
geprc.py
!example/gdbinit-gep
!example/geprc.py
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build and run GEP
on: [push, pull_request]

jobs:
build:
strategy:
fail-fast: false
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Build
run: |
sudo apt-get update && sudo apt-get install -y git gdb python3 python3-pip python3-venv tmux
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install --all
./install.sh
- name: Check GEP is running normally
run: |
gdb --version
export PATH=~/.fzf/bin:$PATH
tmux new-session -d -s check gdb -q
sleep 5
OUTPUT=$(tmux capture-pane -p -t check)
echo $OUTPUT
grep -q "GEP is running" <(echo "$OUTPUT")
! grep -q "Install fzf for better experience with GEP" <(echo "$OUTPUT")
5 changes: 3 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ jobs:
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install dependencies
run: |
python3 -m pip install --user mypy ruff types-gdb prompt_toolkit==3.0.40 vermin
sudo apt-get update && sudo apt-get install -y shellcheck shfmt
curl -sSL https://install.python-poetry.org | python3 -
poetry install --with dev
- name: Run linters
run: |
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Test GEP on different platforms
on: [push, pull_request]

jobs:
tests:
strategy:
fail-fast: false
matrix:
images: [ubuntu22.04] # TODO: Add more targets here

runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4

- name: Docker Build ${{ matrix.images }}
run: docker-compose build ${{ matrix.images }}

- name: Test on ${{ matrix.images }}
run: docker-compose run ${{ matrix.images }} ./tests.sh
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
__pycache__/*
.venv/*
__pycache__
.venv
.gdb_history
.DS_Store
.mypy_cache
.ruff_cache
gdbinit-gep
geprc.py
!example/gdbinit-gep
Expand Down
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ARG image
FROM $image

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -y \
python3 \
python3-pip \
python3-venv \
tmux \
git \
gdb \
curl \
wget \
vim && \
curl -sSL https://install.python-poetry.org | python3 - && \
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && \
~/.fzf/install --all

ENV PATH="/root/.fzf/bin:/root/.local/bin:${PATH}"

COPY . /root/.local/share/GEP

WORKDIR /root/.local/share/GEP

RUN ./install.sh -d && \
poetry install --with dev
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ And also, GEP has some awesome features already, you can directly use it!

## How to install it?

Make sure you have GDB 8.0 or higher compiled with Python3.7+ bindings, then:
Make sure you have GDB 8.0 or higher compiled with Python3.8+ bindings, then:

1. Install git
2. Make sure you have [virtualenv](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#installing-virtualenv) installed
Expand Down
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "3.8"

services:
base: &base-spec
build: .
platform: linux/amd64
security_opt:
- seccomp:unconfined
cap_add:
- SYS_PTRACE

ubuntu22.04:
<<: *base-spec
build:
context: .
dockerfile: Dockerfile
args:
image: ubuntu:22.04

ubuntu20.04:
<<: *base-spec
build:
context: .
dockerfile: Dockerfile
args:
image: ubuntu:20.04
37 changes: 34 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
#!/bin/bash
set -ex

set -o errexit

help_and_exit() {
echo "Usage: $0 [-d|--dev]"
cat << EOF
-d, --dev install development dependencies
EOF
exit 1
}

if [[ $# -gt 1 ]]; then
help_and_exit
fi

DEV=0

while [[ $# -gt 0 ]]; do
case $1 in
-d | --dev)
DEV=1
shift
;;
*)
help_and_exit
;;
esac
done

cd "$(dirname "${BASH_SOURCE[0]}")"
GEP_BASE=$(pwd)
Expand All @@ -18,9 +45,13 @@ VENV_PATH=$GEP_BASE/.venv
echo "Creating virtualenv in path: ${VENV_PATH}"
"$PYTHON" -m venv "$VENV_PATH"
PYTHON=$VENV_PATH/bin/python
echo "Installing prompt_toolkit"
echo "Installing dependencies"
"$PYTHON" -m pip install -U pip
"$VENV_PATH/bin/pip" install --no-cache-dir prompt_toolkit==3.0.40
if [[ $DEV == 1 ]]; then
poetry install --with dev
else
"$VENV_PATH/bin/pip" install --no-cache-dir -e .
fi

# copy example config to GEP_BASE if not exists
echo "Copying default config to $GEP_BASE if not exists"
Expand Down
14 changes: 10 additions & 4 deletions lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -o errexit

help_and_exit() {
echo "Usage: ./lint.sh [-f|--filter]"
echo "Usage: $0 [-f|--filter]"
echo " -f, --filter format code instead of just checking the format"
exit 1
}
Expand All @@ -29,9 +29,15 @@ done

set -o xtrace

LINT_PYTHON_FILES=(
cd "$(dirname "${BASH_SOURCE[0]}")"
GEP_BASE=$(pwd)
# shellcheck disable=SC1091
source "$GEP_BASE/.venv/bin/activate"

VERMIN_TARGETS=(
"gdbinit-gep.py"
"example/geprc.py"
"tests/"
)
LINT_SHELL_FILES=(
"install.sh"
Expand All @@ -46,7 +52,7 @@ else
ruff format --diff
fi

mypy "${LINT_PYTHON_FILES[@]}"
mypy

if [[ $FIX == 1 ]]; then
shfmt -i 4 -bn -ci -sr -w "${LINT_SHELL_FILES[@]}"
Expand All @@ -56,4 +62,4 @@ fi

shellcheck "${LINT_SHELL_FILES[@]}"

vermin -vvv --no-tips -q -t=3.7 --violations "${LINT_PYTHON_FILES[@]}"
vermin -vvv --no-tips -q -t=3.8- --violations "${VERMIN_TARGETS[@]}"
Loading

0 comments on commit fb48256

Please sign in to comment.