Skip to content

Commit

Permalink
Merge pull request #61 from SemanticMediaWiki/docker-compose-ci
Browse files Browse the repository at this point in the history
docker-compose based CI
  • Loading branch information
gesinn-it-gea authored Oct 3, 2023
2 parents c1d484c + dc98e87 commit 20092b8
Show file tree
Hide file tree
Showing 10 changed files with 359 additions and 0 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:

test:

runs-on: ubuntu-20.04
continue-on-error: ${{ matrix.experimental }}

strategy:
matrix:
include:
- mediawiki_version: '1.35'
smw_version: '4.1.0'
php_version: 7.4
database_type: mysql
database_image: "mysql:5.7"
coverage: true
experimental: false
- mediawiki_version: '1.35'
smw_version: '4.1.2'
php_version: 7.4
database_type: sqlite
database_image: "mysql:5.7"
coverage: true
experimental: false
- mediawiki_version: '1.35'
smw_version: dev-master
php_version: 7.4
database_type: mysql
database_image: "mysql:5.7"
coverage: false
experimental: false
- mediawiki_version: '1.39'
smw_version: dev-master
php_version: 8.1
database_type: mysql
database_image: "mysql:5.7"
coverage: false
experimental: true
- mediawiki_version: '1.39'
smw_version: dev-master
php_version: 8.1
database_type: mysql
database_image: "mysql:8"
coverage: false
experimental: true
- mediawiki_version: '1.40'
smw_version: dev-master
php_version: 8.1
database_type: mysql
database_image: "mysql:8"
coverage: false
experimental: true
- mediawiki_version: '1.40'
smw_version: dev-master
php_version: 8.1
database_type: mysql
database_image: "mariadb:latest"
coverage: false
experimental: true
- mediawiki_version: '1.40'
smw_version: dev-master
php_version: 8.1
database_type: postgres
database_image: "postgres:14"
coverage: false
experimental: true

env:
MW_VERSION: ${{ matrix.mediawiki_version }}
SMW_VERSION: ${{ matrix.smw_version }}
PHP_VERSION: ${{ matrix.php_version }}
DB_TYPE: ${{ matrix.database_type }}
DB_IMAGE: ${{ matrix.database_image }}


steps:
- name: Checkout
uses: actions/checkout@v4

- name: Run tests
run: make ci
if: matrix.coverage == false

- name: Run tests with coverage
run: make ci-coverage
if: matrix.coverage == true

- name: Upload code coverage
uses: codecov/codecov-action@v3
with:
files: coverage/php/coverage.xml
if: matrix.coverage == true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*~
*.kate-swp
.*.swp
coverage
.env
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"workbench.colorCustomizations": {
"activityBar.background": "#173325",
"titleBar.activeBackground": "#204833",
"titleBar.activeForeground": "#F8FCFA"
}
}
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ARG MW_VERSION
ARG PHP_VERSION
FROM gesinn/mediawiki-ci:${MW_VERSION}-php${PHP_VERSION}

ARG MW_VERSION
ARG SMW_VERSION
ARG PHP_VERSION

# get needed dependencies for this extension
RUN sed -i s/80/8080/g /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf

RUN COMPOSER=composer.local.json composer require --no-update mediawiki/semantic-media-wiki ${SMW_VERSION}
RUN composer update


RUN chown -R www-data:www-data /var/www/html/extensions/SemanticMediaWiki/

ENV EXTENSION=SemanticCompoundQueries
COPY composer*.json package*.json /var/www/html/extensions/$EXTENSION/

RUN cd extensions/$EXTENSION && composer update

COPY . /var/www/html/extensions/$EXTENSION

RUN echo \
"wfLoadExtension( 'SemanticMediaWiki' );\n" \
"enableSemantics( 'localhost' );\n" \
"wfLoadExtension( '$EXTENSION' );\n" \
>> __setup_extension__
168 changes: 168 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
-include .env
export

# ======== Naming ========
EXTENSION := SemanticCompoundQueries
EXTENSION_FOLDER := /var/www/html/extensions/$(EXTENSION)
extension := $(shell echo $(EXTENSION) | tr A-Z a-z})
IMAGE_NAME := $(extension):test-$(MW_VERSION)-$(SMW_VERSION)-$(PS_VERSION)-$(AL_VERSION)-$(MAPS_VERSION)-$(SRF_VERSION)


# ======== CI ENV Variables ========
MW_VERSION ?= 1.35
SMW_VERSION ?= 4.1.0
PHP_VERSION ?= 7.4
DB_TYPE ?= sqlite
DB_IMAGE ?= ""


environment = IMAGE_NAME=$(IMAGE_NAME) \
MW_VERSION=$(MW_VERSION) \
SMW_VERSION=$(SMW_VERSION) \
PHP_VERSION=$(PHP_VERSION) \
DB_TYPE=$(DB_TYPE) \
DB_IMAGE=$(DB_IMAGE) \
EXTENSION_FOLDER=$(EXTENSION_FOLDER)


ifneq (,$(wildcard ./docker-compose.override.yml))
COMPOSE_OVERRIDE=-f docker-compose.override.yml
endif


compose = $(environment) docker-compose $(COMPOSE_OVERRIDE) $(COMPOSE_ARGS)
compose-ci = $(environment) docker-compose -f docker-compose.yml -f docker-compose-ci.yml $(COMPOSE_OVERRIDE) $(COMPOSE_ARGS)
compose-dev = $(environment) docker-compose -f docker-compose.yml -f docker-compose-dev.yml $(COMPOSE_OVERRIDE) $(COMPOSE_ARGS)

compose-run = $(compose) run -T --rm
compose-exec-wiki = $(compose) exec -T wiki

show-current-target = @echo; echo "======= $@ ========"

# ======== CI ========
# ======== Global Targets ========

.PHONY: ci
ci: install composer-test

.PHONY: ci-coverage
ci-coverage: install composer-test-coverage

.PHONY: install
install: destroy up .install

.PHONY: up
up: .init .build .up

.PHONY: down
down: .init .down

.PHONY: destroy
destroy: .init .destroy

.PHONY: bash
bash: up .bash

# ======== General Docker-Compose Helper Targets ========

.PHONY: .build
.build:
$(show-current-target)
$(compose-ci) build wiki
.PHONY: .up
.up:
$(show-current-target)
$(compose-ci) up -d

.PHONY: .install
.install: .wait-for-db
$(show-current-target)
$(compose-exec-wiki) bash -c "sudo -u www-data \
php maintenance/install.php \
--pass=wiki4everyone --server=http://localhost:8080 --scriptpath='' \
--dbname=wiki --dbuser=wiki --dbpass=wiki $(WIKI_DB_CONFIG) wiki WikiSysop && \
cat __setup_extension__ >> LocalSettings.php && \
sudo -u www-data php maintenance/update.php --skip-external-dependencies --quick \
"

.PHONY: .down
.down:
$(show-current-target)
$(compose-ci) down

.PHONY: .destroy
.destroy:
$(show-current-target)
$(compose-ci) down -v

.PHONY: .bash
.bash: .init
$(show-current-target)
$(compose-exec-wiki) bash -c "cd $(EXTENSION_FOLDER) && bash"

# ======== Test Targets ========

.PHONY: composer-test
composer-test:
$(show-current-target)
$(compose-exec-wiki) bash -c "cd $(EXTENSION_FOLDER) && composer phpunit"

.PHONY: composer-test-coverage
composer-test-coverage:
$(show-current-target)
$(compose-exec-wiki) bash -c "cd $(EXTENSION_FOLDER) && composer phpunit-coverage"

# ======== Dev Targets ========

.PHONY: dev-bash
dev-bash: .init
$(compose-dev) run -it wiki bash -c 'service apache2 start && bash'

.PHONY: run
run:
$(compose-dev) -f docker-compose-dev.yml run -it wiki

# ======== Releasing ========
VERSION = `node -e 'console.log(require("./extension.json").version)'`

.PHONY: release
release: ci git-push gh-login
gh release create $(VERSION)

.PHONY: git-push
git-push:
git diff --quiet || (echo 'git directory has changes'; exit 1)
git push

.PHONY: gh-login
gh-login: require-GH_API_TOKEN
gh config set prompt disabled
@echo $(GH_API_TOKEN) | gh auth login --with-token

.PHONY: require-GH_API_TOKEN
require-GH_API_TOKEN:
ifndef GH_API_TOKEN
$(error GH_API_TOKEN is not set)
endif


# ======== Helpers ========
.PHONY: .init
.init:
$(show-current-target)
$(eval COMPOSE_ARGS = --project-name ${extension}-$(DB_TYPE) --profile $(DB_TYPE))
ifeq ($(DB_TYPE), sqlite)
$(eval WIKI_DB_CONFIG = --dbtype=$(DB_TYPE) --dbpath=/tmp/sqlite)
else
$(eval WIKI_DB_CONFIG = --dbtype=$(DB_TYPE) --dbserver=$(DB_TYPE) --installdbuser=root --installdbpass=database)
endif
@echo "COMPOSE_ARGS: $(COMPOSE_ARGS)"

.PHONY: .wait-for-db
.wait-for-db:
$(show-current-target)
ifeq ($(DB_TYPE), mysql)
$(compose-run) wait-for $(DB_TYPE):3306 -t 120
else ifeq ($(DB_TYPE), postgres)
$(compose-run) wait-for $(DB_TYPE):5432 -t 120
endif
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
},
"scripts": {
"phpunit": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist",
"phpunit-coverage": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --testdox --coverage-text --coverage-html coverage/php --coverage-clover coverage/php/coverage.xml",
"unit": [
"composer dump-autoload",
"php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --testsuite=semantic-compound-queries-unit"
Expand Down
4 changes: 4 additions & 0 deletions docker-compose-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
wiki:
volumes:
- ./coverage:${EXTENSION_FOLDER}/coverage
8 changes: 8 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
wiki:
volumes:
- ./:${EXTENSION_FOLDER}
- ${EXTENSION_FOLDER}/vendor/
ports:
- 8080:8080

29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
services:
wiki:
build:
context: .
args:
MW_VERSION: ${MW_VERSION}
SMW_VERSION: ${SMW_VERSION}
PHP_VERSION: ${PHP_VERSION}
image: ${IMAGE_NAME}

mysql:
image: ${DB_IMAGE:-mysql:5}
environment:
- MYSQL_ROOT_PASSWORD=database
profiles:
- mysql

postgres:
image: ${DB_IMAGE:-postgres:15}
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=database
profiles:
- postgres

wait-for:
image: mintel/docker-wait-for-it
profiles:
- no-up
10 changes: 10 additions & 0 deletions env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# copy this to .env to easily modify local CI ENV variables

# cp env.template .env

MW_VERSION=1.35
SMW_VERSION=4.1.0

PHP_VERSION=7.4
DB_TYPE=mysql
DB_IMAGE="mysql:5.7"

0 comments on commit 20092b8

Please sign in to comment.