From d92b39cae237975a96b17b440836b5cc3d4e73cf Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Tue, 21 Apr 2020 21:27:27 +0000 Subject: [PATCH] cabal-test: add initial haskell job This change adds a new job to test cabal based haskell project. Change-Id: Idb24eb5f8f9bd1409bae07bf4da415f1d05568e4 --- doc/source/haskell-jobs.rst | 4 ++++ doc/source/haskell-roles.rst | 6 ++++++ doc/source/jobs.rst | 1 + doc/source/roles.rst | 1 + playbooks/haskell/cabal.yaml | 3 +++ playbooks/haskell/pre.yaml | 4 ++++ roles/cabal-test/README.rst | 8 ++++++++ roles/cabal-test/defaults/main.yaml | 1 + roles/cabal-test/tasks/main.yaml | 19 +++++++++++++++++ roles/ensure-cabal/README.rst | 4 ++++ roles/ensure-cabal/tasks/main.yaml | 20 ++++++++++++++++++ roles/ensure-ghc/README.rst | 11 ++++++++++ roles/ensure-ghc/defaults/main.yaml | 6 ++++++ roles/ensure-ghc/tasks/main.yaml | 25 +++++++++++++++++++++++ test-playbooks/haskell/setup-project.yaml | 6 ++++++ zuul-tests.d/haskell.yaml | 21 +++++++++++++++++++ zuul.d/haskell-jobs.yaml | 14 +++++++++++++ 17 files changed, 154 insertions(+) create mode 100644 doc/source/haskell-jobs.rst create mode 100644 doc/source/haskell-roles.rst create mode 100644 playbooks/haskell/cabal.yaml create mode 100644 playbooks/haskell/pre.yaml create mode 100644 roles/cabal-test/README.rst create mode 100644 roles/cabal-test/defaults/main.yaml create mode 100644 roles/cabal-test/tasks/main.yaml create mode 100644 roles/ensure-cabal/README.rst create mode 100644 roles/ensure-cabal/tasks/main.yaml create mode 100644 roles/ensure-ghc/README.rst create mode 100644 roles/ensure-ghc/defaults/main.yaml create mode 100644 roles/ensure-ghc/tasks/main.yaml create mode 100644 test-playbooks/haskell/setup-project.yaml create mode 100644 zuul-tests.d/haskell.yaml create mode 100644 zuul.d/haskell-jobs.yaml diff --git a/doc/source/haskell-jobs.rst b/doc/source/haskell-jobs.rst new file mode 100644 index 000000000..dd8326986 --- /dev/null +++ b/doc/source/haskell-jobs.rst @@ -0,0 +1,4 @@ +Haskell Jobs +============ + +.. zuul:autojob:: cabal-test diff --git a/doc/source/haskell-roles.rst b/doc/source/haskell-roles.rst new file mode 100644 index 000000000..09a8dd195 --- /dev/null +++ b/doc/source/haskell-roles.rst @@ -0,0 +1,6 @@ +Haskell Roles +============= + +.. zuul:autorole:: ensure-cabal +.. zuul:autorole:: ensure-ghc +.. zuul:autorole:: cabal-test diff --git a/doc/source/jobs.rst b/doc/source/jobs.rst index 6ac0cfea6..b6a131a43 100644 --- a/doc/source/jobs.rst +++ b/doc/source/jobs.rst @@ -9,6 +9,7 @@ Jobs js-jobs docker-jobs go-jobs + haskell-jobs helm-jobs packer-jobs system-jobs diff --git a/doc/source/roles.rst b/doc/source/roles.rst index ee316b9fd..1c9e28d2b 100644 --- a/doc/source/roles.rst +++ b/doc/source/roles.rst @@ -15,6 +15,7 @@ Roles deprecated-roles galaxy-roles go-roles + haskell-roles helm-roles java-roles js-roles diff --git a/playbooks/haskell/cabal.yaml b/playbooks/haskell/cabal.yaml new file mode 100644 index 000000000..d7dab09b9 --- /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 000000000..d47e4b6cb --- /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 000000000..523a52b61 --- /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 000000000..9739eb171 --- /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 000000000..7d3274913 --- /dev/null +++ b/roles/cabal-test/tasks/main.yaml @@ -0,0 +1,19 @@ +- name: Run cabal install --only-dependencies + command: cabal install --only-dependencies + args: + chdir: "{{ zuul_work_dir }}" + +- name: Run cabal configure --enable-test + command: cabal configure --enable-test + args: + chdir: "{{ zuul_work_dir }}" + +- 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 000000000..a97d4e81a --- /dev/null +++ b/roles/ensure-cabal/README.rst @@ -0,0 +1,4 @@ +Ensure cabal is installed + +This role installs the cabal-install package and ensures +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 000000000..9b6cf95cf --- /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 000000000..fa35b7737 --- /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 000000000..a2cccc875 --- /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 000000000..e3dbe1aa4 --- /dev/null +++ b/roles/ensure-ghc/tasks/main.yaml @@ -0,0 +1,25 @@ +- name: Make sure the role is run on Fedora + fail: + msg: "This role supports Fedora only" + when: "ansible_distribution != 'Fedora'" + +- 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/test-playbooks/haskell/setup-project.yaml b/test-playbooks/haskell/setup-project.yaml new file mode 100644 index 000000000..f88b9bfeb --- /dev/null +++ b/test-playbooks/haskell/setup-project.yaml @@ -0,0 +1,6 @@ +- hosts: all + tasks: + - name: Setup files + command: cabal init --non-interactive + args: + chdir: "{{ zuul.project.src_dir }}" diff --git a/zuul-tests.d/haskell.yaml b/zuul-tests.d/haskell.yaml new file mode 100644 index 000000000..ff672dff3 --- /dev/null +++ b/zuul-tests.d/haskell.yaml @@ -0,0 +1,21 @@ +- job: + name: zuul-jobs-test-cabal-test + description: Test the cabal-test job and roles + parent: cabal-test + files: + - playbooks/haskell/.* + - roles/ensure-cabal/.* + - roles/ensure-ghc/.* + - roles/cabal-test/.* + pre-run: test-playbooks/haskell/setup-project.yaml + nodeset: + nodes: + - name: fedora-31 + label: fedora-31 + +- project: + check: + jobs: &id001 + - zuul-jobs-test-cabal-test + gate: + jobs: *id001 diff --git a/zuul.d/haskell-jobs.yaml b/zuul.d/haskell-jobs.yaml new file mode 100644 index 000000000..8f05c55e6 --- /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