Sort jobs in molecule.yaml file when adding new role

This patch adds a mechanism to keep the job names in
zuul.d/molecule.yaml sorted. Therefore, the to_nice_yaml filter is not
indenting lists correctly, due to [1][2].

[1] https://github.com/ansible/ansible/issues/48865
[2] https://github.com/yaml/pyyaml/issues/234

Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
Change-Id: Ia8f787631c55fabb3a097919971d17b93711d4b7
(cherry picked from commit ae59abe62c)
(cherry picked from commit cc29577f73)
This commit is contained in:
Gael Chamoulaud (Strider) 2021-06-24 13:06:43 +02:00
parent 04c08718e6
commit da801771af
No known key found for this signature in database
GPG Key ID: 4119D0305C651D66
1 changed files with 7 additions and 2 deletions

View File

@ -120,6 +120,8 @@
- name: Create molecule entry
copy:
content: |-
# Managed via ./role-addition.yml, do not edit manually without testing that
# new role addition does not reformat it.
---
{% set items = molecule_yaml['content'] | b64decode | from_yaml %}
{% set job_index = [] %}
@ -158,11 +160,14 @@
"vars": {
"tripleo_validations_role_name": validation_init_prefix ~ "_" ~ _role_name
}
}
}
%}
{% set _ = items.append({"job": new_job}) %}
{% endif %}
{{ items | to_nice_yaml(indent=2, width=1337) }}
{% set project = items.pop(0) %}
{% set sorted_jobs = items | sort(attribute='job.name') %}
{% set _ = sorted_jobs.insert(0, project) %}
{{ sorted_jobs | to_nice_yaml(indent=2, width=1337) }}
dest: "{{ validation_init_zuuld_molecule }}"
- name: Create role documentation