Add base job and roles for javascript
This is in service of getting javascript tarball jobs going. Change-Id: I20b4b4ce0bdf03c5585ca73471611178c94e2599
This commit is contained in:
parent
d577763697
commit
ad1ce4fc2f
3
playbooks/javascript/post.yaml
Normal file
3
playbooks/javascript/post.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
- hosts: all
|
||||
roles:
|
||||
- fetch-javascript-output
|
9
playbooks/javascript/pre.yaml
Normal file
9
playbooks/javascript/pre.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
- hosts: all
|
||||
roles:
|
||||
- role: bindep
|
||||
bindep_profile: test
|
||||
bindep_dir: "{{ zuul_work_dir }}"
|
||||
- test-setup
|
||||
- install-nodejs
|
||||
- revoke-sudo
|
||||
- install-javascript-packages
|
4
playbooks/javascript/tarball.yaml
Normal file
4
playbooks/javascript/tarball.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
- hosts: all
|
||||
roles:
|
||||
- role: npm
|
||||
npm_command: pack
|
8
roles/fetch-javascript-output/README.rst
Normal file
8
roles/fetch-javascript-output/README.rst
Normal file
@ -0,0 +1,8 @@
|
||||
Collect logs from a javascript build
|
||||
|
||||
**Role Variables**
|
||||
|
||||
.. zuul:rolevar:: zuul_work_dir
|
||||
:default: {{ zuul.project.src_dir }}
|
||||
|
||||
Directory to work in
|
1
roles/fetch-javascript-output/defaults/main.yaml
Normal file
1
roles/fetch-javascript-output/defaults/main.yaml
Normal file
@ -0,0 +1 @@
|
||||
zuul_work_dir: "{{ zuul.project.src_dir }}"
|
62
roles/fetch-javascript-output/tasks/main.yaml
Normal file
62
roles/fetch-javascript-output/tasks/main.yaml
Normal file
@ -0,0 +1,62 @@
|
||||
- name: Set log path for multiple nodes
|
||||
set_fact:
|
||||
log_path: "{{ zuul.executor.log_root }}/{{ inventory_hostname }}/npm"
|
||||
when: groups['all'] | length > 1
|
||||
|
||||
- name: Set log path for single node
|
||||
set_fact:
|
||||
log_path: "{{ zuul.executor.log_root }}/npm"
|
||||
when: log_path is not defined
|
||||
|
||||
- name: Ensure local tox dir
|
||||
file:
|
||||
path: "{{ log_path }}"
|
||||
state: directory
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Check for shrinkwrap
|
||||
stat:
|
||||
path: "{{ zuul_work_dir }}/npm-shrinkwrap.json"
|
||||
register: shrinkwrap
|
||||
|
||||
- name: Run npm prune because of https://github.com/npm/npm/issues/6298
|
||||
when: not shrinkwrap.stat.exists
|
||||
command: npm prune
|
||||
environment:
|
||||
DISPLAY: ':99'
|
||||
args:
|
||||
chdir: "{{ zuul_work_dir }}"
|
||||
|
||||
- name: Run npm shrinkwrap
|
||||
when: not shrinkwrap.stat.exists
|
||||
command: npm shrinkwrap
|
||||
environment:
|
||||
DISPLAY: ':99'
|
||||
args:
|
||||
chdir: "{{ zuul_work_dir }}"
|
||||
|
||||
- name: Check for reports
|
||||
stat:
|
||||
path: "{{ zuul_work_dir }}/reports"
|
||||
register: reports_stat
|
||||
|
||||
- name: Collect npm reports
|
||||
synchronize:
|
||||
dest: "{{ log_path }}"
|
||||
mode: pull
|
||||
src: "{{ zuul_work_dir }}/reports"
|
||||
verify_host: true
|
||||
when: reports_stat.stat.exists
|
||||
|
||||
- name: Check for karma.subunit files
|
||||
stat:
|
||||
path: "{{ zuul_work_dir }}/karma.subunit"
|
||||
register: karma_stat
|
||||
|
||||
- name: Collect karma subunit files
|
||||
synchronize:
|
||||
dest: "{{ log_path }}"
|
||||
mode: pull
|
||||
src: "{{ zuul_work_dir }}/karma.subunit"
|
||||
verify_host: true
|
||||
when: karma_stat.stat.exists
|
8
roles/fetch-javascript-tarball/README.rst
Normal file
8
roles/fetch-javascript-tarball/README.rst
Normal file
@ -0,0 +1,8 @@
|
||||
Fetch a Javascript tarball back to be published.
|
||||
|
||||
**Role Variables**
|
||||
|
||||
.. zuul:rolevar:: zuul_work_dir
|
||||
:default: {{ zuul.project.src_dir }}
|
||||
|
||||
Directory to run npm in.
|
1
roles/fetch-javascript-tarball/defaults/main.yaml
Normal file
1
roles/fetch-javascript-tarball/defaults/main.yaml
Normal file
@ -0,0 +1 @@
|
||||
zuul_work_dir: "{{ zuul.project.src_dir }}"
|
20
roles/fetch-javascript-tarball/tasks/main.yaml
Normal file
20
roles/fetch-javascript-tarball/tasks/main.yaml
Normal file
@ -0,0 +1,20 @@
|
||||
- name: Rename tarball for uploading
|
||||
shell: |
|
||||
mkdir -p dist
|
||||
cp *.tgz dist/{{ zuul.project.short_name }}-{{ project_ver }}.tar.gz
|
||||
cp *.tgz dist/{{ zuul.project.short_name }}-latest.tar.gz
|
||||
args:
|
||||
chdir: "{{ zuul_work_dir }}"
|
||||
|
||||
- name: Ensure artifacts directory exists
|
||||
file:
|
||||
path: "{{ zuul.executor.work_root }}/artifacts"
|
||||
state: directory
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Collect artifacts
|
||||
synchronize:
|
||||
dest: "{{ zuul.executor.work_root }}/artifacts/"
|
||||
mode: pull
|
||||
src: "{{ zuul_work_dir }}/dist/"
|
||||
verify_host: true
|
8
roles/install-javascript-packages/README.rst
Normal file
8
roles/install-javascript-packages/README.rst
Normal file
@ -0,0 +1,8 @@
|
||||
Install javascript dependencies needed for a project
|
||||
|
||||
**Role Variables**
|
||||
|
||||
.. zuul:rolevar:: zuul_work_dir
|
||||
:default: {{ zuul.project.src_dir }}
|
||||
|
||||
The directory to work in.
|
1
roles/install-javascript-packages/defaults/main.yaml
Normal file
1
roles/install-javascript-packages/defaults/main.yaml
Normal file
@ -0,0 +1 @@
|
||||
zuul_work_dir: "{{ zuul.project.src_dir }}"
|
6
roles/install-javascript-packages/tasks/main.yaml
Normal file
6
roles/install-javascript-packages/tasks/main.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
- name: Install npm dependencies
|
||||
command: npm install --verbose
|
||||
environment:
|
||||
DISPLAY: ':99'
|
||||
args:
|
||||
chdir: "{{ zuul_work_dir }}"
|
6
roles/install-nodejs/README.rst
Normal file
6
roles/install-nodejs/README.rst
Normal file
@ -0,0 +1,6 @@
|
||||
Install NodeJS from nodesource
|
||||
|
||||
**Role Variables**
|
||||
|
||||
.. zuul:rolevar:: node_version
|
||||
:default: 6
|
2
roles/install-nodejs/defaults/main.yaml
Normal file
2
roles/install-nodejs/defaults/main.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
---
|
||||
node_version: 6
|
40
roles/install-nodejs/tasks/main.yaml
Normal file
40
roles/install-nodejs/tasks/main.yaml
Normal file
@ -0,0 +1,40 @@
|
||||
- name: Update apt cache
|
||||
apt:
|
||||
update_cache: yes
|
||||
become: yes
|
||||
|
||||
- name: Install prereqs
|
||||
package:
|
||||
name: apt-transport-https
|
||||
state: present
|
||||
become: yes
|
||||
|
||||
- name: Add nodesource repository key
|
||||
apt_key:
|
||||
url: "https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
|
||||
become: yes
|
||||
|
||||
- name: Add nodesource apt source repository
|
||||
apt_repository:
|
||||
repo: "deb-src https://deb.nodesource.com/node_{{ node_version }}.x {{ ansible_distribution_release }} main"
|
||||
state: present
|
||||
become: yes
|
||||
|
||||
- name: Add nodesource apt repository
|
||||
apt_repository:
|
||||
repo: "deb https://deb.nodesource.com/node_{{ node_version }}.x {{ ansible_distribution_release }} main"
|
||||
state: present
|
||||
update_cache: yes
|
||||
become: yes
|
||||
|
||||
- name: Install NodeJS from nodesource
|
||||
package:
|
||||
name: nodejs
|
||||
state: latest
|
||||
become: yes
|
||||
|
||||
- name: Output node version
|
||||
command: node --version
|
||||
|
||||
- name: Output npm version
|
||||
command: npm --version
|
15
roles/npm/README.rst
Normal file
15
roles/npm/README.rst
Normal file
@ -0,0 +1,15 @@
|
||||
Run npm command in a source directory. Assumes the appropriate version
|
||||
of npm has been installed.
|
||||
|
||||
**Role Variables**
|
||||
|
||||
.. zuul:rolevar:: npm_command
|
||||
|
||||
Command to run. If it's a standard npm lifecycle command, it will be run as
|
||||
``npm {{ npm_command }}``. Otherwise it will be run as
|
||||
``npm run {{ npm_command }}``.
|
||||
|
||||
.. zuul:rolevar:: zuul_work_dir
|
||||
:default: {{ zuul.project.src_dir }}
|
||||
|
||||
Directory to run npm in.
|
1
roles/npm/defaults/main.yaml
Normal file
1
roles/npm/defaults/main.yaml
Normal file
@ -0,0 +1 @@
|
||||
zuul_work_dir: "{{ zuul.project.src_dir }}"
|
24
roles/npm/tasks/main.yaml
Normal file
24
roles/npm/tasks/main.yaml
Normal file
@ -0,0 +1,24 @@
|
||||
- name: Require npm_command variable
|
||||
fail:
|
||||
msg: npm_command is required for this role
|
||||
when: npm_command is not defined
|
||||
|
||||
- name: Run npm lifecycle command
|
||||
when: npm_command in npm_lifecycle_phases
|
||||
command: "npm {{ npm_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 npm custom command
|
||||
when: npm_command not in npm_lifecycle_phases
|
||||
command: "npm run {{ npm_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 }}"
|
9
roles/npm/vars/main.yaml
Normal file
9
roles/npm/vars/main.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
npm_lifecycle_phases:
|
||||
- install
|
||||
- pack
|
||||
- publish
|
||||
- restart
|
||||
- start
|
||||
- stop
|
||||
- test
|
||||
- version
|
20
roles/version-from-git/README.rst
Normal file
20
roles/version-from-git/README.rst
Normal file
@ -0,0 +1,20 @@
|
||||
Sets three facts based on information in a git repo.
|
||||
|
||||
scm_sha
|
||||
The short sha found in the repository.
|
||||
|
||||
project_ver
|
||||
A string describing the project's version. It will either be the value of
|
||||
{{ zuul.tag }} or {{ scm_tag }}.{{ commits_since_tag }}.{{ scm_sha }}
|
||||
otherwise where ``scm_tag`` is either the most recent tag or the value of
|
||||
``scm_sha`` if there are no commits in the repo.
|
||||
|
||||
commits_since_tag
|
||||
Number of commits since the most recent tag.
|
||||
|
||||
**Role Variables**
|
||||
|
||||
.. zuul:rolevar:: zuul_work_dir
|
||||
:default: {{ zuul.project.src_dir }}
|
||||
|
||||
Directory to run git in.
|
1
roles/version-from-git/defaults/main.yaml
Normal file
1
roles/version-from-git/defaults/main.yaml
Normal file
@ -0,0 +1 @@
|
||||
zuul_work_dir: "{{ zuul.project.src_dir }}"
|
56
roles/version-from-git/tasks/main.yaml
Normal file
56
roles/version-from-git/tasks/main.yaml
Normal file
@ -0,0 +1,56 @@
|
||||
- name: Get SCM_SHA info
|
||||
command: git rev-parse --short HEAD
|
||||
failed_when: false
|
||||
register: scm_sha_output
|
||||
args:
|
||||
chdir: "{{ zuul_work_dir }}"
|
||||
|
||||
- name: Set scm_sha fact
|
||||
set_fact:
|
||||
scm_sha: "{{ scm_sha_output.stdout }}"
|
||||
|
||||
- name: Get SCM_TAG info
|
||||
command: git describe --abbrev=0 --tags
|
||||
failed_when: false
|
||||
register: scm_tag_output
|
||||
when: zuul.tag is not defined
|
||||
args:
|
||||
chdir: "{{ zuul_work_dir }}"
|
||||
|
||||
- name: Set scm_sha fact from output
|
||||
set_fact:
|
||||
scm_tag: "{{ scm_tag_output.stdout }}"
|
||||
when: zuul.tag is not defined and scm_tag_output.stdout
|
||||
|
||||
- name: Set scm_tag fact from zuul
|
||||
set_fact:
|
||||
scm_tag: "{{ zuul.tag }}"
|
||||
when: zuul.tag is defined
|
||||
|
||||
- name: Use git sha if there is no tag
|
||||
set_fact:
|
||||
scm_tag: "{{ scm_sha }}"
|
||||
when: zuul.tag is not defined and not scm_tag_output.stdout
|
||||
|
||||
- name: Get commits since tag
|
||||
# assumes format is like this '0.0.4-2-g135721c'
|
||||
shell: |
|
||||
git describe | awk '{split($0,a,"-"); print a[2]}'
|
||||
failed_when: false
|
||||
register: commits_since_tag_output
|
||||
args:
|
||||
chdir: "{{ zuul_work_dir }}"
|
||||
|
||||
- name: Set commits_since_tag fact
|
||||
set_fact:
|
||||
commits_since_tag: "{{ commits_since_tag_output.stdout }}"
|
||||
|
||||
- name: Set project_ver to scm_tag if there are no commits
|
||||
when: not commits_since_tag
|
||||
set_fact:
|
||||
project_ver: "{{ scm_tag }}"
|
||||
|
||||
- name: Set project_ver if there are commits since the tag
|
||||
when: not commits_since_tag
|
||||
set_fact:
|
||||
project_ver: "{{ scm_tag }}.{{ commits_since_tag }}.{{ scm_sha }}"
|
39
zuul.yaml
39
zuul.yaml
@ -167,3 +167,42 @@
|
||||
Do additional setup needed for multi-node jobs such as setting up
|
||||
overlay networks and setting up known-hosts and ssh keys
|
||||
pre-run: playbooks/multinode/pre
|
||||
|
||||
- job:
|
||||
name: javascript-base
|
||||
description: |
|
||||
Base job for javascript operations
|
||||
|
||||
Responds to these variables:
|
||||
|
||||
.. zuul:jobvar:: node_version
|
||||
:default: 6
|
||||
|
||||
The version of Node to use.
|
||||
|
||||
.. zuul:jobvar: zuul_work_dir
|
||||
:default: {{ zuul.project.src_dir }}
|
||||
|
||||
Path to operate in.
|
||||
pre-run: playbooks/javascript/pre
|
||||
post-run: playbooks/javascript/post
|
||||
|
||||
- job:
|
||||
name: build-javascript-tarball
|
||||
parent: javascript-base
|
||||
description: |
|
||||
Build a source tarball for a Javascript project
|
||||
|
||||
Responds to these variables:
|
||||
|
||||
.. zuul:jobvar:: node_version
|
||||
:default: 6
|
||||
|
||||
The version of Node to use.
|
||||
|
||||
.. zuul:jobvar: zuul_work_dir
|
||||
:default: {{ zuul.project.src_dir }}
|
||||
|
||||
Path to operate in.
|
||||
|
||||
run: playbooks/javascript/tarball
|
||||
|
Loading…
Reference in New Issue
Block a user