Install yarn if needed in javascript jobs

Some javascript projects use yarn for dependencies instead of raw npm.
If a yarn.lock file is detected in the zuul_work_dir, install yarn and
use yarn to install dependencies.

Needed-By: I5864e1b2f9952fbc35b08ebdef348c4917564c37
Change-Id: I9ae7dd3b33b2b607c1c5a17632e2aeb12e339d15
This commit is contained in:
Monty Taylor 2017-12-11 11:44:22 -06:00
parent b125b917d9
commit a08002fd44
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
9 changed files with 76 additions and 0 deletions

View File

@ -5,6 +5,7 @@
bindep_dir: "{{ zuul_work_dir }}" bindep_dir: "{{ zuul_work_dir }}"
- test-setup - test-setup
- install-nodejs - install-nodejs
- install-yarn
# nodejs-test-dependencies requires sudo, # nodejs-test-dependencies requires sudo,
# so we cannot inherit pre.yaml from javascript-base. # so we cannot inherit pre.yaml from javascript-base.
- nodejs-test-dependencies - nodejs-test-dependencies

View File

@ -5,5 +5,6 @@
bindep_dir: "{{ zuul_work_dir }}" bindep_dir: "{{ zuul_work_dir }}"
- test-setup - test-setup
- install-nodejs - install-nodejs
- install-yarn
- revoke-sudo - revoke-sudo
- install-javascript-packages - install-javascript-packages

View File

@ -1,6 +1,23 @@
- 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 - name: Install npm dependencies
command: npm install --verbose command: npm install --verbose
environment: environment:
DISPLAY: ':99' DISPLAY: ':99'
args: args:
chdir: "{{ zuul_work_dir }}" chdir: "{{ zuul_work_dir }}"
when: not yarn_lock.stat.exists

View File

@ -0,0 +1,8 @@
Install yarn from yarnpkg repos
**Role Variables**
.. zuul:rolevar:: zuul_work_dir
:default: {{ zuul.project.src_dir }}
The directory to work in.

View File

@ -0,0 +1 @@
zuul_work_dir: "{{ zuul.project.src_dir }}"

View File

@ -0,0 +1,14 @@
- name: Add yarnpkg repository key
apt_key:
url: https://dl.yarnpkg.com/debian/pubkey.gpg
become: yes
- name: Add yarnpkg apt source repository
apt_repository:
repo: "deb https://dl.yarnpkg.com/debian/ stable main"
state: present
update_cache: yes
become: yes
- name: Install yarn
include: yarn.yaml

View File

@ -0,0 +1,8 @@
- name: Add yarnpkg repo file
get_url:
url: https://dl.yarnpkg.com/rpm/yarn.repo
dest: /etc/yum.repos.d/yarn.repo
become: yes
- name: Install yarn
include: yarn.yaml

View File

@ -0,0 +1,15 @@
- 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 if needed
include: "{{ item }}"
with_first_found:
- "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml"
when:
- yarn_lock.stat.exists

View File

@ -0,0 +1,11 @@
- name: Install yarn from yarnpkg.com
package:
name: yarn
state: latest
become: yes
tags:
# Ignore ANSIBLE0010: We really want latest version
- skip_ansible_lint
- name: Output yarn version
command: yarn --version