Merge "Add ensure-bazelisk role"

This commit is contained in:
Zuul 2020-02-21 15:31:53 +00:00 committed by Gerrit Code Review
commit f4703021a4
5 changed files with 77 additions and 0 deletions

View File

@ -14,6 +14,7 @@ General Purpose Roles
.. zuul:autorole:: dstat-graph
.. zuul:autorole:: emit-job-header
.. zuul:autorole:: enable-netconsole
.. zuul:autorole:: ensure-bazelisk
.. zuul:autorole:: ensure-dstat-graph
.. zuul:autorole:: ensure-markdownlint
.. zuul:autorole:: fetch-markdownlint

View File

@ -0,0 +1,34 @@
Ensure that bazelisk is present.
If bazelisk is already installed, this role does nothing. Otherwise,
it downloads bazelisk from GitHub and installs it in the user's
home directory by default.
**Role Variables**
.. zuul:rolevar:: bazelisk_version
:default: v1.3.0
Version of bazelisk to install.
.. zuul:rolevar:: bazelisk_arch
:default: linux-amd64
Architecture to install.
.. zuul:rolevar:: bazelisk_url
:default: https://github.com/bazelbuild/bazelisk/releases/download/{{ bazelisk_version }}/bazelisk-{{ bazelisk_arch }}
The URL from which to download bazelisk.
.. zuul:rolevar:: bazelisk_executable
:default: bazelisk
The bazelisk executable. If this already exists, the
role will not perform any further actions.
.. zuul:rolevar:: bazelisk_target
:default: "{{ ansible_user_dir }}/.local/bin/bazelisk"
Where to install bazelisk. If the role downloads bazelisk, it will
set :zuul:rolevar:`ensure-bazelisk.bazelisk_executable` to this value as well.

View File

@ -0,0 +1,6 @@
bazelisk_version: v1.3.0
bazelisk_arch: linux-amd64
bazelisk_url: "https://github.com/bazelbuild/bazelisk/releases/download/{{ bazelisk_version }}/bazelisk-{{ bazelisk_arch }}"
bazelisk_executable: bazelisk
# If we have to download it, store it here:
bazelisk_target: "{{ ansible_user_dir }}/.local/bin/bazelisk"

View File

@ -0,0 +1,25 @@
- name: Check if bazelisk is installed
command: bash -c "type -p {{ bazelisk_executable }}"
failed_when: false
register: bazelisk_installed
- name: Ensure target directory exists
file:
state: directory
path: "{{ bazelisk_target | dirname }}"
when: bazelisk_installed.rc != 0
- name: Download bazelisk
get_url:
url: "{{ bazelisk_url }}"
dest: "{{ bazelisk_target }}"
mode: '0755'
when: bazelisk_installed.rc != 0
register: bazelisk_downloaded
# This will apply to further plays and playbooks
- name: Set bazelisk_executable fact
set_fact:
bazelisk_executable: "{{ bazelisk_target }}"
cacheable: true
when: bazelisk_downloaded is changed

View File

@ -233,6 +233,15 @@
vars:
role_name: clear-firewall
- job:
name: zuul-jobs-test-ensure-bazelisk
description: Test the ensure-bazelisk role
files:
- roles/ensure-bazelisk/.*
run: test-playbooks/simple-role-test.yaml
vars:
role_name: ensure-bazelisk
- job:
name: zuul-jobs-test-netconsole
description: Test the netconsole setup role
@ -482,6 +491,7 @@
- zuul-jobs-test-base-roles-ubuntu-xenial
- zuul-jobs-test-bindep
- zuul-jobs-test-clear-firewall
- zuul-jobs-test-ensure-bazelisk
- zuul-jobs-test-netconsole
- zuul-jobs-test-dstat-graph
- zuul-jobs-test-multinode-roles-centos-7
@ -510,6 +520,7 @@
- zuul-jobs-test-base-roles-ubuntu-xenial
- zuul-jobs-test-bindep
- zuul-jobs-test-clear-firewall
- zuul-jobs-test-ensure-bazelisk
- zuul-jobs-test-netconsole
- zuul-jobs-test-dstat-graph
- zuul-jobs-test-multinode-roles-centos-7