summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Cacqueray <tdecacqu@redhat.com>2020-04-21 21:27:27 +0000
committerTristan Cacqueray <tdecacqu@redhat.com>2020-04-21 19:32:00 -0400
commit7f3d86f4af19b5c140c6f1bf3212fde3fd9eb795 (patch)
tree2d4e9a7e5cf67468a9cf60fa1cab66a1b8290456
parent2a33a9e675842fdb0a4fc01159a8b10abd209a08 (diff)
cabal-test: add initial haskell job
This change adds a new job to test cabal based haskell project. Change-Id: Idb24eb5f8f9bd1409bae07bf4da415f1d05568e4
-rw-r--r--playbooks/haskell/cabal.yaml3
-rw-r--r--playbooks/haskell/pre.yaml4
-rw-r--r--roles/cabal-test/README.rst8
-rw-r--r--roles/cabal-test/defaults/main.yaml1
-rw-r--r--roles/cabal-test/tasks/main.yaml9
-rw-r--r--roles/ensure-cabal/README.rst4
-rw-r--r--roles/ensure-cabal/tasks/main.yaml20
-rw-r--r--roles/ensure-ghc/README.rst11
-rw-r--r--roles/ensure-ghc/defaults/main.yaml6
-rw-r--r--roles/ensure-ghc/tasks/main.yaml20
-rw-r--r--zuul.d/haskell-jobs.yaml14
11 files changed, 100 insertions, 0 deletions
diff --git a/playbooks/haskell/cabal.yaml b/playbooks/haskell/cabal.yaml
new file mode 100644
index 0000000..d7dab09
--- /dev/null
+++ b/playbooks/haskell/cabal.yaml
@@ -0,0 +1,3 @@
+- hosts: all
+ roles:
+ - cabal-test
diff --git a/playbooks/haskell/pre.yaml b/playbooks/haskell/pre.yaml
new file mode 100644
index 0000000..d47e4b6
--- /dev/null
+++ b/playbooks/haskell/pre.yaml
@@ -0,0 +1,4 @@
+- hosts: all
+ roles:
+ - ensure-ghc
+ - ensure-cabal
diff --git a/roles/cabal-test/README.rst b/roles/cabal-test/README.rst
new file mode 100644
index 0000000..523a52b
--- /dev/null
+++ b/roles/cabal-test/README.rst
@@ -0,0 +1,8 @@
+Run the cabal test command.
+
+**Role Variables**
+
+.. zuul:rolevar:: zuul_work_dir
+ :default: {{ zuul.project.src_dir }}
+
+ Directory to run the cabal command in.
diff --git a/roles/cabal-test/defaults/main.yaml b/roles/cabal-test/defaults/main.yaml
new file mode 100644
index 0000000..9739eb1
--- /dev/null
+++ b/roles/cabal-test/defaults/main.yaml
@@ -0,0 +1 @@
+zuul_work_dir: "{{ zuul.project.src_dir }}"
diff --git a/roles/cabal-test/tasks/main.yaml b/roles/cabal-test/tasks/main.yaml
new file mode 100644
index 0000000..de58808
--- /dev/null
+++ b/roles/cabal-test/tasks/main.yaml
@@ -0,0 +1,9 @@
+- name: Run cabal build
+ command: cabal build
+ args:
+ chdir: "{{ zuul_work_dir }}"
+
+- name: Run cabal test
+ command: cabal test
+ args:
+ chdir: "{{ zuul_work_dir }}"
diff --git a/roles/ensure-cabal/README.rst b/roles/ensure-cabal/README.rst
new file mode 100644
index 0000000..97fbdf9
--- /dev/null
+++ b/roles/ensure-cabal/README.rst
@@ -0,0 +1,4 @@
+Ensure cabal is installed
+
+This role install the cabal-install package and ensure
+the hackage packages list exists.
diff --git a/roles/ensure-cabal/tasks/main.yaml b/roles/ensure-cabal/tasks/main.yaml
new file mode 100644
index 0000000..9b6cf95
--- /dev/null
+++ b/roles/ensure-cabal/tasks/main.yaml
@@ -0,0 +1,20 @@
+- name: Check cabal version
+ command: cabal --version
+ failed_when: false
+ register: _cabal_version
+
+- name: Install cabal
+ package:
+ name: cabal-install
+ state: present
+ become: yes
+ when: "_cabal_version.rc != 0"
+
+- name: Check package
+ stat:
+ path: "~/.cabal/packages"
+ register: _cabal_packages
+
+- name: Update package list
+ command: cabal update
+ when: not _cabal_packages.stat.exists
diff --git a/roles/ensure-ghc/README.rst b/roles/ensure-ghc/README.rst
new file mode 100644
index 0000000..0f9fc2e
--- /dev/null
+++ b/roles/ensure-ghc/README.rst
@@ -0,0 +1,11 @@
+Ensure ghc is installed
+
+Installs the specified ghc version and the cabal tool.
+This role uses the fedora package module.
+
+**Role Variables**
+
+.. zuul:rolevar:: ghc_version
+ :default: latest
+
+ The ghc version.
diff --git a/roles/ensure-ghc/defaults/main.yaml b/roles/ensure-ghc/defaults/main.yaml
new file mode 100644
index 0000000..a2cccc8
--- /dev/null
+++ b/roles/ensure-ghc/defaults/main.yaml
@@ -0,0 +1,6 @@
+ghc_version: latest
+ghc_versions:
+ latest: "8.10"
+ 8.10: "8.10"
+ 8.8: "8.8"
+ 8.6: "8.6"
diff --git a/roles/ensure-ghc/tasks/main.yaml b/roles/ensure-ghc/tasks/main.yaml
new file mode 100644
index 0000000..aa05a06
--- /dev/null
+++ b/roles/ensure-ghc/tasks/main.yaml
@@ -0,0 +1,20 @@
+- name: Check requested version
+ fail:
+ msg: |
+ Unknown ghc version: {{ ghc_version }}.
+ It needs to be defined in {{ opendev_url }}/roles/ensure-ghc/defaults/main.yaml
+ when: ghc_versions[ghc_version] is not defined
+ vars:
+ opendev_url: https://opendev.org/zuul/zuul-jobs/src/branch/master/
+
+- name: Check ghc version
+ command: ghc --version
+ failed_when: false
+ register: _ghc_version
+
+- name: Install ghc
+ dnf:
+ name: "@ghc:{{ ghc_versions[ghc_version]|string }}"
+ state: present
+ become: yes
+ when: "_ghc_version.rc != 0 or (ghc_versions[ghc_version]|string) not in _ghc_version.stdout"
diff --git a/zuul.d/haskell-jobs.yaml b/zuul.d/haskell-jobs.yaml
new file mode 100644
index 0000000..8f05c55
--- /dev/null
+++ b/zuul.d/haskell-jobs.yaml
@@ -0,0 +1,14 @@
+- job:
+ name: cabal-test
+ description: |
+ Run cabal test for a Haskell project.
+
+ Responds to these variables:
+
+ .. zuul:jobvar:: ghc_version
+
+ Use the specified ghc version (``latest`` picks the latest).
+ run: playbooks/haskell/cabal.yaml
+ pre-run: playbooks/haskell/pre.yaml
+ vars:
+ ghc_version: latest