hlint: add haskell source code suggestions job

This change adds a new job to run hlint on haskell source files.

Change-Id: Ibf76c5552acecd68dfc56c4f31d8045ca5b233f1
diff --git a/playbooks/haskell/hlint.yaml b/playbooks/haskell/hlint.yaml
new file mode 100644
index 0000000..453a607
--- /dev/null
+++ b/playbooks/haskell/hlint.yaml
@@ -0,0 +1,3 @@
+- hosts: all
+  roles:
+    - hlint
diff --git a/playbooks/haskell/pre-hlint.yaml b/playbooks/haskell/pre-hlint.yaml
new file mode 100644
index 0000000..71e0160
--- /dev/null
+++ b/playbooks/haskell/pre-hlint.yaml
@@ -0,0 +1,3 @@
+- hosts: all
+  roles:
+    - ensure-hlint
diff --git a/roles/ensure-hlint/README.rst b/roles/ensure-hlint/README.rst
new file mode 100644
index 0000000..0ac9e99
--- /dev/null
+++ b/roles/ensure-hlint/README.rst
@@ -0,0 +1,3 @@
+Ensure hlint is installed
+
+Installs the hlint tool using the fedora package.
diff --git a/roles/ensure-hlint/tasks/main.yaml b/roles/ensure-hlint/tasks/main.yaml
new file mode 100644
index 0000000..fb39a01
--- /dev/null
+++ b/roles/ensure-hlint/tasks/main.yaml
@@ -0,0 +1,11 @@
+- name: Check hlint version
+  command: hlint --version
+  failed_when: false
+  register: _hlint_version
+
+- name: Install hlint
+  dnf:
+    name: "hlint"
+    state: present
+  become: yes
+  when: "_hlint_version.rc != 0"
diff --git a/roles/hlint/README.rst b/roles/hlint/README.rst
new file mode 100644
index 0000000..8cf4c51
--- /dev/null
+++ b/roles/hlint/README.rst
@@ -0,0 +1,13 @@
+Run the hlint command.
+
+**Role Variables**
+
+.. zuul:rolevar:: hlint_report_name
+   :default: hlint.html
+
+   The name of the report.
+
+.. zuul:rolevar:: zuul_work_dir
+   :default: {{ zuul.project.src_dir }}
+
+   Directory to run the hlint command in.
diff --git a/roles/hlint/defaults/main.yaml b/roles/hlint/defaults/main.yaml
new file mode 100644
index 0000000..5a7b874
--- /dev/null
+++ b/roles/hlint/defaults/main.yaml
@@ -0,0 +1,3 @@
+hlint_report_name: "hlint.html"
+
+zuul_work_dir: "{{ zuul.project.src_dir }}"
diff --git a/roles/hlint/tasks/main.yaml b/roles/hlint/tasks/main.yaml
new file mode 100644
index 0000000..d9e2e45
--- /dev/null
+++ b/roles/hlint/tasks/main.yaml
@@ -0,0 +1,21 @@
+- name: Run hlint
+  command: "hlint --report={{ report_location }} ."
+  register: _hlint
+  failed_when: false
+  vars:
+    report_location: "{{ ansible_user_dir }}/zuul-output/logs/{{ hlint_report_name }}"
+  args:
+    chdir: "{{ zuul_work_dir }}"
+
+- name: Return report to Zuul
+  zuul_return:
+    data:
+      zuul:
+        artifacts:
+          - name: "HLint report"
+            url: "{{ hlint_report_name }}"
+
+- name: Fail on error
+  fail:
+    msg: "HLint failed"
+  when: _hlint.rc != 0
diff --git a/zuul.d/haskell-jobs.yaml b/zuul.d/haskell-jobs.yaml
index 8f05c55..f525583 100644
--- a/zuul.d/haskell-jobs.yaml
+++ b/zuul.d/haskell-jobs.yaml
@@ -12,3 +12,12 @@
     pre-run: playbooks/haskell/pre.yaml
     vars:
       ghc_version: latest
+
+- job:
+    name: hlint
+    description: |
+      Run haskell source code suggestions.
+
+      This job produces an hlint.html report.
+    run: playbooks/haskell/hlint.yaml
+    pre-run: playbooks/haskell/pre-hlint.yaml