Clark Boylan 8fed1dfaa6 Test speedup change to prepare-workspace-git
The child change to prepare-workspace-git explains this in more detail.
We're reducing the number of ansible loops these roles run to reduce
ansible task startup overhead and speed up the role. This change is made
first to the test role so that we can ensure this all works properly
before affecting production zuul installs.

Change-Id: I3d33bb0001e65f449e1026ed323514097088f664
2022-09-22 11:08:48 -07:00

33 lines
1.3 KiB
YAML

# Do all the steps in a single shell script. This reduces the number of times
# ansible must loop over the list of projects which reduces the amount of
# task startup time we incur.
- name: Set initial repo states in workspace
shell: |
set -ex
if [ -d "{{ cached_repos_root }}/{{ zj_project.canonical_name }}" ] ; then
# We do a bare clone here first so that we skip creating a working
# copy that will be overwritten later anyway.
git clone --bare {{ cached_repos_root }}/{{ zj_project.canonical_name }} {{ ansible_user_dir }}/{{ zj_project.src_dir }}/.git
else
git init {{ ansible_user_dir }}/{{ zj_project.src_dir }}
fi
cd {{ ansible_user_dir }}/{{ zj_project.src_dir }}
git config --local --bool core.bare false
git remote -v | grep origin && git remote rm origin || true
git remote add origin file:///dev/null
args:
creates: "{{ ansible_user_dir }}/{{ zj_project.src_dir }}"
with_items: "{{ zuul.projects.values() | list }}"
loop_control:
loop_var: zj_project
# We're using git in a shell script because it is faster and the module
# doesn't support features we need.
tags:
- skip_ansible_lint
# TODO(tobiash): we might want to deprecate the role mirror-workspace-git-repos
# and move it here.
- name: Synchronize repos
import_role:
name: test-mirror-workspace-git-repos