Extract ensure-javascript-build-tool role

The pre-playbook for the javascript jobs got complex. Extract it
to a role so we can better document it.

Also - stop installing javascript depends in pre - the depends
declared in a patch should be tested as part of the patch.

Change-Id: I50a483f223620cd3f9ecd82887062cfc9ac64b7f
This commit is contained in:
Monty Taylor 2020-05-11 11:28:55 -05:00 committed by Andreas Jaeger
parent 202cce830e
commit 5973c9b7b1
6 changed files with 47 additions and 33 deletions

View File

@ -1,6 +1,7 @@
Javascript Roles Javascript Roles
================ ================
.. zuul:autorole:: ensure-javascript-build-tool
.. zuul:autorole:: ensure-javascript-packages .. zuul:autorole:: ensure-javascript-packages
.. zuul:autorole:: ensure-nodejs .. zuul:autorole:: ensure-nodejs
.. zuul:autorole:: ensure-yarn .. zuul:autorole:: ensure-yarn

View File

@ -1,34 +1,3 @@
- hosts: all - hosts: all
tasks: roles:
- name: Set node version if not set - ensure-javascript-build-tool
set_fact:
node_version: '14'
when: node_version is not defined
- name: Check for yarn.lock
when: js_build_tool is not defined
stat:
path: "{{ zuul_work_dir }}/yarn.lock"
get_checksum: false
get_mime: false
get_md5: false
register: yarn_lock_exists
- name: Set js_build_tool fact
set_fact:
js_build_tool: '{{ yarn_lock_exists.stat.exists | ternary("yarn", "npm") }}'
when: js_build_tool is not defined
- name: Ensure yarn if needed
include_role:
name: ensure-yarn
when: js_build_tool == 'yarn'
- name: Ensure nodejs if needed
include_role:
name: ensure-nodejs
when: js_build_tool == 'npm'
- name: Install javascript depends
include_role:
name: ensure-javascript-packages

View File

@ -0,0 +1,14 @@
Install javascript build tool needed for a project
**Role Variables**
.. zuul:rolevar:: js_build_tool
:default: autodetected
What command to use. If the ``zuul_work_dir`` has a ``yarn.lock``
file, it will default to ``yarn``, otherwise ``npm``.
.. zuul:rolevar:: zuul_work_dir
:default: {{ zuul.project.src_dir }}
The directory to work in.

View File

@ -0,0 +1,2 @@
node_version: '14'
zuul_work_dir: "{{ zuul.project.src_dir }}"

View File

@ -0,0 +1,24 @@
- name: Check for yarn.lock
when: js_build_tool is not defined
stat:
path: "{{ zuul_work_dir }}/yarn.lock"
get_checksum: false
get_mime: false
get_md5: false
register: yarn_lock_exists
- name: Set js_build_tool fact
set_fact:
js_build_tool: '{{ yarn_lock_exists.stat.exists | ternary("yarn", "npm") }}'
cacheable: true
when: js_build_tool is not defined
- name: Ensure yarn if needed
include_role:
name: ensure-yarn
when: js_build_tool == 'yarn'
- name: Ensure nodejs if needed
include_role:
name: ensure-nodejs
when: js_build_tool == 'npm'

View File

@ -28,6 +28,10 @@
js_build_tool: '{{ yarn_lock_exists.stat.exists | ternary("yarn", "npm") }}' js_build_tool: '{{ yarn_lock_exists.stat.exists | ternary("yarn", "npm") }}'
when: js_build_tool is not defined when: js_build_tool is not defined
- name: Install javascript depends
include_role:
name: ensure-javascript-packages
- name: Run js build command - name: Run js build command
command: "{{ js_build_tool }} {% if js_build_command not in npm_lifecycle_phases %} run {% endif %} {{ js_build_command }} --verbose" command: "{{ js_build_tool }} {% if js_build_command not in npm_lifecycle_phases %} run {% endif %} {{ js_build_command }} --verbose"
# Need to set DISPLAY to the value that will be set when the virtual # Need to set DISPLAY to the value that will be set when the virtual