# HG changeset patch
# User Georges Racinet <georges.racinet@octobus.net>
# Date 1602858605 -7200
#      Fri Oct 16 16:30:05 2020 +0200
# Node ID 37d21a0e709cc18ccce6ddd846c0b1ad72381134
# Parent  a5ce02f263d7a6f24624d5fe75ef2a6ed2d38cf0
Heptapod CI: using the new base CI images

This raises the question of homegeneity of branch naming conventions
between py-heptapod and HGitaly (see long comment, with reference to
heptapod#352)

There was also a glitch while installing py-heptapod. The solution
adopted is a path of least resistance.

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,63 +2,57 @@
   - main
   - compat
 
-install:
+variables:
+  # has to be "stable" in the stable branch, and actually we should rename
+  # "latest" as "default": this would let us just use $CI_COMMIT_HG_BRANCH
+  BASE_IMAGES_TAG: latest
+  BASE_IMAGES_COLLECTION: registry.heptapod.net:443/heptapod/ci-images/mercurial
+
+check-sdist:
   stage: compat
   image: octobus/ci-hgitaly:variable-hg
-  before_script: []
+  needs: []
   script:
+    - rm -rf dist
+    - python3 setup.py sdist
     # most requirements will be preinstalled in the base image (taken from the
     # default branch of HGitaly at time of image build), but they will be
     # reexamined and any change will be tested.
-    - pip3 install .
+    - pip3 install dist/*.tar.gz
 
-variables:
-  EVOLVE_REPO_URL: https://mirror.octobus.net/evolve
-  EVOLVE_LOCAL_REPO: /ci/repos/evolve
-  PY_HEPTAPOD_LOCAL_REPO: /ci/repos/py-heptapod
-
-before_script:
-  - hg clone https://foss.heptapod.net/heptapod/py-heptapod $PY_HEPTAPOD_LOCAL_REPO
-  - pip3 install --user --upgrade -e $PY_HEPTAPOD_LOCAL_REPO
+.tests:
+  script:
+    # The hgitaly project currently only has one branch: default, and we'll
+    # have a stable branch only after Heptapod 0.17.0 release.
+    # At this point, the simplest will be to have the same branch conventions
+    # in py-heptapod and HGitaly (already implemented below).
+    # So either both have a `heptapod-0-17` branch
+    # or we decide that the new versioning rules (see heptapod#352) allow us to
+    # simply have a `stable` branch in both.
+    # TODO switch to clone/update, but a first attempt cloning in ./py-heptapod
+    # led to shadowing problems and bad applied hg config. Using archives is not
+    # *that* inefficient
+    - pip3 install https://foss.heptapod.net/heptapod/py-heptapod/-/archive/branch/${CI_COMMIT_HG_BRANCH}/py-heptapod-branch-${CI_COMMIT_HG_BRANCH}.tar.bz2
+    # cleanup of previous failed attempt, can be removed after a few weeks
+    - rm -rf py-heptapod
+    - pip3 freeze
+    - flake8 --exclude stub hgitaly hgext3rd
+    - ./run-all-tests
 
 tests-current:
+  extends:
+    - .tests
   stage: main
-  image: octobus/ci-hgitaly
-  script:
-    - pip3 freeze
-    - flake8 --exclude stub hgitaly hgext3rd
-    - PYTHONPATH=/ci/repos/mercurial ./run-all-tests
-
+  image: ${BASE_IMAGES_COLLECTION}/hg-current:${BASE_IMAGES_TAG}
 
 tests-hg-stable:
+  extends:
+    - .tests
   stage: compat
-  image: octobus/ci-hgitaly:variable-hg
-  script:
-    - hg pull -R /ci/repos/mercurial/ --rev stable
-    - hg -R /ci/repos/mercurial/ update stable
-    - hg -R /ci/repos/mercurial summary
-    - (cd /ci/repos/mercurial; make local PYTHON=python3)
-    - hg clone -r stable -u stable $EVOLVE_REPO_URL $EVOLVE_LOCAL_REPO
-    - pip3 install --user $EVOLVE_LOCAL_REPO
-    - pip3 freeze
-    - /ci/repos/mercurial/hg version --debug
-    - PYTHONPATH=/ci/repos/mercurial python3 -c "from mercurial import util; print(util.version())"
-    - PYTHONPATH=/ci/repos/mercurial PATH=$HOME/.local/bin:$PATH
-         ./run-all-tests
+  image: ${BASE_IMAGES_COLLECTION}/hg-stable:${BASE_IMAGES_TAG}
 
 tests-hg-default:
+  extends:
+    - .tests
   stage: compat
-  allow_failure: true
-  image: octobus/ci-hgitaly:variable-hg
-  script:
-    - hg pull -R /ci/repos/mercurial/ --rev default
-    - hg -R /ci/repos/mercurial/ update default
-    - hg -R /ci/repos/mercurial summary
-    - (cd /ci/repos/mercurial; make local PYTHON=python3)
-    - hg clone -r default -u default $EVOLVE_REPO_URL $EVOLVE_LOCAL_REPO
-    - pip3 install --user $EVOLVE_LOCAL_REPO
-    - pip3 freeze
-    - /ci/repos/mercurial/hg version --debug
-    - PYTHONPATH=/ci/repos/mercurial python3 -c "from mercurial import util; print(util.version())"
-    - PYTHONPATH=/ci/repos/mercurial PATH=$HOME/.local/bin:$PATH
-         ./run-all-tests
+  image: ${BASE_IMAGES_COLLECTION}/hg-default:${BASE_IMAGES_TAG}