From 98aa9f9bb04cd576d7e1391fb0972d853fb1d147 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Fri, 27 Jul 2018 09:34:22 -0400 Subject: [PATCH] Add a yarn role Projects using yarn for dependencies can just run yarn commands instead of npm commands. Add a yarn role that allows a project to do that. Change-Id: I48a722ca55c88c6330114da3a2c035b1f84f92e1 --- roles/yarn/README.rst | 15 +++++++++++++++ roles/yarn/defaults/main.yaml | 1 + roles/yarn/tasks/main.yaml | 24 ++++++++++++++++++++++++ roles/yarn/vars/main.yaml | 9 +++++++++ 4 files changed, 49 insertions(+) create mode 100644 roles/yarn/README.rst create mode 100644 roles/yarn/defaults/main.yaml create mode 100644 roles/yarn/tasks/main.yaml create mode 100644 roles/yarn/vars/main.yaml diff --git a/roles/yarn/README.rst b/roles/yarn/README.rst new file mode 100644 index 000000000..87ae17dee --- /dev/null +++ b/roles/yarn/README.rst @@ -0,0 +1,15 @@ +Run yarn command in a source directory. Assumes the appropriate version +of yarn has been installed. + +**Role Variables** + +.. zuul:rolevar:: yarn_command + + Command to run. If it's a standard lifecycle command, it will be run as + ``yarn {{ yarn_command }}``. Otherwise it will be run as + ``yarn run {{ yarn_command }}``. + +.. zuul:rolevar:: zuul_work_dir + :default: {{ zuul.project.src_dir }} + + Directory to run yarn in. diff --git a/roles/yarn/defaults/main.yaml b/roles/yarn/defaults/main.yaml new file mode 100644 index 000000000..9739eb171 --- /dev/null +++ b/roles/yarn/defaults/main.yaml @@ -0,0 +1 @@ +zuul_work_dir: "{{ zuul.project.src_dir }}" diff --git a/roles/yarn/tasks/main.yaml b/roles/yarn/tasks/main.yaml new file mode 100644 index 000000000..f751cfdb8 --- /dev/null +++ b/roles/yarn/tasks/main.yaml @@ -0,0 +1,24 @@ +- name: Require yarn_command variable + fail: + msg: yarn_command is required for this role + when: yarn_command is not defined + +- name: Run yarn lifecycle command + when: yarn_command in yarn_lifecycle_phases + command: "yarn {{ yarn_command }} --verbose" + # Need to set DISPLAY to the value that will be set when the virtual + # framebuffer is set up for doing browser tests. + environment: + DISPLAY: ':99' + args: + chdir: "{{ zuul_work_dir }}" + +- name: Run yarn custom command + when: yarn_command not in yarn_lifecycle_phases + command: "yarn run {{ yarn_command }} --verbose" + # Need to set DISPLAY to the value that will be set when the virtual + # framebuffer is set up for doing browser tests. + environment: + DISPLAY: ':99' + args: + chdir: "{{ zuul_work_dir }}" diff --git a/roles/yarn/vars/main.yaml b/roles/yarn/vars/main.yaml new file mode 100644 index 000000000..5343f7036 --- /dev/null +++ b/roles/yarn/vars/main.yaml @@ -0,0 +1,9 @@ +yarn_lifecycle_phases: + - install + - pack + - publish + - restart + - start + - stop + - test + - version