2019-02-14 16:39:01 +01:00
|
|
|
{%- set processed_gitdirs = {} %}
|
|
|
|
{%- set processed_gitdir_envs = [] %}
|
|
|
|
{%- set processed_basedirs = [] %}
|
2014-12-23 16:02:08 +01:00
|
|
|
|
2019-02-14 16:39:01 +01:00
|
|
|
{%- from "salt/map.jinja" import formulas_settings with context %}
|
|
|
|
{%- from "salt/formulas.jinja" import formulas_git_opt with context %}
|
|
|
|
{%- from "salt/formulas.jinja" import formulas_opts_for_git_latest with context %}
|
2014-12-23 16:02:08 +01:00
|
|
|
|
2019-08-01 13:52:46 +02:00
|
|
|
## from template-formula
|
|
|
|
{%- set tplroot = tpldir.split('/')[0] %}
|
|
|
|
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
|
|
|
|
|
2014-12-23 16:02:08 +01:00
|
|
|
# Loop over all formulas listed in pillar data
|
2019-02-14 16:39:01 +01:00
|
|
|
{%- for env, entries in salt['pillar.get']('salt_formulas:list', {}).items() %}
|
|
|
|
{%- for entry in entries %}
|
2019-06-07 06:40:05 +02:00
|
|
|
{%- set f_name = entry | first if entry is mapping else entry %}
|
|
|
|
{%- set f_opts = entry[f_name] if entry is mapping else {} %}
|
2014-12-23 16:02:08 +01:00
|
|
|
|
2019-02-14 16:39:01 +01:00
|
|
|
{%- set basedir = formulas_git_opt(env, 'basedir')|load_yaml %}
|
2019-06-07 06:40:05 +02:00
|
|
|
{%- set gitdir = '{0}/{1}'.format(basedir, f_name) %}
|
2019-02-14 16:39:01 +01:00
|
|
|
{%- set update = formulas_git_opt(env, 'update')|load_yaml %}
|
2014-12-23 16:02:08 +01:00
|
|
|
|
2019-02-14 16:39:01 +01: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 %}
|
2018-06-10 11:18:20 +02:00
|
|
|
|
2014-12-23 16:02:08 +01:00
|
|
|
# Setup the directory hosting the Git repository
|
2019-02-14 16:39:01 +01:00
|
|
|
{%- if basedir not in processed_basedirs %}
|
|
|
|
{%- do processed_basedirs.append(basedir) %}
|
2014-12-23 16:02:08 +01:00
|
|
|
{{ basedir }}:
|
|
|
|
file.directory:
|
2020-09-11 23:03:25 +02:00
|
|
|
- parallel: {{ salt_settings.parallel }}
|
2019-02-15 05:28:51 +01:00
|
|
|
{%- for key, value in salt['pillar.get']('salt_formulas:basedir_opts',
|
|
|
|
{'makedirs': True}).items() %}
|
2014-12-23 16:02:08 +01:00
|
|
|
- {{ key }}: {{ value }}
|
2019-08-01 13:52:46 +02:00
|
|
|
- user: {{ salt_settings.rootuser }}
|
|
|
|
- group: {{ salt_settings.rootgroup }}
|
2019-02-14 16:39:01 +01:00
|
|
|
{%- endfor %}
|
|
|
|
{%- endif %}
|
2014-12-23 16:02:08 +01:00
|
|
|
|
|
|
|
# Setup the formula Git repository
|
2019-02-14 16:39:01 +01: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 %}
|
2019-06-07 06:40:05 +02:00
|
|
|
{%- do options.update(f_opts) %}
|
2019-02-14 16:39:01 +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:
|
2019-06-07 06:40:05 +02:00
|
|
|
- name: {{ baseurl }}/{{ f_name }}.git
|
2020-09-11 23:03:25 +02:00
|
|
|
- parallel: {{ salt_settings.parallel }}
|
2014-12-23 16:02:08 +01:00
|
|
|
- target: {{ gitdir }}
|
2019-02-14 16:39:01 +01:00
|
|
|
{%- for key, value in options.items() %}
|
2014-12-23 16:02:08 +01:00
|
|
|
- {{ key }}: {{ value }}
|
2019-02-14 16:39:01 +01:00
|
|
|
{%- endfor %}
|
2019-02-15 05:28:51 +01:00
|
|
|
{%- if not update %}
|
2019-04-17 00:56:08 +02:00
|
|
|
- unless: test -e {{ gitdir }} >/dev/null 2>&1
|
2019-02-15 05:28:51 +01:00
|
|
|
{%- endif %}
|
2019-02-14 16:39:01 +01:00
|
|
|
{%- endif %}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- endfor %}
|
2018-06-10 11:18:20 +02:00
|
|
|
|
2019-02-14 16:39:01 +01:00
|
|
|
{%- if formulas_settings.checkout_orig_branch %}
|
2018-06-10 11:18:20 +02:00
|
|
|
# For each directory processed, explicitly checkout the original branch before
|
|
|
|
# the `git.latest` state ran
|
2019-02-14 16:39:01 +01:00
|
|
|
{%- for gitdir, original_branch in processed_gitdirs.items() %}
|
|
|
|
{%- if original_branch %}
|
|
|
|
{%- set gitdir_user = salt['file.get_user'](gitdir) %}
|
2018-06-10 11:18:20 +02:00
|
|
|
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 }}"
|
2019-02-14 16:39:01 +01:00
|
|
|
{%- endif %}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- endif %}
|