fetch-javascript-tarball: introduce zuul_use_fetch_output

This change enables using fetch-javascript role along with
the fetch-output role. By default the role still synchronizes
artifacts back to the executor.

Change-Id: I8450ecf91b3387445ebe2436754d1b88f2a77844
This commit is contained in:
Tristan Cacqueray 2019-09-11 20:39:49 +00:00
parent be8308c7ac
commit 9204e7d1d8
5 changed files with 74 additions and 14 deletions

View File

@ -6,3 +6,11 @@ Fetch a Javascript tarball back to be published.
:default: {{ zuul.project.src_dir }}
Directory to run npm in.
.. zuul:rolevar:: zuul_use_fetch_output
:default: false
Whether to synchronize files to the executor work dir, or to copy them
on the test instance.
When set to false, the role synchronizes the file to the executor.
When set to true, the job needs to use the fetch-output role later.

View File

@ -1 +1,3 @@
zuul_work_dir: "{{ zuul.project.src_dir }}"
zuul_output_dir: "{{ ansible_user_dir }}/zuul-output"
zuul_use_fetch_output: "{{ zuul_site_use_fetch_output|default(false) }}"

View File

@ -1,23 +1,25 @@
- 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
mkdir -p {{ zuul_output_dir }}/artifacts
cp *.tgz {{ zuul_output_dir }}/artifacts/{{ zuul.project.short_name }}-{{ project_ver }}.tar.gz
cp *.tgz {{ zuul_output_dir }}/artifacts/{{ zuul.project.short_name }}-latest.tar.gz
args:
chdir: "{{ zuul_work_dir }}"
tags:
# Ignore ANSIBLE0007: No need to use file module instead of mkdir
- skip_ansible_lint
- name: Ensure artifacts directory exists
file:
path: "{{ zuul.executor.work_root }}/artifacts"
state: directory
delegate_to: localhost
- block:
- 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
- name: Collect artifacts
synchronize:
dest: "{{ zuul.executor.work_root }}/artifacts/"
mode: pull
src: "{{ zuul_output_dir }}/artifacts/"
verify_host: true
when: not zuul_use_fetch_output

View File

@ -0,0 +1,26 @@
- hosts: all
pre_tasks:
- name: Create fake tarball
shell: |
mkdir -p {{ zuul.project.src_dir }}
tar czf {{ zuul.project.src_dir }}/dist.tgz /etc/os-release
tasks:
- import_role:
name: fetch-javascript-tarball
vars:
project_ver: master
- import_role:
name: fetch-output
when: zuul_use_fetch_output
post_tasks:
- name: Check for artifact on the test instance
stat:
path: "{{ ansible_user_dir }}/zuul-output/artifacts/zuul-jobs-latest.tar.gz"
register: _test_artifact
failed_when: not _test_artifact.stat.exists
- name: Check for artifact on the executor
stat:
path: "{{ zuul.executor.work_root }}/artifacts/zuul-jobs-latest.tar.gz"
delegate_to: localhost
register: _executor_artifact
failed_when: not _executor_artifact.stat.exists

View File

@ -7,6 +7,26 @@
vars:
role_name: install-nodejs
- job:
name: zuul-jobs-test-fetch-javascript-tarball
description: Test the fetch-javascript-tarball
files:
- roles/fetch-javascript-tarball/.*
- roles/fetch-output/.*
run: test-playbooks/javascripts/fetch-javascript-tarball.yaml
vars:
zuul_use_fetch_output: true
- job:
name: zuul-jobs-test-fetch-javascript-tarball-synchronize
description: Test the fetch-javascript-tarball without fetch-output
files:
- roles/fetch-javascript-tarball/.*
run: test-playbooks/javascripts/fetch-javascript-tarball.yaml
vars:
zuul_use_fetch_output: false
# -* AUTOGENERATED *-
# The following project section is autogenerated by
# tools/update-test-platforms.py
@ -16,5 +36,7 @@
check:
jobs: &id001
- zuul-jobs-test-install-nodejs
- zuul-jobs-test-fetch-javascript-tarball
- zuul-jobs-test-fetch-javascript-tarball-synchronize
gate:
jobs: *id001