diff --git a/doc/source/jobs.rst b/doc/source/jobs.rst index 4180cee0b..b051b97d8 100644 --- a/doc/source/jobs.rst +++ b/doc/source/jobs.rst @@ -12,5 +12,6 @@ Jobs hashicorp-jobs haskell-jobs helm-jobs + nim-jobs system-jobs deprecated-jobs diff --git a/doc/source/nim-jobs.rst b/doc/source/nim-jobs.rst new file mode 100644 index 000000000..030b820ae --- /dev/null +++ b/doc/source/nim-jobs.rst @@ -0,0 +1,4 @@ +Nim Jobs +======== + +.. zuul:autojob:: nimble diff --git a/doc/source/nim-roles.rst b/doc/source/nim-roles.rst new file mode 100644 index 000000000..18a8caa78 --- /dev/null +++ b/doc/source/nim-roles.rst @@ -0,0 +1,6 @@ +Nim Roles +========= + +.. zuul:autorole:: ensure-nimble +.. zuul:autorole:: nimble + diff --git a/doc/source/roles.rst b/doc/source/roles.rst index b3b88b087..8815c50db 100644 --- a/doc/source/roles.rst +++ b/doc/source/roles.rst @@ -23,6 +23,7 @@ Roles js-roles kubernetes-roles launchpad-roles + nim-roles puppet-roles python-roles rust-roles diff --git a/playbooks/nimble/pre.yaml b/playbooks/nimble/pre.yaml new file mode 100644 index 000000000..1d2749287 --- /dev/null +++ b/playbooks/nimble/pre.yaml @@ -0,0 +1,3 @@ +- hosts: all + roles: + - ensure-nimble diff --git a/playbooks/nimble/run.yaml b/playbooks/nimble/run.yaml new file mode 100644 index 000000000..bd89bf16f --- /dev/null +++ b/playbooks/nimble/run.yaml @@ -0,0 +1,3 @@ +- hosts: all + roles: + - nimble diff --git a/roles/ensure-nimble/README.rst b/roles/ensure-nimble/README.rst new file mode 100644 index 000000000..0fb5039d5 --- /dev/null +++ b/roles/ensure-nimble/README.rst @@ -0,0 +1,6 @@ +Install nim + +**Role Variables** + +.. zuul:rolevar:: nim_version + :default: stable diff --git a/roles/ensure-nimble/defaults/main.yaml b/roles/ensure-nimble/defaults/main.yaml new file mode 100644 index 000000000..ecc6c1d43 --- /dev/null +++ b/roles/ensure-nimble/defaults/main.yaml @@ -0,0 +1 @@ +nim_version: stable diff --git a/roles/ensure-nimble/tasks/main.yaml b/roles/ensure-nimble/tasks/main.yaml new file mode 100644 index 000000000..a3d2a54b1 --- /dev/null +++ b/roles/ensure-nimble/tasks/main.yaml @@ -0,0 +1,35 @@ +- name: Set nim_path fact + set_fact: + nim_path: "{{ ansible_user_dir }}/.nimble/bin/" + cacheable: true + +- name: Check if nimble is installed + command: nimble --version + environment: + PATH: "{{ nim_path }}:{{ ansible_env.PATH }}" + failed_when: false + changed_when: false + register: _nimble_installed + +- when: _nimble_installed.rc != 0 + block: + - name: Create tempfile for choosenim install script + tempfile: + register: choosenim_installer + + - name: Install nim with choosenim + get_url: + url: https://nim-lang.org/choosenim/init.sh + dest: "{{ choosenim_installer.path }}" + mode: 0755 + + - name: Install nim + command: "{{ choosenim_installer.path }} -y" + environment: + CHOOSENIM_NO_ANALYTICS: 1 + CHOOSENIM_CHOOSE_VERSION: "{{ nim_version }}" + always: + - name: Remove installer tempfile + file: + state: absent + path: "{{ choosenim_installer.path }}" diff --git a/roles/nimble/README.rst b/roles/nimble/README.rst new file mode 100644 index 000000000..671d9c421 --- /dev/null +++ b/roles/nimble/README.rst @@ -0,0 +1,18 @@ +Run nimble command in a source directory. Assumes the appropriate version of nim and nimble is installed. + +**Role Variables** + +.. zuul:rolevar:: nimble_command + :default: build + + Nimble command to run. + Examples are "build", "run" or "test". + +.. zuul:rolevar:: nim_path + + Path where nim and nimble are installed. + +.. zuul:rolevar:: zuul_work_dir + :default: {{ zuul.project.src_dir }} + + Directory to run nimble in. diff --git a/roles/nimble/defaults/main.yaml b/roles/nimble/defaults/main.yaml new file mode 100644 index 000000000..63dd89c64 --- /dev/null +++ b/roles/nimble/defaults/main.yaml @@ -0,0 +1,2 @@ +nimble_command: build +zuul_work_dir: "{{ zuul.project.src_dir }}" diff --git a/roles/nimble/tasks/main.yaml b/roles/nimble/tasks/main.yaml new file mode 100644 index 000000000..e97656511 --- /dev/null +++ b/roles/nimble/tasks/main.yaml @@ -0,0 +1,6 @@ +- name: Run nimble + command: "nimble {{ nimble_command }} --accept" + args: + chdir: "{{ zuul_work_dir }}" + environment: + PATH: "{{ nim_path }}:{{ ansible_env.PATH }}" diff --git a/test-playbooks/nimble/src/test.nim b/test-playbooks/nimble/src/test.nim new file mode 100644 index 000000000..f42ff3959 --- /dev/null +++ b/test-playbooks/nimble/src/test.nim @@ -0,0 +1 @@ +echo "Hello world!" diff --git a/test-playbooks/nimble/test.nimble b/test-playbooks/nimble/test.nimble new file mode 100644 index 000000000..8631c2635 --- /dev/null +++ b/test-playbooks/nimble/test.nimble @@ -0,0 +1,13 @@ +# Package + +version = "0.1.0" +author = "Albin Vass" +description = "A new awesome nimble package" +license = "MIT" +srcDir = "src" +bin = @["test"] + + +# Dependencies + +requires "nim >= 1.4.0" diff --git a/zuul-tests.d/nim-jobs.yaml b/zuul-tests.d/nim-jobs.yaml new file mode 100644 index 000000000..09af17957 --- /dev/null +++ b/zuul-tests.d/nim-jobs.yaml @@ -0,0 +1,152 @@ +- job: + name: zuul-jobs-test-nimble + parent: nimble + description: Test the nimble job + tags: all-platforms + files: + - playbooks/nimble + - roles/ensure-nimble + - roles/nimble + - test-playbooks/nimble + vars: + zuul_work_dir: '{{ zuul.project.src_dir }}/test-playbooks/nimble' + +- job: + name: zuul-jobs-test-nimble-centos-7 + description: Test the nimble job on centos-7 + parent: zuul-jobs-test-nimble + tags: auto-generated + nodeset: + nodes: + - name: centos-7 + label: centos-7 + +- job: + name: zuul-jobs-test-nimble-centos-8 + description: Test the nimble job on centos-8 + parent: zuul-jobs-test-nimble + tags: auto-generated + nodeset: + nodes: + - name: centos-8 + label: centos-8 + +- job: + name: zuul-jobs-test-nimble-centos-8-stream + description: Test the nimble job on centos-8-stream + parent: zuul-jobs-test-nimble + tags: auto-generated + nodeset: + nodes: + - name: centos-8-stream + label: centos-8-stream + +- job: + name: zuul-jobs-test-nimble-debian-stretch + description: Test the nimble job on debian-stretch + parent: zuul-jobs-test-nimble + tags: auto-generated + nodeset: + nodes: + - name: debian-stretch + label: debian-stretch + +- job: + name: zuul-jobs-test-nimble-fedora-32 + description: Test the nimble job on fedora-32 + parent: zuul-jobs-test-nimble + tags: auto-generated + nodeset: + nodes: + - name: fedora-32 + label: fedora-32 + +- job: + name: zuul-jobs-test-nimble-gentoo-17-0-systemd + description: Test the nimble job on gentoo-17-0-systemd + parent: zuul-jobs-test-nimble + tags: auto-generated + nodeset: + nodes: + - name: gentoo-17-0-systemd + label: gentoo-17-0-systemd + +- job: + name: zuul-jobs-test-nimble-opensuse-15 + description: Test the nimble job on opensuse-15 + parent: zuul-jobs-test-nimble + tags: auto-generated + nodeset: + nodes: + - name: opensuse-15 + label: opensuse-15 + +- job: + name: zuul-jobs-test-nimble-opensuse-tumbleweed-nv + voting: false + description: Test the nimble job on opensuse-tumbleweed + parent: zuul-jobs-test-nimble + tags: auto-generated + nodeset: + nodes: + - name: opensuse-tumbleweed + label: opensuse-tumbleweed + +- job: + name: zuul-jobs-test-nimble-ubuntu-bionic + description: Test the nimble job on ubuntu-bionic + parent: zuul-jobs-test-nimble + tags: auto-generated + nodeset: + nodes: + - name: ubuntu-bionic + label: ubuntu-bionic + +- job: + name: zuul-jobs-test-nimble-ubuntu-xenial + description: Test the nimble job on ubuntu-xenial + parent: zuul-jobs-test-nimble + tags: auto-generated + nodeset: + nodes: + - name: ubuntu-xenial + label: ubuntu-xenial + +- job: + name: zuul-jobs-test-nimble-ubuntu-focal + description: Test the nimble job on ubuntu-focal + parent: zuul-jobs-test-nimble + tags: auto-generated + nodeset: + nodes: + - name: ubuntu-focal + label: ubuntu-focal + +- project: + check: + jobs: + - zuul-jobs-test-nimble-centos-7 + - zuul-jobs-test-nimble-centos-8 + - zuul-jobs-test-nimble-centos-8-stream + - zuul-jobs-test-nimble-debian-stretch + - zuul-jobs-test-nimble-fedora-32 + - zuul-jobs-test-nimble-gentoo-17-0-systemd + - zuul-jobs-test-nimble-opensuse-15 + - zuul-jobs-test-nimble-opensuse-tumbleweed-nv + - zuul-jobs-test-nimble-ubuntu-bionic + - zuul-jobs-test-nimble-ubuntu-xenial + - zuul-jobs-test-nimble-ubuntu-focal + gate: + jobs: &id001 + - zuul-jobs-test-nimble-centos-7 + - zuul-jobs-test-nimble-centos-8 + - zuul-jobs-test-nimble-centos-8-stream + - zuul-jobs-test-nimble-debian-stretch + - zuul-jobs-test-nimble-fedora-32 + - zuul-jobs-test-nimble-gentoo-17-0-systemd + - zuul-jobs-test-nimble-opensuse-15 + - zuul-jobs-test-nimble-ubuntu-bionic + - zuul-jobs-test-nimble-ubuntu-xenial + - zuul-jobs-test-nimble-ubuntu-focal + periodic-weekly: + jobs: *id001 diff --git a/zuul.d/nim-jobs.yaml b/zuul.d/nim-jobs.yaml new file mode 100644 index 000000000..06b2f09d0 --- /dev/null +++ b/zuul.d/nim-jobs.yaml @@ -0,0 +1,22 @@ +- job: + name: nimble + parent: unittests + description: | + Base job for nim operations + + Responds to these variables: + + ..zuul:jobvar:: nimble_command + :default: build + + .. zuul:jobvar:: nim_version + :default: stable + + The version of nim to use. + + .. zuul:jobvar:: zuul_work_dir + ::default: {{ zuul.project.src_dir }} + + Path to operate in. + pre-run: playbooks/nimble/pre.yaml + run: playbooks/nimble/run.yaml