FAQ | This is a LIVE service | Changelog

Commit 8e159c9e authored by Ed Kirk's avatar Ed Kirk Committed by Ryan Kowalewski
Browse files

feat: add poe-based test runner proof of concept

This is a proof of concept template to generate a dynamic downstream pipeline
containing multiple poe task jobs. For more information see the guidebook page -
https://guidebook.devops.uis.cam.ac.uk/howtos/git-gitlab/poe-test-pipeline/
parent eadd8d2e
Loading
Loading
Loading
Loading
+51 −0
Original line number Diff line number Diff line
# This template is currently in POC state. More details here:
# https://guidebook.devops.uis.cam.ac.uk/howtos/git-gitlab/poe-test-pipeline/

# Job to generate dynamic pipeline file with poe commands list variables
poe-tests-generator:
  image: registry.gitlab.developers.cam.ac.uk/uis/devops/infra/dockerimages/python:slim
  stage: test
  needs: []
  script:
    - pip install pyyaml
    - |
      python - <<EOF
      import tomllib
      import yaml
      with open("pyproject.toml", "rb") as pyproject_file:
          pyproject = tomllib.load(pyproject_file)
      all_tasks = pyproject.get("tool", {}).get("poe", {}).get("tasks", {})
      test_tasks = [key for key in all_tasks.keys() if key.startswith("test-")]
      trigger_pipeline = {
          "include": [
            {
              "project": "uis/devops/continuous-delivery/ci-templates",
              "file": "/fragments/poe-tests-base.gitlab-ci.yml",
            }
          ],
          "poe-tests": {
              "extends": ".poe-tests",
              "parallel": {
                  "matrix": [
                      {
                          "POE_TASK": test_tasks
                      }
                  ]
              }
          }
      }
      with open("poe-tests-matrix.gitlab-ci.yml", "w") as matrix_file:
          matrix_file.write(yaml.dump(trigger_pipeline))
      EOF
  artifacts:
    paths:
      - poe-tests-matrix.gitlab-ci.yml

poe-tests-trigger:
  stage: test
  trigger:
    strategy: depend
    include:
      - artifact: poe-tests-matrix.gitlab-ci.yml
        job: poe-tests-generator
  needs: [poe-tests-generator]
 No newline at end of file
+28 −0
Original line number Diff line number Diff line
.poe-tests:
  # See https://gitlab.developers.cam.ac.uk/uis/devops/docs/guidebook/-/blob/master/docs/howtos/development/prepare-your-system.md?ref_type=heads 
  #(and https://gitlab.developers.cam.ac.uk/uis/devops/docs/guidebook/-/merge_requests/482)
  image: registry.gitlab.developers.cam.ac.uk/uis/devops/infra/dockerimages/python:alpine

  services:
    - docker:dind

  # This job does not need the "build" stage to have completed.
  needs: []

  stage: test

  before_script:
    - apk update
    - apk add --no-cache docker docker-compose git bash curl musl-dev gcc libffi-dev linux-headers
    - pip install poethepoet

  script:
    - DOCKER_HOST='tcp://docker:2375' poe $POE_TASK

  rules:
      # This job is used in a downstream child pipeline, triggered by a parent pipeline.
      - if: $CI_PIPELINE_SOURCE == "parent_pipeline"

  parallel:
    matrix:
      - POE_TASK: