diff options
author | Marc Lagrange <dashie@sigpipe.me> | 2019-08-05 18:06:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-05 18:06:29 +0200 |
commit | f48978cf5ecb7b3f6e1c200b3990df6db393afac (patch) | |
tree | 8c640765bede05419329c4d846080b842fd4b4da | |
parent | 08b19e359825bd34e45d6aabd085a03c5bdbc76a (diff) |
Switch CI to CircleCI (#90)
* Add CircleCI test config
-rw-r--r-- | .circleci/config.yml | 173 | ||||
-rw-r--r-- | .coveragerc | 1 | ||||
-rw-r--r-- | .drone.yml | 2 | ||||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | config.py.sample | 2 | ||||
-rw-r--r-- | pyproject.toml | 1 | ||||
-rw-r--r-- | setup.cfg | 3 | ||||
-rw-r--r-- | tests/config_test.py | 2 | ||||
-rwxr-xr-x | tests/install_audiowaveform.sh | 36 |
10 files changed, 210 insertions, 13 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..77442c95 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,173 @@ +# Python CircleCI 2.0 configuration file +# Check https://circleci.com/docs/2.0/language-python/ for more details +version: 2 + +aliases: + - &defaults + docker: + - image: circleci/python:3.6-buster-node + working_directory: ~/projects/reel2bits + + - &attach_workspace + attach_workspace: + at: ~/projects/ + + - &persist_to_workspace + persist_to_workspace: + root: ~/projects/ + paths: + - ./reel2bits/ + - ./audiowaveform/ + + - &install_steps + steps: + - checkout + - *attach_workspace + # TODO: npm/node/front v2 + - *persist_to_workspace + + - &install_system_dependencies + run: + name: Install system dependencies + command: | + sudo apt-get update + sudo apt-get install -y sox libtag1v5 libmagic1 libffi6 ffmpeg postgresql-client-11 + sudo apt-get install -y cmake build-essential git wget make libboost-all-dev + sudo apt-get install -y libsox-dev libsox-fmt-all libtag1-dev libmagic-dev libffi-dev libgd-dev libmad0-dev libsndfile1-dev libid3tag0-dev + + - &install_audiowaveform + run: + name: Install audiowaveform + command: ./tests/install_audiowaveform.sh + + - &install_python_dependencies + steps: + - *attach_workspace + - *install_system_dependencies + - *install_audiowaveform + - run: python -V | tee /tmp/.python-version + - restore_cache: + keys: + - v1-dependencies-{{ checksum "/tmp/.python-version" }}-{{ checksum "requirements.txt" }} + - v1-dependencies-{{ checksum "/tmp/.python-version" }}- + - v1-dependencies- + - run: python3 -m venv venv + - run: + command: | + . venv/bin/activate + pip install --requirement requirements.txt + pip install black + pip install flake8 + - save_cache: + key: v1-dependencies-{{ checksum "/tmp/.python-version" }}-{{ checksum "requirements.txt" }} + paths: + - ./venv + - *persist_to_workspace + + - &test_steps + steps: + - *attach_workspace + - *install_system_dependencies + - *install_audiowaveform + - run: + name: Linters + command: | + . venv/bin/activate + black --check . + flake8 . --count --show-source --statistics + - run: + name: Tests + command: | + . venv/bin/activate + cp tests/config_test.py config.py + mkdir test-reports + python setup.py test + - run: + name: Full migrations + command: | + psql -U postgres -h localhost -w -c 'CREATE DATABASE reel2bits' + psql -U postgres -h localhost -w -c 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";' reel2bits + . venv/bin/activate + cp config.py.sample config.py + flask db upgrade + - store_test_results: + path: test-reports + - store_artifacts: + path: test-reports + +jobs: + install: + <<: *defaults + <<: *install_steps + + install-python3.6: + <<: *defaults + <<: *install_python_dependencies + + install-python3.7: + <<: *defaults + docker: + - image: circleci/python:3.7-buster-node + <<: *install_python_dependencies + + install-python3.8: + <<: *defaults + docker: + - image: circleci/python:3.8-rc-buster-node + <<: *install_python_dependencies + + test-python3.6: + <<: *defaults + docker: + - image: circleci/python:3.6-buster-node + - image: circleci/postgres:11-alpine + environment: + POSTGRES_USER: postgres + POSTGRES_DB: reel2bits_test + <<: *test_steps + + test-python3.7: + <<: *defaults + docker: + - image: circleci/python:3.7-buster-node + - image: circleci/postgres:11-alpine + environment: + POSTGRES_USER: postgres + POSTGRES_DB: reel2bits_test + <<: *test_steps + + test-python3.8: + <<: *defaults + docker: + - image: circleci/python:3.8-rc-buster-node + - image: circleci/postgres:11-alpine + environment: + POSTGRES_USER: postgres + POSTGRES_DB: reel2bits_test + <<: *test_steps + +workflows: + version: 2 + build-and-test: + jobs: + - install + - install-python3.6: + requires: + - install + - install-python3.7: + requires: + - install + - install-python3.6 + - install-python3.8: + requires: + - install + - install-python3.6 + - test-python3.6: + requires: + - install-python3.6 + - test-python3.7: + requires: + - install-python3.7 + - test-python3.8: + requires: + - install-python3.8 diff --git a/.coveragerc b/.coveragerc index 1e5b9ed8..dfb9d6e6 100644 --- a/.coveragerc +++ b/.coveragerc @@ -5,3 +5,4 @@ omit = config.py configtest.py **/*__init__.py + venv/* @@ -34,7 +34,7 @@ steps: - python setup.py install - ./tests/install_audiowaveform.sh - black --check . - - flake8 . + - flake8 . --count --show-source --statistics - cp tests/config_test.py config.py - python setup.py test @@ -14,3 +14,4 @@ .coverage /.ropeproject /.mypy_cache +/test-reports @@ -5,7 +5,7 @@ </h1> <p align="center"> - <a href="https://drone.sigpipe.me/dashie/reel2bits"><img src="https://drone.sigpipe.me/api/badges/dashie/reel2bits/status.svg" alt="Build Status"/></a> + <a href="https://circleci.com/gh/rhaamo/reel2bits"><img src="https://circleci.com/gh/rhaamo/reel2bits.svg?style=svg" alt="Build Status"/></a> <a href="https://dev.sigpipe.me/dashie/reel2bits/src/branch/master/LICENSE"><img src="https://img.shields.io/badge/license-AGPL3-green.svg"/></a> <img src="https://img.shields.io/badge/python-%3E%3D3.6-blue.svg"/> <a href="https://github.com/ambv/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code Style: black" /></a> diff --git a/config.py.sample b/config.py.sample index 2b81b621..3ff9b1a3 100644 --- a/config.py.sample +++ b/config.py.sample @@ -28,7 +28,7 @@ AP_ENABLED = False # Activate federation at your own risks SQLALCHEMY_DATABASE_URI = \ - 'postgresql+psycopg2://postgres@database/reel2bits' + 'postgresql+psycopg2://postgres@localhost/reel2bits' # Should users confirm theire email address ? SECURITY_CONFIRMABLE = True diff --git a/pyproject.toml b/pyproject.toml index 4a74cfd6..eae17d0f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,7 @@ exclude = ''' | \.eggs | \.idea | \__pycache__ + | venv )/ ''' skip-numeric-underscore-normalization = true @@ -2,9 +2,10 @@ test=pytest [tool:pytest] -addopts = --verbose --cov=. +addopts = --verbose --cov=. --cov-report=xml:test-reports/coverage.xml --junitxml=test-reports/junit.xml python_files = tests/*.py [flake8] max-line-length = 120 ignore = E501 +exclude = .svn,CVS,.bzr,.hg,.git,__pycache__,.tox,venv,.eggs diff --git a/tests/config_test.py b/tests/config_test.py index 008ce0ce..9474e650 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -5,7 +5,7 @@ TESTING = True WTF_CSRF_ENABLED = False SECRET_KEY = "udf298euf02uf2f02f2uf0" -SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://postgres@database:5432/reel2bits_test" +SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://postgres@localhost:5432/reel2bits_test" # SQLALCHEMY_DATABASE_URI = 'sqlite:///ahrl.db' # SQLALCHEMY_DATABASE_URI = 'mysql://dashie:saucisse@localhost/ahrl' SQLALCHEMY_ECHO = False diff --git a/tests/install_audiowaveform.sh b/tests/install_audiowaveform.sh index 87c6baae..96c3a092 100755 --- a/tests/install_audiowaveform.sh +++ b/tests/install_audiowaveform.sh @@ -1,7 +1,29 @@ -#!/bin/sh +#!/bin/bash # Quick and dirty AudioWaveform build with cache logic for speedup +if [ -z "$DRONE_RUNNER_PLATFORM" ]; then + # CircleCI + RUNNER="$(uname -s)" + BINPATH=/home/circleci/projects/audiowaveform/${RUNNER}/audiowaveform + CACHEPATH=~/projects + CI="CircleCI" + SUDO="sudo" +else + # Drone + RUNNER=$DRONE_RUNNER_PLATFORM + BINPATH="${PWD}/.cache/audiowaveform/${RUNNER}/audiowaveform" + CACHEPATH=~/.cache + CI="DroneCI" +fi + +echo "-- debug start" +echo "-- CI detected: ${CI}" +echo "-- runner: ${RUNNER}" +echo "-- ls cachepath (${CACHEPATH}): $(ls -la ${CACHEPATH})" +echo "-- file: $(file ${BINPATH})" +echo "-- debug end" + # Build function build() { echo "-- build audiowaveform; building AudioWaveform..." @@ -15,17 +37,15 @@ build() { cd build cmake .. make - mkdir -pv /usr/local/bin - cp -fv audiowaveform /usr/local/bin/audiowaveform + ${SUDO} mkdir -pv /usr/local/bin + ${SUDO} cp -fv audiowaveform /usr/local/bin/audiowaveform } -BINPATH="${PWD}/.cache/audiowaveform/${DRONE_RUNNER_PLATFORM}/audiowaveform" - # Cache logic : test if we have an executable already built, and working -if [[ -d .cache ]]; then +if [[ -d $CACHEPATH ]]; then echo "-- build audiowaveform; cache available" # We have a cache dir, create struct - mkdir -pv ".cache/audiowaveform/${DRONE_RUNNER_PLATFORM}" + mkdir -pv "${CACHEPATH}/audiowaveform/${RUNNER}" # Check if a binary exists if [[ -x ${BINPATH} ]]; then @@ -34,7 +54,7 @@ if [[ -d .cache ]]; then if ${BINPATH} --help|grep "AudioWaveform v"; then echo "-- build audiowaveform; and can run; copying it" # can run - cp -fv ${BINPATH} /usr/local/bin/audiowaveform + ${SUDO} cp -fv ${BINPATH} /usr/local/bin/audiowaveform else # can't run build |