zuul-jobs/roles/version-from-git/tasks/main.yaml
Ian Wienand 6d23d20f2f linters: add names to blocks
This is preparation for a later version of ansbile-lint, which finds
missing names on blocks.  This seems a reasonable rule, and the
Ansible manual says [1]

  Names for blocks have been available since Ansible 2.3. We recommend
  using names in all tasks, within blocks or elsewhere, for better
  visibility into the tasks being executed when you run the playbook.

This simply adds a name tag for blocks that are missing it.  This
should have no operational change, but allows us to update the linter
in a follow-on change.

[1] https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html

Change-Id: I92ed4616775650aced352bc9088a07e919f1a25f
2022-07-27 17:13:39 +10:00

91 lines
2.6 KiB
YAML

- name: Get SCM_SHA info
command: git rev-parse --short HEAD
failed_when: false
register: scm_sha_output
args:
chdir: "{{ zuul_work_dir }}"
# ANSIBLE0006: Skip linting since it triggers on the "git" command,
# but rev-parse is not supported by ansible git module.
tags:
- skip_ansible_lint
- name: Set scm_sha fact
set_fact:
scm_sha: "{{ scm_sha_output.stdout }}"
- name: Get SCM_TAG info
command: git describe --abbrev=0 --tags
failed_when: false
register: scm_tag_output
when: zuul.tag is not defined
args:
chdir: "{{ zuul_work_dir }}"
# ANSIBLE0006: Skip linting since it triggers on the "git" command,
# but describe is not supported by ansible git module.
tags:
- skip_ansible_lint
- name: Set scm_sha fact from output
set_fact:
scm_tag: "{{ scm_tag_output.stdout }}"
when: zuul.tag is not defined and scm_tag_output.stdout
- name: Set scm_tag fact from zuul
set_fact:
scm_tag: "{{ zuul.tag }}"
when: zuul.tag is defined
- name: Use git sha if there is no tag
set_fact:
scm_tag: "{{ scm_sha }}"
when: zuul.tag is not defined and not scm_tag_output.stdout
- name: Get commits since tag
# assumes format is like this '0.0.4-2-g135721c'
shell: |
git describe | awk '{split($0,a,"-"); print a[2]}'
failed_when: false
register: commits_since_tag_output
args:
chdir: "{{ zuul_work_dir }}"
# ANSIBLE0006: Skip linting since it triggers on the "git" command,
# but describe is not supported by ansible git module.
tags:
- skip_ansible_lint
- name: Set commits_since_tag fact
when: commits_since_tag_output.rc == 0
set_fact:
commits_since_tag: "{{ commits_since_tag_output.stdout }}"
# Some repos, like storyboard-webclient, do not have any tags. git describe
# throws an error in those repos. To be consistent, do a commit count the
# hard way.
- name: Get commits
when: commits_since_tag_output.rc != 0
block:
- name: Get commits since the beginning
command: git rev-list HEAD --count
register: commits_since_beginning
args:
chdir: "{{ zuul_work_dir }}"
# ANSIBLE0006: Skip linting since it triggers on the "git" command,
# but rev-list is not supported by ansible git module.
tags:
- skip_ansible_lint
- name: Set commits_since_tag fact
set_fact:
commits_since_tag: "{{ commits_since_beginning.stdout }}"
- name: Set project_ver to scm_tag if there are no commits
when: not commits_since_tag
set_fact:
project_ver: "{{ scm_tag }}"
- name: Set project_ver if there are commits since the tag
when: commits_since_tag
set_fact:
project_ver: "{{ scm_tag }}.{{ commits_since_tag }}.{{ scm_sha }}"