From 2e82d88589f2b484430b6cb20ecc093cf922bf83 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Thu, 23 Apr 2020 13:00:11 +0000 Subject: [PATCH] hlint: add haskell source code suggestions job This change adds a new job to run hlint on haskell source files. Change-Id: Ibf76c5552acecd68dfc56c4f31d8045ca5b233f1 --- doc/source/haskell-jobs.rst | 1 + doc/source/haskell-roles.rst | 2 ++ playbooks/haskell/hlint.yaml | 3 +++ playbooks/haskell/pre-hlint.yaml | 3 +++ roles/ensure-hlint/README.rst | 3 +++ roles/ensure-hlint/tasks/main.yaml | 11 +++++++++++ roles/hlint/README.rst | 13 +++++++++++++ roles/hlint/defaults/main.yaml | 3 +++ roles/hlint/tasks/main.yaml | 16 ++++++++++++++++ zuul-tests.d/haskell.yaml | 21 ++++++++++++++++++++- zuul.d/haskell-jobs.yaml | 9 +++++++++ 11 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 playbooks/haskell/hlint.yaml create mode 100644 playbooks/haskell/pre-hlint.yaml create mode 100644 roles/ensure-hlint/README.rst create mode 100644 roles/ensure-hlint/tasks/main.yaml create mode 100644 roles/hlint/README.rst create mode 100644 roles/hlint/defaults/main.yaml create mode 100644 roles/hlint/tasks/main.yaml diff --git a/doc/source/haskell-jobs.rst b/doc/source/haskell-jobs.rst index dd8326986..0dcb6e4c2 100644 --- a/doc/source/haskell-jobs.rst +++ b/doc/source/haskell-jobs.rst @@ -2,3 +2,4 @@ Haskell Jobs ============ .. zuul:autojob:: cabal-test +.. zuul:autojob:: hlint diff --git a/doc/source/haskell-roles.rst b/doc/source/haskell-roles.rst index 09a8dd195..ddae7ecab 100644 --- a/doc/source/haskell-roles.rst +++ b/doc/source/haskell-roles.rst @@ -3,4 +3,6 @@ Haskell Roles .. zuul:autorole:: ensure-cabal .. zuul:autorole:: ensure-ghc +.. zuul:autorole:: ensure-hlint .. zuul:autorole:: cabal-test +.. zuul:autorole:: hlint diff --git a/playbooks/haskell/hlint.yaml b/playbooks/haskell/hlint.yaml new file mode 100644 index 000000000..453a6079c --- /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 000000000..71e01604e --- /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 000000000..d88a0e03e --- /dev/null +++ b/roles/ensure-hlint/README.rst @@ -0,0 +1,3 @@ +Ensure hlint is installed + +Installs the hlint tool using the distro package. diff --git a/roles/ensure-hlint/tasks/main.yaml b/roles/ensure-hlint/tasks/main.yaml new file mode 100644 index 000000000..33d1ae5aa --- /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 + package: + 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 000000000..8cf4c5186 --- /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 000000000..5a7b87448 --- /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 000000000..f04bda223 --- /dev/null +++ b/roles/hlint/tasks/main.yaml @@ -0,0 +1,16 @@ +- block: + - name: Run hlint + command: "hlint --report={{ report_location }} ." + vars: + report_location: "{{ ansible_user_dir }}/zuul-output/logs/{{ hlint_report_name }}" + args: + chdir: "{{ zuul_work_dir }}" + + always: + - name: Return report to Zuul + zuul_return: + data: + zuul: + artifacts: + - name: "HLint report" + url: "{{ hlint_report_name }}" diff --git a/zuul-tests.d/haskell.yaml b/zuul-tests.d/haskell.yaml index ff672dff3..21c43e901 100644 --- a/zuul-tests.d/haskell.yaml +++ b/zuul-tests.d/haskell.yaml @@ -3,7 +3,8 @@ description: Test the cabal-test job and roles parent: cabal-test files: - - playbooks/haskell/.* + - playbooks/haskell/cabal.yaml + - playbooks/haskell/pre.yaml - roles/ensure-cabal/.* - roles/ensure-ghc/.* - roles/cabal-test/.* @@ -13,9 +14,27 @@ - name: fedora-31 label: fedora-31 +- job: + name: zuul-jobs-test-hlint + description: Test the hlint job and roles + parent: hlint + files: + - playbooks/haskell/hlint.yaml + - playbooks/haskell/pre-hlint.yaml + - roles/ensure-hlint/.* + - roles/hlint/.* + pre-run: + - playbooks/haskell/pre.yaml + - test-playbooks/haskell/setup-project.yaml + nodeset: + nodes: + - name: fedora-31 + label: fedora-31 + - project: check: jobs: &id001 - zuul-jobs-test-cabal-test + - zuul-jobs-test-hlint gate: jobs: *id001 diff --git a/zuul.d/haskell-jobs.yaml b/zuul.d/haskell-jobs.yaml index 8f05c55e6..f5255835b 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