Skip to content

Commit

Permalink
Merge pull request #107 from SemanticMediaWiki/docker-compose-ci
Browse files Browse the repository at this point in the history
use docker-compose-ci as a git submodule
  • Loading branch information
gesinn-it-evl authored Oct 19, 2023
2 parents 7ec9227 + d2dc851 commit b7c073b
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 239 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Run tests
run: make ci
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "build"]
path = build
url = [email protected]:gesinn-it-pub/docker-compose-ci.git
32 changes: 0 additions & 32 deletions Dockerfile

This file was deleted.

187 changes: 21 additions & 166 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,178 +1,33 @@
-include .env
export

# ======== Naming ========
EXTENSION := SemanticFormsSelect
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.2
PHP_VERSION ?= 7.4
PF_VERSION ?= 5.5.1
DB_TYPE ?= sqlite
DB_IMAGE ?= ""


environment = IMAGE_NAME=$(IMAGE_NAME) \
MW_VERSION=$(MW_VERSION) \
SMW_VERSION=$(SMW_VERSION) \
PHP_VERSION=$(PHP_VERSION) \
PF_VERSION=$(PF_VERSION) \
DB_TYPE=$(DB_TYPE) \
DB_IMAGE=$(DB_IMAGE) \
EXTENSION_FOLDER=$(EXTENSION_FOLDER)
# setup for docker-compose-ci build directory
# delete "build" directory to update docker-compose-ci


ifneq (,$(wildcard ./docker-compose.override.yml))
COMPOSE_OVERRIDE=-f docker-compose.override.yml
ifeq (,$(wildcard ./build/))
$(shell git submodule update --init --remote)
endif

EXTENSION := SemanticFormsSelect

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 npm-test

.PHONY: ci-coverage
ci-coverage: install composer-test-coverage npm-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"

.PHONY: npm-test
npm-test:
$(compose-exec-wiki) bash -c "cd ${EXTENSION_FOLDER} && npm run test"

.PHONY: npm-test-coverage
npm-test-coverage:
$(compose-exec-wiki) bash -c "cd ${EXTENSION_FOLDER} && npm run test-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
# docker images
MW_VERSION?=1.35
PHP_VERSION?=7.4
DB_TYPE?=sqlite
DB_IMAGE?=""

.PHONY: gh-login
gh-login: require-GH_API_TOKEN
gh config set prompt disabled
@echo $(GH_API_TOKEN) | gh auth login --with-token
# extensions
SMW_VERSION?=4.1.2
PF_VERSION?=5.5.1

.PHONY: require-GH_API_TOKEN
require-GH_API_TOKEN:
ifndef GH_API_TOKEN
$(error GH_API_TOKEN is not set)
endif
# composer
# Enables "composer update" inside of extension
COMPOSER_EXT?=true

# nodejs
# Enables node.js related tests and "npm install"
NODE_JS?=true

# ======== 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)"
# check for build dir and git submodule init if it does not exist
include build/Makefile

.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 build
Submodule build added at f60175
4 changes: 0 additions & 4 deletions docker-compose-ci.yml

This file was deleted.

8 changes: 0 additions & 8 deletions docker-compose-dev.yml

This file was deleted.

29 changes: 0 additions & 29 deletions docker-compose.yml

This file was deleted.

0 comments on commit b7c073b

Please sign in to comment.