2018-06-10 11:18:20 +02:00
|
|
|
{% set processed_gitdirs = {} %}
|
|
|
|
{% set processed_gitdir_envs = [] %}
|
2014-12-23 16:02:08 +01:00
|
|
|
{% set processed_basedirs = [] %}
|
|
|
|
|
2018-06-10 11:18:20 +02:00
|
|
|
{% from "salt/map.jinja" import formulas_settings with context %}
|
2014-12-23 16:02:08 +01:00
|
|
|
{% from "salt/formulas.jinja" import formulas_git_opt with context %}
|
2018-06-10 11:18:20 +02:00
|
|
|
{% from "salt/formulas.jinja" import formulas_opts_for_git_latest with context %}
|
2014-12-23 16:02:08 +01:00
|
|
|
|
|
|
|
# Loop over all formulas listed in pillar data
|
2016-02-16 16:20:42 +01:00
|
|
|
{% for env, entries in salt['pillar.get']('salt_formulas:list', {}).items() %}
|
2014-12-23 16:02:08 +01:00
|
|
|
{% for entry in entries %}
|
|
|
|
|
2015-09-03 20:56:45 +02:00
|
|
|
{% set basedir = formulas_git_opt(env, 'basedir')|load_yaml %}
|
2015-06-17 16:12:28 +02:00
|
|
|
{% set gitdir = '{0}/{1}'.format(basedir, entry) %}
|
2014-12-23 16:02:08 +01:00
|
|
|
{% set update = formulas_git_opt(env, 'update')|load_yaml %}
|
|
|
|
|
2018-06-10 11:18:20 +02:00
|
|
|
{% if formulas_settings.checkout_orig_branch %}
|
|
|
|
{% if not salt['file.directory_exists']('{0}/{1}'.format(gitdir, '.git')) %}
|
|
|
|
{% set gitdir_branch = '' %}
|
|
|
|
{% else %}
|
|
|
|
{% set gitdir_branch = salt['git.current_branch'](gitdir) %}
|
|
|
|
{% endif %}
|
|
|
|
{% do processed_gitdirs.update({gitdir:gitdir_branch}) %}
|
|
|
|
{% endif %}
|
|
|
|
|
2014-12-23 16:02:08 +01:00
|
|
|
# Setup the directory hosting the Git repository
|
|
|
|
{% if basedir not in processed_basedirs %}
|
|
|
|
{% do processed_basedirs.append(basedir) %}
|
|
|
|
{{ basedir }}:
|
|
|
|
file.directory:
|
|
|
|
{%- for key, value in salt['pillar.get']('salt_formulas:basedir_opts',
|
2015-11-17 02:05:36 +01:00
|
|
|
{'makedirs': True}).items() %}
|
2014-12-23 16:02:08 +01:00
|
|
|
- {{ key }}: {{ value }}
|
|
|
|
{%- endfor %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
# Setup the formula Git repository
|
2018-06-10 11:18:20 +02:00
|
|
|
{% set gitdir_env = '{0}_{1}'.format(gitdir, env) %}
|
|
|
|
{% if gitdir_env not in processed_gitdir_envs %}
|
|
|
|
{% do processed_gitdir_envs.append(gitdir_env) %}
|
|
|
|
{% set options = formulas_opts_for_git_latest(env)|load_yaml %}
|
2016-02-16 16:20:42 +01:00
|
|
|
{% set baseurl = formulas_git_opt(env, 'baseurl')|load_yaml %}
|
2018-06-10 11:18:20 +02:00
|
|
|
|
|
|
|
{{ gitdir_env }}:
|
2014-12-23 16:02:08 +01:00
|
|
|
git.latest:
|
2015-09-03 20:56:45 +02:00
|
|
|
- name: {{ baseurl }}/{{ entry }}.git
|
2014-12-23 16:02:08 +01:00
|
|
|
- target: {{ gitdir }}
|
2015-11-17 02:05:36 +01:00
|
|
|
{%- for key, value in options.items() %}
|
2014-12-23 16:02:08 +01:00
|
|
|
- {{ key }}: {{ value }}
|
|
|
|
{%- endfor %}
|
|
|
|
- require:
|
|
|
|
- file: {{ basedir }}
|
|
|
|
{%- if not update %}
|
|
|
|
- unless: test -e {{ gitdir }}
|
|
|
|
{%- endif %}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}
|
2018-06-10 11:18:20 +02:00
|
|
|
|
|
|
|
{% if formulas_settings.checkout_orig_branch %}
|
|
|
|
# For each directory processed, explicitly checkout the original branch before
|
|
|
|
# the `git.latest` state ran
|
|
|
|
{% for gitdir, original_branch in processed_gitdirs.items() %}
|
|
|
|
{% if original_branch %}
|
|
|
|
{% set gitdir_user = salt['file.get_user'](gitdir) %}
|
|
|
|
checkout_original_branch_for_{{ gitdir }}:
|
|
|
|
module.run:
|
|
|
|
- name: git.checkout
|
|
|
|
- order: last
|
|
|
|
- cwd: {{ gitdir }}
|
|
|
|
- rev: {{ original_branch }}
|
|
|
|
- user: {{ gitdir_user }}
|
|
|
|
- unless: test "$(cd {{ gitdir }}; git rev-parse --abbrev-ref HEAD)" = "{{ original_branch }}"
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|