From ff44b6cd4e5e73dc6c3e1f59e2da9711cf1997d8 Mon Sep 17 00:00:00 2001 From: vass Date: Wed, 1 Apr 2020 19:43:39 +0200 Subject: [PATCH] Rename install-javascript-packages to ensure-javascript-packages for consistency The old role will be kept and include ensure-javascript-packages for backwards-compatability. Change-Id: Ibb896edf0652a19be13018b4abddb4a81c51f07b --- doc/source/js-roles.rst | 1 + playbooks/javascript/pre.yaml | 2 +- roles/ensure-javascript-packages/README.rst | 14 ++++++ .../defaults/main.yaml | 3 ++ .../tasks/main.yaml | 44 +++++++++++++++++ .../tasks/main.yaml | 47 ++----------------- 6 files changed, 66 insertions(+), 45 deletions(-) create mode 100644 roles/ensure-javascript-packages/README.rst create mode 100644 roles/ensure-javascript-packages/defaults/main.yaml create mode 100644 roles/ensure-javascript-packages/tasks/main.yaml diff --git a/doc/source/js-roles.rst b/doc/source/js-roles.rst index 0c628d84d..595262a2d 100644 --- a/doc/source/js-roles.rst +++ b/doc/source/js-roles.rst @@ -1,6 +1,7 @@ Javascript Roles ================ +.. zuul:autorole:: ensure-javascript-packages .. zuul:autorole:: fetch-javascript-content-tarball .. zuul:autorole:: fetch-javascript-output .. zuul:autorole:: fetch-javascript-tarball diff --git a/playbooks/javascript/pre.yaml b/playbooks/javascript/pre.yaml index 34206c20c..46b467645 100644 --- a/playbooks/javascript/pre.yaml +++ b/playbooks/javascript/pre.yaml @@ -2,4 +2,4 @@ roles: - install-nodejs - install-yarn - - install-javascript-packages + - ensure-javascript-packages diff --git a/roles/ensure-javascript-packages/README.rst b/roles/ensure-javascript-packages/README.rst new file mode 100644 index 000000000..529c9dfcb --- /dev/null +++ b/roles/ensure-javascript-packages/README.rst @@ -0,0 +1,14 @@ +Install javascript dependencies needed for a project + +**Role Variables** + +.. zuul:rolevar:: zuul_work_dir + :default: {{ zuul.project.src_dir }} + + The directory to work in. + +.. zuul:rolevar:: tox_constraints_file + + Path to a pip constraints file. Will set the + ``UPPER_CONSTRAINTS_FILE`` environment variable. Useful if npm + ``postinstall`` runs tox. diff --git a/roles/ensure-javascript-packages/defaults/main.yaml b/roles/ensure-javascript-packages/defaults/main.yaml new file mode 100644 index 000000000..79e5a2e91 --- /dev/null +++ b/roles/ensure-javascript-packages/defaults/main.yaml @@ -0,0 +1,3 @@ +npm_environment: + DISPLAY: ':99' +zuul_work_dir: "{{ zuul.project.src_dir }}" diff --git a/roles/ensure-javascript-packages/tasks/main.yaml b/roles/ensure-javascript-packages/tasks/main.yaml new file mode 100644 index 000000000..70f3443f8 --- /dev/null +++ b/roles/ensure-javascript-packages/tasks/main.yaml @@ -0,0 +1,44 @@ +- name: Check to see if the constraints file exists + stat: + path: "{{ tox_constraints_file }}" + get_checksum: false + get_mime: false + get_md5: false + register: stat_results + when: tox_constraints_file is defined + +- name: Fail if constraints file is missing + when: tox_constraints_file is defined and not stat_results.stat.exists + fail: + msg: tox_constraints_file is defined but was not found + +- name: Record file location + set_fact: + tox_constraints_env: + TOX_CONSTRAINTS_FILE: "{{ tox_constraints_file }}" + # Backward compatibility, to be removed + UPPER_CONSTRAINTS_FILE: "{{ tox_constraints_file }}" + when: tox_constraints_file is defined + +- name: Check for yarn.lock file + stat: + path: "{{ zuul_work_dir }}/yarn.lock" + get_checksum: false + get_mime: false + get_md5: false + register: yarn_lock + +- name: Install yarn dependencies + command: yarn install + environment: + DISPLAY: ':99' + args: + chdir: "{{ zuul_work_dir }}" + when: yarn_lock.stat.exists + +- name: Install npm dependencies + command: npm install --verbose + environment: "{{ npm_environment|combine(tox_constraints_env|default({})) }}" + args: + chdir: "{{ zuul_work_dir }}" + when: not yarn_lock.stat.exists diff --git a/roles/install-javascript-packages/tasks/main.yaml b/roles/install-javascript-packages/tasks/main.yaml index 70f3443f8..427e5e8e8 100644 --- a/roles/install-javascript-packages/tasks/main.yaml +++ b/roles/install-javascript-packages/tasks/main.yaml @@ -1,44 +1,3 @@ -- name: Check to see if the constraints file exists - stat: - path: "{{ tox_constraints_file }}" - get_checksum: false - get_mime: false - get_md5: false - register: stat_results - when: tox_constraints_file is defined - -- name: Fail if constraints file is missing - when: tox_constraints_file is defined and not stat_results.stat.exists - fail: - msg: tox_constraints_file is defined but was not found - -- name: Record file location - set_fact: - tox_constraints_env: - TOX_CONSTRAINTS_FILE: "{{ tox_constraints_file }}" - # Backward compatibility, to be removed - UPPER_CONSTRAINTS_FILE: "{{ tox_constraints_file }}" - when: tox_constraints_file is defined - -- name: Check for yarn.lock file - stat: - path: "{{ zuul_work_dir }}/yarn.lock" - get_checksum: false - get_mime: false - get_md5: false - register: yarn_lock - -- name: Install yarn dependencies - command: yarn install - environment: - DISPLAY: ':99' - args: - chdir: "{{ zuul_work_dir }}" - when: yarn_lock.stat.exists - -- name: Install npm dependencies - command: npm install --verbose - environment: "{{ npm_environment|combine(tox_constraints_env|default({})) }}" - args: - chdir: "{{ zuul_work_dir }}" - when: not yarn_lock.stat.exists +- name: Include ensure-javascript-packages + include_role: + name: ensure-javascript-packages