From 634cb78e7fd9051749facf83073f608d2459462c Mon Sep 17 00:00:00 2001
From: Tristan Cacqueray <tdecacqu@redhat.com>
Date: Jan 06 2021 15:22:08 +0000
Subject: [PATCH 1/2] Update jobs expression to enable testing variants


This change adds a top-level variable to enable generating testing
variants.

---

diff --git a/zuul.d/jobs.dhall b/zuul.d/jobs.dhall
index 78475dc..ae72e48 100644
--- a/zuul.d/jobs.dhall
+++ b/zuul.d/jobs.dhall
@@ -14,12 +14,16 @@ Install zuulfmt by running: `python3 -mpip install --user zuulfmt`
 -}
 
 let Zuul =
-        https://raw.githubusercontent.com/softwarefactory-project/dhall-zuul/master/package.dhall
-      ? ~/git/softwarefactory-project.io/software-factory/dhall-zuul/package.dhall
+        ~/git/softwarefactory-project.io/software-factory/dhall-zuul/package.dhall
+      ? https://raw.githubusercontent.com/softwarefactory-project/dhall-zuul/master/package.dhall
 
 let Prelude =
       https://prelude.dhall-lang.org/v17.0.0/package.dhall sha256:10db3c919c25e9046833df897a8ffe2701dc390fa0893d958c3430524be5a43e
 
+let --| When setting a custom prefix, redirect the output to a new file to preserve the existing job definition
+    job-prefix =
+      ""
+
 let Arch =
       let Union = < X86_64 | S390X | PPC64LE | I686 | ARMV7HL | AARCH64 >
 
@@ -117,7 +121,7 @@ let executor_nodeset =
 
 let check_for_tests =
       Zuul.Job::{
-      , name = Some "check-for-tests"
+      , name = Some "${job-prefix}check-for-tests"
       , description = Some "Check the project has a tests/tests.yml"
       , branches = Some Branch.allText
       , run = Some "playbooks/rpm/check-for-tests.yaml"
@@ -126,7 +130,7 @@ let check_for_tests =
 
 let common_koji_rpm_build =
       Zuul.Job::{
-      , name = Some "common-koji-rpm-build"
+      , name = Some "${job-prefix}common-koji-rpm-build"
       , abstract = Some True
       , protected = Some True
       , description = Some "Base job for RPM build on Fedora Koji"
@@ -176,7 +180,7 @@ let generateRpmBuildJobName
               then  "rpm-scratch-build" ++ suffix
               else  "rpm-build"
 
-        in  name
+        in  job-prefix ++ name
 
 let doFetchArtifact
     : Arch.Type → KojiBuild.Type → Bool

From e796e5e4c076811961fa1d012d48e1b42d034f05 Mon Sep 17 00:00:00 2001
From: Tristan Cacqueray <tdecacqu@redhat.com>
Date: Jan 06 2021 16:14:46 +0000
Subject: [PATCH 2/2] Add check-for-arches parent job preview


---

diff --git a/playbooks/rpm/check-for-arches.yaml b/playbooks/rpm/check-for-arches.yaml
new file mode 100644
index 0000000..2f9989a
--- /dev/null
+++ b/playbooks/rpm/check-for-arches.yaml
@@ -0,0 +1,21 @@
+- hosts: localhost
+  tasks:
+    - name: Check for noarch
+      command: sh -c "rpm --specfile *.spec | rev | cut -d'.' -f 1 | rev | grep -v '^noarch$'"
+      register: tests_noarch
+      failed_when: false
+      args:
+        chdir: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}"
+
+    - zuul_return:
+        data:
+          zuul:
+            child_jobs: "{{ arch_jobs }}"
+      when: tests_noarch.stdout_lines != []
+
+    - zuul_return:
+        data:
+          zuul:
+            child_jobs:
+              - noop
+      when: tests_noarch.stdout_lines == []
diff --git a/zuul.d/jobs-preview.yaml b/zuul.d/jobs-preview.yaml
new file mode 100644
index 0000000..464220f
--- /dev/null
+++ b/zuul.d/jobs-preview.yaml
@@ -0,0 +1,402 @@
+
+- job:
+    name: preview-check-for-tests
+    description: Check the project has a tests/tests.yml
+    run: playbooks/rpm/check-for-tests.yaml
+    branches:
+      - master
+      - f33
+      - f32
+      - epel8
+    nodeset:
+      nodes: []
+
+- job:
+    name: preview-check-for-arches
+    description: Check the packages needs arches builds
+    run: playbooks/rpm/check-for-arches.yaml
+    branches:
+      - master
+      - f33
+      - f32
+      - epel8
+    nodeset:
+      nodes: []
+    vars:
+      arch_jobs:
+        - preview-rpm-scratch-build-s390x
+        - preview-rpm-scratch-build-ppc64le
+        - preview-rpm-scratch-build-i686
+        - preview-rpm-scratch-build-armv7hl
+        - preview-rpm-scratch-build-aarch64
+
+- job:
+    name: preview-common-koji-rpm-build
+    description: Base job for RPM build on Fedora Koji
+    run: playbooks/koji/build-ng.yaml
+    abstract: true
+    nodeset: fedora-33-container
+    protected: true
+    provides:
+      - repo
+    roles:
+      - zuul: zuul-distro-jobs
+    secrets:
+      - name: krb_keytab
+        secret: krb_keytab
+    timeout: 21600
+
+- job:
+    name: preview-rpm-scratch-build
+    parent: preview-common-koji-rpm-build
+    branches:
+      - master
+    final: true
+    vars:
+      arches: x86_64
+      fetch_artifacts: true
+      release: master
+      scratch_build: true
+      target: rawhide
+
+- job:
+    name: preview-rpm-scratch-build-s390x
+    parent: preview-common-koji-rpm-build
+    branches:
+      - master
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: s390x
+      fetch_artifacts: false
+      release: master
+      scratch_build: true
+      target: rawhide
+
+- job:
+    name: preview-rpm-scratch-build-ppc64le
+    parent: preview-common-koji-rpm-build
+    branches:
+      - master
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: ppc64le
+      fetch_artifacts: false
+      release: master
+      scratch_build: true
+      target: rawhide
+
+- job:
+    name: preview-rpm-scratch-build-i686
+    parent: preview-common-koji-rpm-build
+    branches:
+      - master
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: i686
+      fetch_artifacts: false
+      release: master
+      scratch_build: true
+      target: rawhide
+
+- job:
+    name: preview-rpm-scratch-build-armv7hl
+    parent: preview-common-koji-rpm-build
+    branches:
+      - master
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: armv7hl
+      fetch_artifacts: false
+      release: master
+      scratch_build: true
+      target: rawhide
+
+- job:
+    name: preview-rpm-scratch-build-aarch64
+    parent: preview-common-koji-rpm-build
+    branches:
+      - master
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: aarch64
+      fetch_artifacts: false
+      release: master
+      scratch_build: true
+      target: rawhide
+
+- job:
+    name: preview-rpm-scratch-build
+    parent: preview-common-koji-rpm-build
+    branches:
+      - f33
+    final: true
+    vars:
+      arches: x86_64
+      fetch_artifacts: true
+      release: f33
+      scratch_build: true
+      target: f33
+
+- job:
+    name: preview-rpm-scratch-build-s390x
+    parent: preview-common-koji-rpm-build
+    branches:
+      - f33
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: s390x
+      fetch_artifacts: false
+      release: f33
+      scratch_build: true
+      target: f33
+
+- job:
+    name: preview-rpm-scratch-build-ppc64le
+    parent: preview-common-koji-rpm-build
+    branches:
+      - f33
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: ppc64le
+      fetch_artifacts: false
+      release: f33
+      scratch_build: true
+      target: f33
+
+- job:
+    name: preview-rpm-scratch-build-i686
+    parent: preview-common-koji-rpm-build
+    branches:
+      - f33
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: i686
+      fetch_artifacts: false
+      release: f33
+      scratch_build: true
+      target: f33
+
+- job:
+    name: preview-rpm-scratch-build-armv7hl
+    parent: preview-common-koji-rpm-build
+    branches:
+      - f33
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: armv7hl
+      fetch_artifacts: false
+      release: f33
+      scratch_build: true
+      target: f33
+
+- job:
+    name: preview-rpm-scratch-build-aarch64
+    parent: preview-common-koji-rpm-build
+    branches:
+      - f33
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: aarch64
+      fetch_artifacts: false
+      release: f33
+      scratch_build: true
+      target: f33
+
+- job:
+    name: preview-rpm-scratch-build
+    parent: preview-common-koji-rpm-build
+    branches:
+      - f32
+    final: true
+    vars:
+      arches: x86_64
+      fetch_artifacts: true
+      release: f32
+      scratch_build: true
+      target: f32
+
+- job:
+    name: preview-rpm-scratch-build-s390x
+    parent: preview-common-koji-rpm-build
+    branches:
+      - f32
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: s390x
+      fetch_artifacts: false
+      release: f32
+      scratch_build: true
+      target: f32
+
+- job:
+    name: preview-rpm-scratch-build-ppc64le
+    parent: preview-common-koji-rpm-build
+    branches:
+      - f32
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: ppc64le
+      fetch_artifacts: false
+      release: f32
+      scratch_build: true
+      target: f32
+
+- job:
+    name: preview-rpm-scratch-build-i686
+    parent: preview-common-koji-rpm-build
+    branches:
+      - f32
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: i686
+      fetch_artifacts: false
+      release: f32
+      scratch_build: true
+      target: f32
+
+- job:
+    name: preview-rpm-scratch-build-armv7hl
+    parent: preview-common-koji-rpm-build
+    branches:
+      - f32
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: armv7hl
+      fetch_artifacts: false
+      release: f32
+      scratch_build: true
+      target: f32
+
+- job:
+    name: preview-rpm-scratch-build-aarch64
+    parent: preview-common-koji-rpm-build
+    branches:
+      - f32
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: aarch64
+      fetch_artifacts: false
+      release: f32
+      scratch_build: true
+      target: f32
+
+- job:
+    name: preview-rpm-scratch-build
+    parent: preview-common-koji-rpm-build
+    branches:
+      - epel8
+    final: true
+    vars:
+      arches: x86_64
+      fetch_artifacts: true
+      release: epel8
+      scratch_build: true
+      target: epel8
+
+- job:
+    name: preview-rpm-scratch-build-ppc64le
+    parent: preview-common-koji-rpm-build
+    branches:
+      - epel8
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: ppc64le
+      fetch_artifacts: false
+      release: epel8
+      scratch_build: true
+      target: epel8
+
+- job:
+    name: preview-rpm-scratch-build-aarch64
+    parent: preview-common-koji-rpm-build
+    branches:
+      - epel8
+    dependencies:
+      - check-for-arches
+    final: true
+    vars:
+      arches: aarch64
+      fetch_artifacts: false
+      release: epel8
+      scratch_build: true
+      target: epel8
+
+- job:
+    name: preview-rpm-build
+    parent: preview-common-koji-rpm-build
+    branches:
+      - master
+    final: true
+    vars:
+      fetch_artifacts: false
+      release: master
+      scratch_build: false
+      target: rawhide
+
+- job:
+    name: preview-rpm-build
+    parent: preview-common-koji-rpm-build
+    branches:
+      - f33
+    final: true
+    vars:
+      fetch_artifacts: false
+      release: f33
+      scratch_build: false
+      target: f33
+
+- job:
+    name: preview-rpm-build
+    parent: preview-common-koji-rpm-build
+    branches:
+      - f32
+    final: true
+    vars:
+      fetch_artifacts: false
+      release: f32
+      scratch_build: false
+      target: f32
+
+- job:
+    name: preview-rpm-build
+    parent: preview-common-koji-rpm-build
+    branches:
+      - epel8
+    final: true
+    vars:
+      fetch_artifacts: false
+      release: epel8
+      scratch_build: false
+      target: epel8
diff --git a/zuul.d/jobs.dhall b/zuul.d/jobs.dhall
index ae72e48..51eb339 100644
--- a/zuul.d/jobs.dhall
+++ b/zuul.d/jobs.dhall
@@ -115,6 +115,35 @@ let KojiBuild =
               λ(kb : Union) → merge { Scratch = "scratch", Final = "final" } kb
           }
 
+let generateRpmBuildJobName
+    : Arch.Type → KojiBuild.Type → Text
+    = λ(arch : Arch.Type) →
+      λ(kbtype : KojiBuild.Type) →
+        let suffix = if Arch.isX86_64 arch then "" else "-" ++ Arch.show arch
+
+        let name =
+              if    KojiBuild.isScratch kbtype
+              then  "rpm-scratch-build" ++ suffix
+              else  "rpm-build"
+
+        in  job-prefix ++ name
+
+let Arch =
+        Arch
+      ⫽ { extras =
+            Prelude.List.filter
+              Arch.Type
+              (λ(arch : Arch.Type) → Prelude.Bool.not (Arch.isX86_64 arch))
+              Arch.fedora
+        , scratch-job-names =
+            Prelude.List.map
+              Arch.Type
+              Text
+              ( λ(arch : Arch.Type) →
+                  generateRpmBuildJobName arch KojiBuild.Type.Scratch
+              )
+        }
+
 let executor_nodeset =
       Zuul.Nodeset.Inline
         Zuul.Nodeset::{ nodes = [] : List Zuul.Nodeset.NodeType }
@@ -128,6 +157,29 @@ let check_for_tests =
       , nodeset = Some executor_nodeset
       }
 
+let check_for_arches =
+      Zuul.Job::{
+      , name = Some "${job-prefix}check-for-arches"
+      , description = Some "Check the packages needs arches builds"
+      , branches = Some Branch.allText
+      , run = Some "playbooks/rpm/check-for-arches.yaml"
+      , vars = Some
+          ( Zuul.Vars.object
+              ( toMap
+                  { arch_jobs =
+                      Zuul.Vars.array
+                        ( Prelude.List.map
+                            Text
+                            Zuul.Vars.Type
+                            Zuul.Vars.string
+                            (Arch.scratch-job-names Arch.extras)
+                        )
+                  }
+              )
+          )
+      , nodeset = Some executor_nodeset
+      }
+
 let common_koji_rpm_build =
       Zuul.Job::{
       , name = Some "${job-prefix}common-koji-rpm-build"
@@ -169,19 +221,6 @@ let setVars =
 
         in  Zuul.Vars.object vars
 
-let generateRpmBuildJobName
-    : Arch.Type → KojiBuild.Type → Text
-    = λ(arch : Arch.Type) →
-      λ(kbtype : KojiBuild.Type) →
-        let suffix = if Arch.isX86_64 arch then "" else "-" ++ Arch.show arch
-
-        let name =
-              if    KojiBuild.isScratch kbtype
-              then  "rpm-scratch-build" ++ suffix
-              else  "rpm-build"
-
-        in  job-prefix ++ name
-
 let doFetchArtifact
     : Arch.Type → KojiBuild.Type → Bool
     = λ(arch : Arch.Type) →
@@ -196,6 +235,10 @@ let generateRpmBuildJob =
         , name = Some (generateRpmBuildJobName arch kbtype)
         , parent = Some (Zuul.Job.getName common_koji_rpm_build)
         , final = Some True
+        , dependencies =
+            if    Arch.isX86_64 arch
+            then  None (List Zuul.Job.Dependency.union)
+            else  Some [ Zuul.Job.Dependency.Name "check-for-arches" ]
         , branches = Some [ Branch.show branch ]
         , vars = Some
             ( setVars
@@ -228,7 +271,7 @@ let generateRpmBuildJobs
               Branch.all
 
 let Jobs =
-        [ check_for_tests, common_koji_rpm_build ]
+        [ check_for_tests, check_for_arches, common_koji_rpm_build ]
       # generateRpmBuildJobs KojiBuild.Type.Scratch
       # generateRpmBuildJobs KojiBuild.Type.Final
 

