From fc28535da07a603694c3792c6586008593a6279d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20=C5=A0pa=C4=8Dek?= <petr.spacek@nic.cz>
Date: Tue, 7 Aug 2018 17:49:16 +0200
Subject: [PATCH] ci: do not re-run tests on master, use nightly instead

All tests are executed before merge and we allow only fast-forward
merges so it is pointless to re-run them again on merge commit.

Code coverage and OBS will be done on auto-synchornized nightly branch.
---
 .gitlab-ci.yml | 63 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 58 insertions(+), 5 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7ea7a68b1..1b9b445f4 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -17,6 +17,8 @@ stages:
 
 build:linux:amd64:
   stage: build
+  except:
+    - master@knot/knot-resolver
   script:
     - rm daemon/lua/kres-gen.lua
     - make -k all CFLAGS="-Werror -ggdb"
@@ -32,6 +34,8 @@ build:linux:amd64:
 
 build:clang:linux:amd64:
   stage: build
+  except:
+    - master@knot/knot-resolver
   image: $CI_REGISTRY/knot/knot-resolver/ci/debian-unstable:knot-2.6  # newer Debian for newer Clang
   script:
     - rm daemon/lua/kres-gen.lua
@@ -46,6 +50,8 @@ build:clang:linux:amd64:
 
 srpm:
   stage: build
+  except:
+    - master@knot/knot-resolver
   allow_failure: true  # don't block testing pipeline in case of failure
   image: $CI_REGISTRY/knot/knot-resolver/ci:fedora-27
   script:
@@ -62,6 +68,8 @@ srpm:
 
 lint:lua:
   stage: test
+  except:
+    - master@knot/knot-resolver
   dependencies: []  # do not download build artifacts
   script:
     - make lint-lua
@@ -70,6 +78,8 @@ lint:lua:
 
 lint:c:
   stage: test
+  except:
+    - master@knot/knot-resolver
   image: $CI_REGISTRY/knot/knot-resolver/ci/debian-unstable:knot-2.6  # newer Debian for newer Clang
   dependencies: []  # do not download build artifacts
   script:
@@ -80,6 +90,8 @@ lint:c:
 lint:clang-scan-build:
   allow_failure: true  # for now it is just informative
   stage: test
+  except:
+    - master@knot/knot-resolver
   image: $CI_REGISTRY/knot/knot-resolver/ci/debian-unstable:knot-2.6  # newer Debian for newer Clang
   dependencies: []  # do not download build artifacts
   script:
@@ -94,6 +106,8 @@ lint:clang-scan-build:
 
 test:linux:amd64:
   stage: test
+  except:
+    - master@knot/knot-resolver
   script:
     # recompile everything otherwise lcov will bark because Git files will be "newer" than gcda files
     # this is caused by interaction between Git approach to timestamps and Gitlab artifacts
@@ -113,6 +127,8 @@ test:linux:amd64:
 
 installcheck:linux:amd64:
   stage: test
+  except:
+    - master@knot/knot-resolver
   script:
     # recompile everything otherwise lcov will bark because Git files will be "newer" than gcda files
     # this is caused by interaction between Git approach to timestamps and Gitlab artifacts
@@ -132,6 +148,8 @@ installcheck:linux:amd64:
 
 doc:
   stage: test
+  except:
+    - master@knot/knot-resolver
   script:
     - SPHINXFLAGS="-W" make doc
   dependencies: []
@@ -144,6 +162,8 @@ doc:
 
 deckard:linux:amd64:
   stage: test
+  except:
+    - master@knot/knot-resolver
   variables:
     TMPDIR: $CI_PROJECT_DIR
   except:
@@ -167,6 +187,8 @@ deckard:linux:amd64:
 
 installcheck:valgrind:linux:amd64:
   stage: test
+  except:
+    - master@knot/knot-resolver
   script:
     - DEBUGGER="valgrind --leak-check=full --trace-children=yes --quiet --suppressions=/lj.supp" make -k installcheck
   dependencies:
@@ -197,6 +219,8 @@ installcheck:valgrind:linux:amd64:
 
 test:linux:amd64:valgrind:
   stage: test
+  except:
+    - master@knot/knot-resolver
   variables:
     TMPDIR: $CI_PROJECT_DIR
   script:
@@ -214,7 +238,7 @@ test:linux:amd64:valgrind:
   only:
     - branches@knot/knot-resolver  # do not trigger job for forks
   except:
-    - master
+    - master@knot/knot-resolver
   script:
     - export TESTDIR="/var/tmp/respdiff-jobs/$(git rev-parse --short HEAD)-gitlab/$RESPDIFF_TEST"
     - >
@@ -287,6 +311,8 @@ respdiff:fwd-udp6-unbound.tls6:
 
 respdiff:iter:udp:linux:amd64:
   stage: test
+  except:
+    - master@knot/knot-resolver
   script:
     - source <(./scripts/coverage_env.sh "$(pwd)" "$(pwd)/coverage.stats/respdiff" "iter/udp" --export)
     - ulimit -n "$(ulimit -Hn)" # applies only for kresd ATM
@@ -315,6 +341,8 @@ respdiff:iter:udp:linux:amd64:
 
 respdiff:iter:tcp:linux:amd64:
   stage: test
+  except:
+    - master@knot/knot-resolver
   script:
     - source <(./scripts/coverage_env.sh "$(pwd)" "$(pwd)/coverage.stats/respdiff" "iter/tcp" --export)
     - ./ci/respdiff/start-resolvers.sh
@@ -343,6 +371,8 @@ respdiff:iter:tcp:linux:amd64:
 
 respdiff:iter:tls:linux:amd64:
   stage: test
+  except:
+    - master@knot/knot-resolver
   script:
     - source <(./scripts/coverage_env.sh "$(pwd)" "$(pwd)/coverage.stats/respdiff" "iter/tls" --export)
     - ./ci/respdiff/start-resolvers.sh
@@ -370,6 +400,8 @@ respdiff:iter:tls:linux:amd64:
 
 distro:fedora-27:
   stage: test
+  except:
+    - master@knot/knot-resolver
   image: $CI_REGISTRY/knot/knot-resolver/ci:fedora-27
   only:
     - branches@knot/knot-resolver  # do not trigger job for forks (no privileged runners)
@@ -389,6 +421,8 @@ distro:fedora-27:
 
 distro:epel-7:
   stage: test
+  except:
+    - master@knot/knot-resolver
   image: $CI_REGISTRY/knot/knot-resolver/ci:fedora-27
   only:
     - branches@knot/knot-resolver  # do not trigger job for forks (no privileged runners)
@@ -409,6 +443,8 @@ distro:epel-7:
 # compute coverage for runs with COVERAGE=1
 coverage:
   stage: coverage
+  except:
+    - master@knot/knot-resolver
   only:
     variables:
       - $COVERAGE == "1"
@@ -436,10 +472,10 @@ coverage:
 pages:
   stage: deploy
   only:
-   refs:
-    - master@knot/knot-resolver
-   variables:
-     - $COVERAGE == "1"
+    refs:
+      - nightly@knot/knot-resolver
+    variables:
+      - $COVERAGE == "1"
   dependencies:
     - coverage
   script:
@@ -462,6 +498,23 @@ obs:devel:
     - scripts/build-in-obs.sh knot-dns-devel  # build against latest development version of knot
     - scripts/build-in-obs.sh knot-resolver-devel  # build against knot in knot-resolver-latest
 
+# copy snapshot of current master to nightly branch for further processing
+# (this is workaround for missing complex conditions for job limits in Gitlab)
+nightly:copy:
+  stage: deploy
+  only:
+    variables:
+      - $CREATE_NIGHTLY == "1"
+    refs:
+      - master@knot/knot-resolver
+  dependencies: []
+  script:
+    # delete nightly branch
+    - 'curl --request DELETE --header "PRIVATE-TOKEN: $GITLAB_API_TOKEN" "https://gitlab.labs.nic.cz/api/v4/projects/147/repository/branches/nightly"'
+    # recreate nightly branch from current master
+    - 'curl --request POST --header "PRIVATE-TOKEN: $GITLAB_API_TOKEN" "https://gitlab.labs.nic.cz/api/v4/projects/147/repository/branches?branch=nightly&ref=master"'
+
+
 #arm_build:
 #  image: cznic/armhf-ubuntu:16.04
 #  stage: build
-- 
GitLab