From e0806102ade658c38435491edc8f5ef19757822f Mon Sep 17 00:00:00 2001
From: Fabien Boucher <fboucher@redhat.com>
Date: Jul 16 2021 08:49:15 +0000
Subject: Add fmf-tests on testing-farm jobs support (dhall)


---

diff --git a/playbooks/rpm/check-for-fmf-tests.yaml b/playbooks/rpm/check-for-fmf-tests.yaml
new file mode 100644
index 0000000..7f1f8cc
--- /dev/null
+++ b/playbooks/rpm/check-for-fmf-tests.yaml
@@ -0,0 +1,13 @@
+---
+- hosts: localhost
+  tasks:
+    - name: Check for .fmf exists
+      stat:
+        path: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/.fmf"
+      register: tests_stat
+    - zuul_return:
+        data:
+          zuul:
+            child_jobs:
+              - rpm-tmt-test-on-testing-farm
+      when: not tests_stat.stat.isdir
diff --git a/playbooks/testing-farm/fetch.yaml b/playbooks/testing-farm/fetch.yaml
new file mode 100644
index 0000000..847ba84
--- /dev/null
+++ b/playbooks/testing-farm/fetch.yaml
@@ -0,0 +1,6 @@
+- hosts: all
+  tasks:
+    - debug:
+        msg: "Post run fetching artifacts"
+#    - include_role:
+#        name: testing-farm-fetch-artifacts
diff --git a/playbooks/testing-farm/run.yaml b/playbooks/testing-farm/run.yaml
new file mode 100644
index 0000000..b727a62
--- /dev/null
+++ b/playbooks/testing-farm/run.yaml
@@ -0,0 +1,6 @@
+- hosts: all
+  tasks:
+    - debug:
+        msg: "Running tmt job"
+#    - include_role:
+#        name: testing-farm-run-test
diff --git a/zuul.d/jobs.dhall b/zuul.d/jobs.dhall
index 101c64b..15ec3f1 100644
--- a/zuul.d/jobs.dhall
+++ b/zuul.d/jobs.dhall
@@ -83,6 +83,15 @@ let check_for_tests =
       , nodeset = Some executor_nodeset
       }
 
+let check_for_fmf_tests =
+      Zuul.Job::{
+      , name = "${job-prefix}check-for-fmf-tests"
+      , description = Some "Check the project has a .fmf directory"
+      , branches = Some Branches.allText
+      , run = Some "playbooks/rpm/check-for-fmf-tests.yaml"
+      , nodeset = Some executor_nodeset
+      }
+
 let check_for_arches =
       Zuul.Job::{
       , name = "${job-prefix}check-for-arches"
@@ -210,13 +219,58 @@ let generateRpmBuildJobs
               forBranch
               Branches.all
 
+let getTMTJobVars =
+      λ(branch : Branches.Type) →
+        let name =
+              merge
+                { Rawhide = "Fedora-Rawhide"
+                , F33 = "Fedora-33"
+                , F34 = "Fedora-34"
+                , Epel8 = "Fedora-epel8"
+                }
+                branch
+
+        in  Zuul.Vars.object
+              [ { mapKey = "compose", mapValue = Zuul.Vars.string name } ]
+
+let generateTMTTestsJob =
+      λ(branch : Branches.Type) →
+        Zuul.Job::{
+        , name = "rpm-tmt-test"
+        , description = Some "Running fmf test on Testing Farm"
+        , final = Some True
+        , branches = Branches.zuulBranch branch
+        , roles = Some [ { zuul = "zuul-distro-jobs" } ]
+        , timeout = Some 21600
+        , nodeset = Some default_nodeset
+        , requires = Some [ "repo" ]
+        , secrets = Some
+          [ Zuul.Job.Secret::{
+            , name = "testing_farm_zuul_fedora_ci_key"
+            , secret = "testing_farm_zuul_fedora_ci_key"
+            }
+          ]
+        , run = Some "playbooks/testing-farm/run.yaml"
+        , post-run = Some [ "playbooks/testing-farm/fetch.yaml" ]
+        , vars = Some (getTMTJobVars branch)
+        }
+
+let generateTMTTestsJobs =
+      Prelude.List.map
+        Branches.Type
+        Zuul.Job.Type
+        generateTMTTestsJob
+        Branches.all
+
 let Jobs =
         [ clean_stalled_koji_tasks
         , check_for_tests
+        , check_for_fmf_tests
         , check_for_arches
         , common_koji_rpm_build
         ]
       # generateRpmBuildJobs KojiBuild.Type.Scratch
       # generateRpmBuildJobs KojiBuild.Type.Final
+      # generateTMTTestsJobs
 
 in  Zuul.Job.wrap Jobs
diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml
index 115bcc0..d220e48 100644
--- a/zuul.d/jobs.yaml
+++ b/zuul.d/jobs.yaml
@@ -26,6 +26,19 @@
       nodes: []
 
 - job:
+    name: check-for-fmf-tests
+    description: Check the project has a .fmf directory
+    run: playbooks/rpm/check-for-fmf-tests.yaml
+    branches:
+      - rawhide
+      - f34
+      - f33
+      - epel8
+      - main
+    nodeset:
+      nodes: []
+
+- job:
     name: check-for-arches
     description: Check the packages needs arches builds
     run: playbooks/rpm/check-for-arches.yaml
@@ -428,3 +441,88 @@
       release: epel8
       scratch_build: false
       target: epel8
+
+- job:
+    name: rpm-tmt-test
+    description: Running fmf test on Testing Farm
+    run: playbooks/testing-farm/run.yaml
+    post-run:
+      - playbooks/testing-farm/fetch.yaml
+    branches:
+      - rawhide
+      - main
+    final: true
+    nodeset: fedora-33-container
+    requires:
+      - repo
+    roles:
+      - zuul: zuul-distro-jobs
+    secrets:
+      - name: testing_farm_zuul_fedora_ci_key
+        secret: testing_farm_zuul_fedora_ci_key
+    timeout: 21600
+    vars:
+      compose: Fedora-Rawhide
+
+- job:
+    name: rpm-tmt-test
+    description: Running fmf test on Testing Farm
+    run: playbooks/testing-farm/run.yaml
+    post-run:
+      - playbooks/testing-farm/fetch.yaml
+    branches:
+      - f34
+    final: true
+    nodeset: fedora-33-container
+    requires:
+      - repo
+    roles:
+      - zuul: zuul-distro-jobs
+    secrets:
+      - name: testing_farm_zuul_fedora_ci_key
+        secret: testing_farm_zuul_fedora_ci_key
+    timeout: 21600
+    vars:
+      compose: Fedora-34
+
+- job:
+    name: rpm-tmt-test
+    description: Running fmf test on Testing Farm
+    run: playbooks/testing-farm/run.yaml
+    post-run:
+      - playbooks/testing-farm/fetch.yaml
+    branches:
+      - f33
+    final: true
+    nodeset: fedora-33-container
+    requires:
+      - repo
+    roles:
+      - zuul: zuul-distro-jobs
+    secrets:
+      - name: testing_farm_zuul_fedora_ci_key
+        secret: testing_farm_zuul_fedora_ci_key
+    timeout: 21600
+    vars:
+      compose: Fedora-33
+
+- job:
+    name: rpm-tmt-test
+    description: Running fmf test on Testing Farm
+    run: playbooks/testing-farm/run.yaml
+    post-run:
+      - playbooks/testing-farm/fetch.yaml
+    branches:
+      - epel8
+    final: true
+    nodeset: fedora-33-container
+    requires:
+      - repo
+    roles:
+      - zuul: zuul-distro-jobs
+    secrets:
+      - name: testing_farm_zuul_fedora_ci_key
+        secret: testing_farm_zuul_fedora_ci_key
+    timeout: 21600
+    vars:
+      compose: Fedora-epel8

