This commit is contained in:
Karel.Picman 2021-12-10 13:52:56 +01:00
parent 64745d5819
commit 5dcd4c7423
9 changed files with 262 additions and 155 deletions

71
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,71 @@
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov
# Copyright © 2019-21 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
image: docker:stable
before_script:
- docker info
stages:
- custom_workflows
mariadb:
stage: custom_workflows
tags:
- docker
script:
# Create an image
- docker build -t custom_workflows_image -f Dockerfile .
# Run the container, optionally run some tests/apps in it
- docker rm -f custom_workflows_container 2>/dev/null || true
- docker run --name custom_workflows_container custom_workflows_image bash ./test/ci/ci.sh mariadb
# Remove the container
- docker rm custom_workflows_container
# Remove image
- docker rmi custom_workflows_image
postgres:
stage: custom_workflows
tags:
- docker
script:
# Create an image
- docker build -t custom_workflows_image -f Dockerfile .
# Run the container, optionally run some tests/apps in it
- docker rm -f custom_workflows_container 2>/dev/null || true
- docker run --name custom_workflows_container custom_workflows_image bash ./test/ci/ci.sh postgres
# Remove the container
- docker rm custom_workflows_container
# Remove image
- docker rmi custom_workflows_image
sqlite3:
stage: custom_workflows
tags:
- docker
script:
# Create an image
- docker build -t custom_workflows_image -f Dockerfile .
# Run the container, optionally run some tests/apps in it
- docker rm -f custom_workflows_container 2>/dev/null || true
- docker run --name custom_workflows_container custom_workflows_image bash ./test/ci/ci.sh sqlite3
# Remove the container
- docker rm custom_workflows_container
# Remove image
- docker rmi custom_workflows_image

View File

@ -1,5 +1,3 @@
# encoding: utf-8
#
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov
@ -18,46 +16,11 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The Docker file definition for GitLab Continous Integration
language: ruby
sudo: true
dist: xenial
rvm:
- 2.5
before_install:
- mysql -e 'CREATE DATABASE IF NOT EXISTS test CHARACTER SET utf8mb4;'
- psql -c 'create database test;' -U postgres
- export WORKSPACE=`pwd`/workspace
- export PATH_TO_CUSTOM_WORKFLOWS=`pwd`
- export PATH_TO_REDMINE=$WORKSPACE/redmine
- export BUNDLE_GEMFILE=$PATH_TO_REDMINE/Gemfile
- mkdir -p ${WORKSPACE}
- cp -f ./test/ci/${DB}.yml ${WORKSPACE}/database.yml
- bash -x ./test/ci/redmine_install.sh -c
- bash -x ./test/ci/redmine_install.sh -i
install:
script:
- bash -x ./test/ci/redmine_install.sh -t
after_script:
- bash -x ./test/ci/redmine_install.sh -u
env:
- DB=sqlite
- DB=mysql
- DB=postgres
cache: bundler
services:
- mysql
- postgresql
addons:
mariadb: '10.3'
FROM debian:latest
RUN apt-get update
RUN apt-get -qq install mariadb-server postgresql sqlite3 libsqlite3-dev ruby ruby-dev build-essential libmariadb-dev libpq-dev subversion git
COPY . /app
WORKDIR /app

109
test/ci/ci.sh Normal file
View File

@ -0,0 +1,109 @@
#!/bin/bash
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov
# Copyright © 2019-21 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The script for GitLab Continuous Integration
# Exit if any command fails
set -e
# Display the first argument (DB engine)
echo $1
# Variables
REDMINE_REPO=http://svn.redmine.org/redmine/branches/4.2-stable/
REDMINE_PATH=/opt/redmine
# Init
rm -rf "${REDMINE_PATH}"
# Clone Redmine
svn export "${REDMINE_REPO}" "${REDMINE_PATH}"
# Add the plugin
ln -s /app "${REDMINE_PATH}"/plugins/redmine_custom_workflows
# Prepare the database
cp "./test/ci/$1.yml" "${REDMINE_PATH}/config/database.yml"
case $1 in
mariadb)
/etc/init.d/$1 start
mariadb -e "CREATE DATABASE IF NOT EXISTS test CHARACTER SET utf8mb4"
mariadb -e "CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'redmine'";
mariadb -e "GRANT ALL PRIVILEGES ON test.* TO 'redmine'@'localhost'";
;;
postgres)
/etc/init.d/$1ql start
su -c "psql -c \"CREATE ROLE redmine LOGIN ENCRYPTED PASSWORD 'redmine' NOINHERIT VALID UNTIL 'infinity';\"" postgres
su -c "psql -c \"CREATE DATABASE test WITH ENCODING='UTF8' OWNER=redmine;\"" postgres
su -c "psql -c \"ALTER USER redmine CREATEDB;\"" postgres
;;
sqlite3)
;;
*)
echo 'Missing argument'
exit 1
;;
esac
# Install Redmine
cd "${REDMINE_PATH}"
gem install bundler
RAILS_ENV=test bundle config set --local without 'development'
RAILS_ENV=test bundle install
RAILS_ENV=test bundle exec rake generate_secret_token
RAILS_ENV=test bundle exec rake db:migrate
RAILS_ENV=test bundle exec rake redmine:plugins:migrate
RAILS_ENV=test REDMINE_LANG=en bundle exec rake redmine:load_default_data
# Run Redmine tests
#RAILS_ENV=test bundle exec rake test
# Run Custom Workflows' tests
bundle exec rake redmine:plugins:test:units NAME=redmine_custom_workflows RAILS_ENV=test
bundle exec rake redmine:plugins:test:functionals NAME=redmine_custom_workflows RAILS_ENV=test
bundle exec rake redmine:plugins:test:integration NAME=redmine_custom_workflows RAILS_ENV=test
# Clean up database from the plugin changes
bundle exec rake redmine:plugins:migrate NAME=redmine_custom_workflows VERSION=0 RAILS_ENV=test
case $1 in
mariadb)
/etc/init.d/$1 stop
;;
postgres)
/etc/init.d/$1ql stop
;;
sqlite3)
;;
*)
echo 'Missing argument'
exit 1
;;
esac
echo "$1 Okay"

28
test/ci/mariadb.yml Normal file
View File

@ -0,0 +1,28 @@
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov
# Copyright © 2019-21 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# MariDb file definition for GitLab Continous Integration
test:
adapter: mysql2
database: test
username: redmine
password: "redmine"
encoding: utf8mb4
collation: utf8mb4_unicode_ci

View File

@ -1,7 +0,0 @@
test:
adapter: mysql2
database: test
username: root
encoding: utf8mb4
collation: utf8mb4_unicode_ci

View File

@ -1,5 +1,27 @@
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov
# Copyright © 2019-21 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# PosgreSQL file definition for GitLab Continous Integration
test:
adapter: postgresql
database: test
encoding: utf8
username: redmine
password: redmine
host: localhost

View File

@ -1,98 +0,0 @@
#!/bin/bash
# encoding: utf-8
#
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov
# Copyright © 2019-21 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
export REDMINE_GIT_REPO=git://github.com/redmine/redmine.git
export REDMINE_GIT_TAG=4.1-stable
clone()
{
# Exit if the cloning fails
set -e
rm -rf ${PATH_TO_REDMINE}
git clone -b ${REDMINE_GIT_TAG} --depth=100 --quiet ${REDMINE_GIT_REPO} ${PATH_TO_REDMINE}
}
test()
{
# Exit if a test fails
set -e
cd ${PATH_TO_REDMINE}
# Run tests within application
bundle exec rake redmine:plugins:test:units NAME=redmine_custom_workflows RAILS_ENV=test
bundle exec rake redmine:plugins:test:functionals NAME=redmine_custom_workflows RAILS_ENV=test
}
uninstall()
{
# Exit if the migration fails
set -e
cd ${PATH_TO_REDMINE}
# clean up database
bundle exec rake redmine:plugins:migrate NAME=redmine_custom_workflows VERSION=0 RAILS_ENV=test
}
install()
{
# Exit if the installation fails
set -e
# cd to redmine folder
cd ${PATH_TO_REDMINE}
echo current directory is `pwd`
# Create a link to the Custom Workflows plugin
ln -sf ${PATH_TO_CUSTOM_WORKFLOWS} plugins/redmine_custom_workflows
# Copy database.yml
cp ${WORKSPACE}/database.yml config/
# Install gems
# Not ideal, but at present Travis-CI will not install with xapian enabled:
bundle install --without rmagick development RAILS_ENV=test
# Run Redmine database migrations
bundle exec rake db:migrate --trace RAILS_ENV=test
# Load Redmine database default data
bundle exec rake redmine:load_default_data REDMINE_LANG=en RAILS_ENV=test
# generate session store/secret token
bundle exec rake generate_secret_token RAILS_ENV=test
# Run the plugin database migrations
bundle exec rake redmine:plugins:migrate RAILS_ENV=test
}
while getopts :ictu opt
do case "$opt" in
c) clone; exit 0;;
i) install; exit 0;;
t) test; exit 0;;
u) uninstall; exit 0;;
[?]) echo "i: install; c: clone redmine; t: run tests; u: uninstall";;
esac
done

View File

@ -1,5 +0,0 @@
test:
adapter: sqlite3
database: db/test.sqlite3
timeout: 500

24
test/ci/sqlite3.yml Normal file
View File

@ -0,0 +1,24 @@
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov
# Copyright © 2019-21 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# SQLite file definition for GitLab Continous Integration
test:
adapter: sqlite3
database: db/redmine.sqlite3