cleanup and add more linting in gitlab ci

This commit is contained in:
HgO 2022-08-13 14:00:40 +02:00
parent beed628a9b
commit fd3067047c
6 changed files with 42 additions and 210 deletions

View file

@ -1,38 +0,0 @@
# This workflow will install Python dependencies, then run various linting programs on a single Python version
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Lint
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U isort==5.6.4 flake8==3.8.4 flake8-comprehensions==3.3.1 black==20.8b1
- name: Check import statement sorting
run: |
isort -c --df matrix_alertbot/ matrix-alertbot tests
- name: Python syntax errors, undefined names, etc.
run: |
flake8 . --count --show-source --statistics
- name: PEP8 formatting
run: |
black --check --diff matrix_alertbot/ matrix-alertbot tests

View file

@ -1,57 +0,0 @@
# This workflow will install Python dependencies, then run unit testing across the earliest and latest supported Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Run unit tests
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
python_36:
# We need to use 20.04 to get access to the libolm3 package
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: 3.6
- name: Install project dependencies
run: |
# Install libolm, required for end-to-end encryption functionality
sudo apt install -y libolm-dev libolm3
# Install python dependencies
python setup.py install
- name: Run unit tests
run: |
python -m unittest
python_39:
# We need to use 20.04 to get access to the libolm3 package
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install project dependencies
run: |
# Install libolm, required for end-to-end encryption functionality
sudo apt install -y libolm-dev libolm3
# Install python dependencies
python setup.py install
- name: Run unit tests
run: |
python -m unittest

2
.gitignore vendored
View file

@ -24,6 +24,8 @@ __pycache__/
*.egg-info/ *.egg-info/
build/ build/
dist/ dist/
.pytest_cache/
.mypy_cache/
# Config file # Config file
config.yaml config.yaml

View file

@ -39,16 +39,47 @@ install:
cache: cache:
policy: pull-push policy: pull-push
interruptible: true interruptible: true
needs: []
linting: isort linting:
extends: .pip cache template extends: .pip cache template
image: python:3.10-alpine image: python:3.10-alpine
stage: quality stage: quality
script: script:
- flake8 . - isort -c --df .
cache: cache:
policy: pull policy: pull
interruptible: true interruptible: true
needs:
- job: install
artifacts: false
flake8 linting:
extends: .pip cache template
image: python:3.10-alpine
stage: quality
script:
- flake8 --count --show-source --statistics .
- black --check --diff .
cache:
policy: pull
interruptible: true
needs:
- job: install
artifacts: false
black linting:
extends: .pip cache template
image: python:3.10-alpine
stage: quality
script:
- black --check --diff .
cache:
policy: pull
interruptible: true
needs:
- job: install
artifacts: false
tests: tests:
extends: .pip cache template extends: .pip cache template
@ -69,3 +100,10 @@ tests:
junit: report.xml junit: report.xml
coverage: '/^TOTAL\s+\d+\s+\d+\s+(\d+\.\d+\%)$/' coverage: '/^TOTAL\s+\d+\s+\d+\s+(\d+\.\d+\%)$/'
interruptible: true interruptible: true
needs:
- job: isort linting
artifacts: false
- job: flake8 linting
artifacts: false
- job: black linting
artifacts: false

View file

@ -1,49 +0,0 @@
#!/bin/bash
# A script to quickly setup a running development environment
#
# It's primary purpose is to set up docker networking correctly so that
# the bot can connect to remote services as well as those hosted on
# the host machine.
#
# Change directory to where this script is located. We'd like to run
# `docker-compose` in the same directory to use the adjacent
# docker-compose.yml and .env files
cd `dirname "$0"`
function on_exit {
cd -
}
# Ensure we change back to the old directory on script exit
trap on_exit EXIT
# To allow the docker container to connect to services running on the host,
# we need to use the host's internal ip address. Attempt to retrieve this.
#
# Check whether the ip address has been defined in the environment already
if [ -z "$HOST_IP_ADDRESS" ]; then
# It's not defined. Try to guess what it is
# First we try the `ip` command, available primarily on Linux
export HOST_IP_ADDRESS="`ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p'`"
if [ $? -ne 0 ]; then
# That didn't work. `ip` isn't available on old Linux systems, or MacOS.
# Try `ifconfig` instead
export HOST_IP_ADDRESS="`ifconfig $(netstat -rn | grep -E "^default|^0.0.0.0" | head -1 | awk '{print $NF}') | grep 'inet ' | awk '{print $2}' | grep -Eo '([0-9]*\.){3}[0-9]*'`"
if [ $? -ne 0 ]; then
# That didn't work either, give up
echo "
Unable to determine host machine's internal IP address.
Please set HOST_IP_ADDRESS environment variable manually and re-run this script.
If you do not have a need to connect to a homeserver running on the host machine,
set HOST_IP_ADDRESS=127.0.0.1"
exit 1
fi
fi
fi
# Build and run latest code
docker-compose up --build local-checkout-dev

View file

@ -1,64 +0,0 @@
#!/bin/bash -e
# Check that regex-rename is installed
if ! command -v regex-rename &> /dev/null
then
echo "regex-rename python module not found. Please run 'python -m pip install regex-rename'"
exit 1
fi
# GNU sed and BSD(Mac) sed handle -i differently :(
function is_gnu_sed(){
sed --version >/dev/null 2>&1
}
# Allow specifying either:
# * One argument, which is the new project name, assuming the old project name is "my project name"
# * Or two arguments, where one can specify 1. the old project name and 2. the new project name
if [ $# -eq 1 ]; then
PLACEHOLDER="my project name"
REPLACEMENT=$1
elif [ $# -eq 2 ]; then
PLACEHOLDER=$1
REPLACEMENT=$2
else
echo "Usage:"
echo "./"$(basename "$0") "\"new name\""
echo "./"$(basename "$0") "\"old name\" \"new name\""
exit 1
fi
PLACEHOLDER_DASHES="${PLACEHOLDER// /-}"
PLACEHOLDER_UNDERSCORES="${PLACEHOLDER// /_}"
REPLACEMENT_DASHES="${REPLACEMENT// /-}"
REPLACEMENT_UNDERSCORES="${REPLACEMENT// /_}"
echo "Updating file and folder names..."
# Iterate over all directories (besides venv's and .git) and rename files/folders
# Yes this looks like some crazy voodoo, but it's necessary as regex-rename does
# not provide any sort of recursive functionality...
find . -type d -not -path "./env*" -not -path "./.git" -not -path "./.git*" \
-exec sh -c "cd {} && \
regex-rename --rename \"(.*)$PLACEHOLDER_DASHES(.*)\" \"\1$REPLACEMENT_DASHES\2\" && \
regex-rename --rename \"(.*)$PLACEHOLDER_UNDERSCORES(.*)\" \"\1$REPLACEMENT_UNDERSCORES\2\"" \; > /dev/null
echo "Updating references within files..."
# Iterate through each file and replace strings within files
for file in $(grep --exclude-dir=env --exclude-dir=venv --exclude-dir=.git --exclude *.pyc -lEw "$PLACEHOLDER_DASHES|$PLACEHOLDER_UNDERSCORES" -R * .[^.]*); do
echo "Checking $file"
if [[ $file != $(basename "$0") ]]; then
if is_gnu_sed; then
sed -i "s/$PLACEHOLDER_DASHES/$REPLACEMENT_DASHES/g" $file
sed -i "s/$PLACEHOLDER_UNDERSCORES/$REPLACEMENT_UNDERSCORES/g" $file
else
sed -i "" "s/$PLACEHOLDER_DASHES/$REPLACEMENT_DASHES/g" $file
sed -i "" "s/$PLACEHOLDER_UNDERSCORES/$REPLACEMENT_UNDERSCORES/g" $file
fi
echo " - $file"
fi
done
echo "Done!"