From cf64b73f78bcf1f438056163f6654a37ed161dbc Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Sun, 26 Apr 2020 20:09:24 +0000 Subject: [PATCH] haskell-stack-test: add haskell tool stack test This change adds a new job to test stack based haskell project. Change-Id: Ie3492097b351eec743d98e9ca8bc693c00c11a78 --- doc/source/haskell-jobs.rst | 1 + doc/source/haskell-roles.rst | 2 ++ playbooks/haskell/pre-stack.yaml | 3 ++ playbooks/haskell/stack.yaml | 3 ++ roles/ensure-haskell-stack/README.rst | 10 +++++++ roles/ensure-haskell-stack/defaults/main.yaml | 1 + roles/ensure-haskell-stack/tasks/main.yaml | 28 +++++++++++++++++++ roles/haskell-stack-test/README.rst | 12 ++++++++ roles/haskell-stack-test/defaults/main.yaml | 2 ++ roles/haskell-stack-test/tasks/main.yaml | 4 +++ .../haskell/setup-stack-project.yaml | 7 +++++ zuul-tests.d/haskell.yaml | 16 +++++++++++ zuul.d/haskell-jobs.yaml | 13 +++++++++ 13 files changed, 102 insertions(+) create mode 100644 playbooks/haskell/pre-stack.yaml create mode 100644 playbooks/haskell/stack.yaml create mode 100644 roles/ensure-haskell-stack/README.rst create mode 100644 roles/ensure-haskell-stack/defaults/main.yaml create mode 100644 roles/ensure-haskell-stack/tasks/main.yaml create mode 100644 roles/haskell-stack-test/README.rst create mode 100644 roles/haskell-stack-test/defaults/main.yaml create mode 100644 roles/haskell-stack-test/tasks/main.yaml create mode 100644 test-playbooks/haskell/setup-stack-project.yaml diff --git a/doc/source/haskell-jobs.rst b/doc/source/haskell-jobs.rst index 0dcb6e4c2..c9b8b5533 100644 --- a/doc/source/haskell-jobs.rst +++ b/doc/source/haskell-jobs.rst @@ -2,4 +2,5 @@ Haskell Jobs ============ .. zuul:autojob:: cabal-test +.. zuul:autojob:: haskell-stack-test .. zuul:autojob:: hlint diff --git a/doc/source/haskell-roles.rst b/doc/source/haskell-roles.rst index ddae7ecab..17e5e47da 100644 --- a/doc/source/haskell-roles.rst +++ b/doc/source/haskell-roles.rst @@ -4,5 +4,7 @@ Haskell Roles .. zuul:autorole:: ensure-cabal .. zuul:autorole:: ensure-ghc .. zuul:autorole:: ensure-hlint +.. zuul:autorole:: ensure-haskell-stack .. zuul:autorole:: cabal-test +.. zuul:autorole:: haskell-stack-test .. zuul:autorole:: hlint diff --git a/playbooks/haskell/pre-stack.yaml b/playbooks/haskell/pre-stack.yaml new file mode 100644 index 000000000..111c8aa60 --- /dev/null +++ b/playbooks/haskell/pre-stack.yaml @@ -0,0 +1,3 @@ +- hosts: all + roles: + - ensure-haskell-stack diff --git a/playbooks/haskell/stack.yaml b/playbooks/haskell/stack.yaml new file mode 100644 index 000000000..e901302fe --- /dev/null +++ b/playbooks/haskell/stack.yaml @@ -0,0 +1,3 @@ +- hosts: all + roles: + - haskell-stack-test diff --git a/roles/ensure-haskell-stack/README.rst b/roles/ensure-haskell-stack/README.rst new file mode 100644 index 000000000..c74a47d54 --- /dev/null +++ b/roles/ensure-haskell-stack/README.rst @@ -0,0 +1,10 @@ +Ensure the Haskell tool stack is installed. + +Installs the specified stack version and setup the toolchain. +This role uses the Fedora copr package. + +**Role Variables** + +.. zuul:rolevar:: lts_version + + The lts version. diff --git a/roles/ensure-haskell-stack/defaults/main.yaml b/roles/ensure-haskell-stack/defaults/main.yaml new file mode 100644 index 000000000..efcfb5069 --- /dev/null +++ b/roles/ensure-haskell-stack/defaults/main.yaml @@ -0,0 +1 @@ +lts_version: "" diff --git a/roles/ensure-haskell-stack/tasks/main.yaml b/roles/ensure-haskell-stack/tasks/main.yaml new file mode 100644 index 000000000..e7ad8a33c --- /dev/null +++ b/roles/ensure-haskell-stack/tasks/main.yaml @@ -0,0 +1,28 @@ +- name: Make sure the role is run on Fedora + fail: + msg: "This role supports Fedora only" + when: "ansible_distribution != 'Fedora'" + +- name: Check stack version + command: stack --version + failed_when: false + register: _stack_version + +- block: + - name: Install stack copr + command: dnf copr enable -y petersen/stack2 + become: true + + - name: Install stack + package: + name: stack + state: present + become: true + + - name: Upgrade stack + command: stack upgrade + become: true + + - name: Setup stack LTS + command: "stack {% if lts_version %}--resolver {{ lts_version }}{% endif %} setup" + when: _stack_version.rc != 0 diff --git a/roles/haskell-stack-test/README.rst b/roles/haskell-stack-test/README.rst new file mode 100644 index 000000000..9a85a46b9 --- /dev/null +++ b/roles/haskell-stack-test/README.rst @@ -0,0 +1,12 @@ +Run the Haskell stack test command. + +**Role Variables** + +.. zuul:rolevar:: lts_version + + The lts version. + +.. zuul:rolevar:: zuul_work_dir + :default: {{ zuul.project.src_dir }} + + Directory to run the cabal command in. diff --git a/roles/haskell-stack-test/defaults/main.yaml b/roles/haskell-stack-test/defaults/main.yaml new file mode 100644 index 000000000..d354a93e4 --- /dev/null +++ b/roles/haskell-stack-test/defaults/main.yaml @@ -0,0 +1,2 @@ +lts_version: "" +zuul_work_dir: "{{ zuul.project.src_dir }}" diff --git a/roles/haskell-stack-test/tasks/main.yaml b/roles/haskell-stack-test/tasks/main.yaml new file mode 100644 index 000000000..6fd4aad0e --- /dev/null +++ b/roles/haskell-stack-test/tasks/main.yaml @@ -0,0 +1,4 @@ +- name: Run stack test + command: "stack {% if lts_version %}--resolver {{ lts_version }}{% endif %} test" + args: + chdir: "{{ zuul_work_dir }}" diff --git a/test-playbooks/haskell/setup-stack-project.yaml b/test-playbooks/haskell/setup-stack-project.yaml new file mode 100644 index 000000000..d9fb288a7 --- /dev/null +++ b/test-playbooks/haskell/setup-stack-project.yaml @@ -0,0 +1,7 @@ +- hosts: all + tasks: + - name: Setup file + command: stack new new-project + + - name: Copy file over zuul-jobs + command: rsync -a new-project/ "{{ zuul.project.src_dir }}/" diff --git a/zuul-tests.d/haskell.yaml b/zuul-tests.d/haskell.yaml index 21c43e901..4934e591e 100644 --- a/zuul-tests.d/haskell.yaml +++ b/zuul-tests.d/haskell.yaml @@ -14,6 +14,21 @@ - name: fedora-31 label: fedora-31 +- job: + name: zuul-jobs-test-haskell-stack-test + description: Test the haskell-stack-test job and roles + parent: haskell-stack-test + files: + - playbooks/haskell/stack.yaml + - playbooks/haskell/pre-stack.yaml + - roles/ensure-haskell-stack/.* + - roles/haskell-stack-test/.* + pre-run: test-playbooks/haskell/setup-stack-project.yaml + nodeset: + nodes: + - name: fedora-31 + label: fedora-31 + - job: name: zuul-jobs-test-hlint description: Test the hlint job and roles @@ -35,6 +50,7 @@ check: jobs: &id001 - zuul-jobs-test-cabal-test + - zuul-jobs-test-haskell-stack-test - zuul-jobs-test-hlint gate: jobs: *id001 diff --git a/zuul.d/haskell-jobs.yaml b/zuul.d/haskell-jobs.yaml index f5255835b..6f60e8d0d 100644 --- a/zuul.d/haskell-jobs.yaml +++ b/zuul.d/haskell-jobs.yaml @@ -13,6 +13,19 @@ vars: ghc_version: latest +- job: + name: haskell-stack-test + description: | + Run stack test for a Haskell project. + + .. zuul:jobvar:: lts_version + + Use the specified lts version. + run: playbooks/haskell/stack.yaml + pre-run: playbooks/haskell/pre-stack.yaml + vars: + ghc_version: latest + - job: name: hlint description: |