From 6dc34f4f76181a94aa9b3f9f5088e5cae18588bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Mon, 11 Feb 2019 22:05:28 +0100 Subject: [PATCH] added circle ci MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Bauer --- .circleci/config.yml | 67 +++++++++++++++++++++++++++++++++ .circleci/docker-image-build.sh | 35 +++++++++++++++++ .circleci/install.sh | 43 +++++++++++++++++++++ .circleci/lint-scripts.sh | 18 +++++++++ 4 files changed, 163 insertions(+) create mode 100644 .circleci/config.yml create mode 100755 .circleci/docker-image-build.sh create mode 100755 .circleci/install.sh create mode 100755 .circleci/lint-scripts.sh diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 000000000..dc6a6623e --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,67 @@ +version: 2.1 +jobs: + lint-scripts: + docker: + - image: koalaman/shellcheck-alpine + steps: + - checkout + - run: + name: lint-scripts + command: .circleci/lint-scripts.sh + + install-mysql: + docker: + - image: circleci/ruby:2.4.4 + - image: circleci/mysql:5.7-ram + command: --max_allowed_packet=64MB + environment: + MYSQL_DATABASE: zammad_test + MYSQL_USER: zammad_test + MYSQL_PASSWORD: zammad_test + environment: + RAILS_ENV: test + steps: + - checkout + - run: + name: install-mysql + command: .circleci/install.sh + + install-postgresql: + docker: + - image: circleci/ruby:2.4.4 + - image: circleci/postgres:11-ram + environment: + POSTGRES_DB: zammad_test + POSTGRES_USER: zammad_test + POSTGRES_PASSWORD: zammad_test + environment: + RAILS_ENV: test + steps: + - checkout + - run: + name: install-postgresql + command: .circleci/install.sh + + docker-image-build: + machine: true + steps: + - checkout + - run: + name: docker-image-build + command: .circleci/docker-image-build.sh + +workflows: + version: 2 + install_unittest_dockerbuild: + jobs: + - lint-scripts + - install-mysql: + requires: + - lint-scripts + - install-postgresql: + requires: + - lint-scripts + - docker-image-build: + requires: + - install-mysql + - install-postgresql diff --git a/.circleci/docker-image-build.sh b/.circleci/docker-image-build.sh new file mode 100755 index 000000000..b744ad6ff --- /dev/null +++ b/.circleci/docker-image-build.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# +# build zammads docker & docker-compose images + +set -o errexit +set -o pipefail + +REPO_ROOT="$(git rev-parse --show-toplevel)" +REPO_USER="zammad" +ZAMMAD_VERSION="$(git describe --tags | sed -e 's/-[a-z0-9]\{8,\}.*//g')" +export ZAMMAD_VERSION + +if [ "${CIRCLE_BRANCH}" == 'develop' ]; then + DOCKER_REPOSITORY="zammad-docker" + BUILD_SCRIPT="scripts/build_image.sh" +elif [ "${CIRCLE_BRANCH}" == 'stable' ]; then + DOCKER_REPOSITORY="zammad-docker-compose" + BUILD_SCRIPT="hooks/build.sh" +else + echo "branch is ${CIRCLE_BRANCH}... no docker image build needed..." + exit 0 +fi + +# dockerhub auth +echo "${DOCKER_PASSWORD}" | docker login --username="${DOCKER_USERNAME}" --password-stdin + +# clone docker repo +git clone https://github.com/"${REPO_USER}"/"${DOCKER_REPOSITORY}" + +# enter dockerfile dir +cd "${REPO_ROOT}/${DOCKER_REPOSITORY}" + +# build & push docker image +# shellcheck disable=SC1090 +source "${REPO_ROOT}/${DOCKER_REPOSITORY}/${BUILD_SCRIPT}" diff --git a/.circleci/install.sh b/.circleci/install.sh new file mode 100755 index 000000000..c32d96dc7 --- /dev/null +++ b/.circleci/install.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# +# install & unit test zammad +# + +exit 0 + +set -o errexit +set -o pipefail + +DB_CONFIG="test:\n adapter: postgresql\n database: zammad_test\n host: 127.0.0.1\n pool: 50\n timeout: 5000\n encoding: utf8\n username: zammad_test\n password: zammad_test" + +# install build dependencies +sudo apt-get update +sudo apt-get install -y --no-install-recommends autoconf automake autotools-dev bison build-essential curl git-core libffi-dev libgdbm-dev libgmp-dev libmariadbclient-dev-compat libncurses5-dev libreadline-dev libsqlite3-dev libssl-dev libtool libxml2-dev libxslt1-dev libyaml-0-2 libyaml-dev patch pkg-config postfix sqlite3 zlib1g-dev + +if [ "${CIRCLE_JOB}" == "install-mysql" ]; then + DB_ADAPTER="mysql2" + INSTALL_OPTION="postgres" +elif [ "${CIRCLE_JOB}" == "install-postgresql" ]; then + DB_ADAPTER="postgresql" + INSTALL_OPTION="mysql" +else + echo "nothing to do for circle ci job ${CIRCLE_JOB}..." + exit 0 +fi + +# create db config +echo -e "${DB_CONFIG}" | sed "s/adapter: postgresql/adapter: ${DB_ADAPTER}/g" > config/database.yml + +# install zammad +bundle install --without "${INSTALL_OPTION}" + +# unit tests +bundle exec rubocop +rake db:migrate +rake db:seed +bundle exec rspec -t ~type:system +bundle exec rake db:environment:set RAILS_ENV=test +rake db:reset +rake test:units +ruby -I test/ test/integration/object_manager_test.rb +ruby -I test/ test/integration/package_test.rb diff --git a/.circleci/lint-scripts.sh b/.circleci/lint-scripts.sh new file mode 100755 index 000000000..da44ac63e --- /dev/null +++ b/.circleci/lint-scripts.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# +# lint bash scripts +# + +set -o errexit + +CONFIG_DIR="./.circleci" +TMP_FILE="$(mktemp)" + +find "${CONFIG_DIR}" -type f -name "*.sh" > "${TMP_FILE}" + +while read -r FILE; do + echo lint "${FILE}" + shellcheck -x "${FILE}" +done < "${TMP_FILE}" + +rm "${TMP_FILE}"