cabal-test: add initial haskell job

This change adds a new job to test cabal based haskell project.

Change-Id: Idb24eb5f8f9bd1409bae07bf4da415f1d05568e4
This commit is contained in:
Tristan Cacqueray 2020-04-21 21:27:27 +00:00
parent b3358c7559
commit d92b39cae2
17 changed files with 154 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Haskell Jobs
============
.. zuul:autojob:: cabal-test

View File

@ -0,0 +1,6 @@
Haskell Roles
=============
.. zuul:autorole:: ensure-cabal
.. zuul:autorole:: ensure-ghc
.. zuul:autorole:: cabal-test

View File

@ -9,6 +9,7 @@ Jobs
js-jobs js-jobs
docker-jobs docker-jobs
go-jobs go-jobs
haskell-jobs
helm-jobs helm-jobs
packer-jobs packer-jobs
system-jobs system-jobs

View File

@ -15,6 +15,7 @@ Roles
deprecated-roles deprecated-roles
galaxy-roles galaxy-roles
go-roles go-roles
haskell-roles
helm-roles helm-roles
java-roles java-roles
js-roles js-roles

View File

@ -0,0 +1,3 @@
- hosts: all
roles:
- cabal-test

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- ensure-ghc
- ensure-cabal

View File

@ -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.

View File

@ -0,0 +1 @@
zuul_work_dir: "{{ zuul.project.src_dir }}"

View File

@ -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 }}"

View File

@ -0,0 +1,4 @@
Ensure cabal is installed
This role installs the cabal-install package and ensures
the hackage packages list exists.

View File

@ -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

View File

@ -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.

View File

@ -0,0 +1,6 @@
ghc_version: latest
ghc_versions:
latest: "8.10"
8.10: "8.10"
8.8: "8.8"
8.6: "8.6"

View File

@ -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"

View File

@ -0,0 +1,6 @@
- hosts: all
tasks:
- name: Setup files
command: cabal init --non-interactive
args:
chdir: "{{ zuul.project.src_dir }}"

21
zuul-tests.d/haskell.yaml Normal file
View File

@ -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

14
zuul.d/haskell-jobs.yaml Normal file
View File

@ -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