From 9f425564ed1998eccff7e9648cd193607b6e82f4 Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Mon, 15 Oct 2018 14:58:40 +0200 Subject: [PATCH 1/3] Gitlab-CI --- .gitlab-ci.yml | 21 +++++++++++++++++++++ Makefile | 17 +++++++++-------- build/docker/bin/Makefile | 2 +- 3 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..9446c843 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,21 @@ +stages: + - build + - test + +build:binary: + stage: build + tags: + - blockbook + script: make build + +test:unittest: + stage: test + tags: + - blockbook + script: make test + +test:integration: + stage: test + tags: + - blockbook + script: make test-integration ARGS="-run='TestIntegration/(bcash|bgold|bitcoin|dash|dogecoin|litecoin|vertcoin|zcash)/'" diff --git a/Makefile b/Makefile index 2709d73b..37ab8062 100644 --- a/Makefile +++ b/Makefile @@ -39,17 +39,20 @@ $(addprefix all-, $(TARGETS)): all-%: clean-deb build-images deb-% all: clean-deb build-images $(addprefix deb-, $(TARGETS)) -build-images: - rm -f .bin-image .deb-image +build-images: clean-images $(MAKE) .bin-image .deb-image .bin-image: - docker build --no-cache=$(NO_CACHE) -t $(BIN_IMAGE) build/docker/bin - @ docker images -q $(BIN_IMAGE) > $@ + @if [ -z "$(shell docker images --quiet --filter=reference=$(BIN_IMAGE):latest)" ]; then \ + echo "Building image $(BIN_IMAGE)..."; \ + docker build --no-cache=$(NO_CACHE) -t $(BIN_IMAGE) build/docker/bin; \ + fi .deb-image: .bin-image - docker build --no-cache=$(NO_CACHE) -t $(DEB_IMAGE) build/docker/deb - @ docker images -q $(DEB_IMAGE) > $@ + @if [ -z "$(shell docker images --quiet --filter=reference=$(DEB_IMAGE):latest)" ]; then \ + echo "Building image $(DEB_IMAGE)..."; \ + docker build --no-cache=$(NO_CACHE) -t $(DEB_IMAGE) build/docker/deb; \ + fi clean: clean-bin clean-deb @@ -66,8 +69,6 @@ clean-images: clean-bin-image clean-deb-image clean-bin-image: - docker rmi $(BIN_IMAGE) - @ rm -f .bin-image clean-deb-image: - docker rmi $(DEB_IMAGE) - @ rm -f .deb-image diff --git a/build/docker/bin/Makefile b/build/docker/bin/Makefile index dbe44e16..6a446a31 100644 --- a/build/docker/bin/Makefile +++ b/build/docker/bin/Makefile @@ -34,7 +34,7 @@ test-all: prepare-sources generate-data prepare-sources: @ [ -n "`ls /src 2> /dev/null`" ] || (echo "/src doesn't exist or is empty" 1>&2 && exit 1) - [ -d $(BLOCKBOOK_SRC) ] && rm -rf $(BLOCKBOOK_SRC) + rm -rf $(BLOCKBOOK_SRC) cp -r /src $(BLOCKBOOK_SRC) $(MAKE) prepare-vendor From acae88fcdccdef9f6ad591a81ca56b272248fbe4 Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Tue, 16 Oct 2018 12:24:38 +0200 Subject: [PATCH 2/3] Changed test names in order to filter mainnet/testnet targets --- .gitlab-ci.yml | 8 ++++---- tests/integration.go | 12 +++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9446c843..fe2b77c3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,20 +2,20 @@ stages: - build - test -build:binary: +build: stage: build tags: - blockbook script: make build -test:unittest: +unit-test: stage: test tags: - blockbook script: make test -test:integration: +integration-test: stage: test tags: - blockbook - script: make test-integration ARGS="-run='TestIntegration/(bcash|bgold|bitcoin|dash|dogecoin|litecoin|vertcoin|zcash)/'" + script: make test-integration ARGS="-run='TestIntegration/(bcash|bgold|bitcoin|dash|dogecoin|litecoin|vertcoin|zcash)=main/'" diff --git a/tests/integration.go b/tests/integration.go index e0483472..56a73ddb 100644 --- a/tests/integration.go +++ b/tests/integration.go @@ -17,6 +17,7 @@ import ( "path/filepath" "reflect" "sort" + "strings" "testing" "github.com/jakm/btcutil/chaincfg" @@ -45,7 +46,8 @@ func runIntegrationTests(t *testing.T) { for _, coin := range keys { cfg := tests[coin] - t.Run(coin, func(t *testing.T) { runTests(t, coin, cfg) }) + name := getMatchableName(coin) + t.Run(name, func(t *testing.T) { runTests(t, coin, cfg) }) } } @@ -60,6 +62,14 @@ func loadTests(path string) (map[string]map[string]json.RawMessage, error) { return v, err } +func getMatchableName(coin string) string { + if idx := strings.Index(coin, "_testnet"); idx != -1 { + return coin[:idx] + "=test" + } else { + return coin + "=main" + } +} + func runTests(t *testing.T, coin string, cfg map[string]json.RawMessage) { if cfg == nil || len(cfg) == 0 { t.Skip("No tests to run") From 423d4721c07b10deda760201ab04f9dafe8e005f Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Tue, 16 Oct 2018 12:55:57 +0200 Subject: [PATCH 3/3] Restrict CI jobs by branch/schedule --- .gitlab-ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fe2b77c3..9cefeef3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,18 +4,24 @@ stages: build: stage: build + only: + - master tags: - blockbook script: make build unit-test: stage: test + only: + - master tags: - blockbook script: make test integration-test: stage: test + only: + - schedules tags: - blockbook script: make test-integration ARGS="-run='TestIntegration/(bcash|bgold|bitcoin|dash|dogecoin|litecoin|vertcoin|zcash)=main/'"