<commit_before>---
# This Ansible playbook outlines actions taken on the host machine on the
# container after the container is provisioned. It is included in the
# create_container playbook.

- name: Set the location to look for and place build artefacts, and whether or not to clobber the output files.
  set_fact:
    artefact_dir: "{{ container_dir }}/../../artefacts/"
    clobber_output: false

- name: Ensure that a directory is created for build artefacts.
  file:
    name={{ artefact_dir }}
    state=directory

- name: Obtain current tag of this repository, if any.
  shell: git name-rev --tags --name-only HEAD | cut -f1 -d^
  args:
    chdir: "{{ container_dir }}"
    executable: /bin/bash
  register: tag

- name: Obtain current version hash of this repository.
  shell: git rev-parse --short HEAD
  args:
    chdir: "{{ container_dir }}"
    executable: /bin/bash
  register: version

- name: Obtain current branch of this repository.
  shell: git symbolic-ref HEAD | grep -o [^/]*$
  args:
    chdir: "{{ container_dir }}"
    executable: /bin/bash
  register: branch

# Exporting container filesystem as tarball.

- name: Set artefact name with tag, if we could find one.
  set_fact:
    artefact_name: "{{ container_name }}_{{ tag.stdout }}.tar"
  when: tag.stdout != "undefined"

- name: Set artefact name with version hash, if we could not find a tag.
  set_fact:
    artefact_name: "{{ container_name }}_{{ version.stdout }}.tar"
  when: tag.stdout == "undefined"

- name: Export the container filesystem as an artefact.
  command: docker export --output={{ artefact_dir }}{{ artefact_name }} {{ container_name }}
  args:
    creates: "{{ artefact_dir }}{{ artefact_name }}"

# Storing container with tag=branch.

- name: Define the name used for the output Docker image using the branch.
  set_fact:
    output_image_name_branch: virtualmicromagnetics/{{ container_name }}:{{ branch.stdout }}<commit_msg>Allow Ansible to obtain the Git branch name when building on Jenkins (with a detached head).<commit_after>---
# This Ansible playbook outlines actions taken on the host machine on the
# container after the container is provisioned. It is included in the
# create_container playbook.

- name: Set the location to look for and place build artefacts, and whether or not to clobber the output files.
  set_fact:
    artefact_dir: "{{ container_dir }}/../../artefacts/"
    clobber_output: false

- name: Ensure that a directory is created for build artefacts.
  file:
    name={{ artefact_dir }}
    state=directory

- name: Obtain current tag of this repository, if any.
  shell: git name-rev --tags --name-only HEAD | cut -f1 -d^
  args:
    chdir: "{{ container_dir }}"
    executable: /bin/bash
  register: tag

- name: Obtain current version hash of this repository.
  shell: git rev-parse --short HEAD
  args:
    chdir: "{{ container_dir }}"
    executable: /bin/bash
  register: version

- name: Obtain current branch of this repository. Does not work in detached-head state.
  shell: git symbolic-ref HEAD | grep -o [^/]*$
  args:
    chdir: "{{ container_dir }}"
    executable: /bin/bash
  register: branch
  when: ("{{ lookup('env','GIT_BRANCH') }}" == "")

# Alternatively, we can obtain the branch in detached-head state using the
# environment variable GIT_BRANCH if it is set. This helps out Jenkins.
- name: Obtain current branch of this repository using GIT_BRANCH environment variable.
  shell: echo $GIT_BRANCH
  args:
    chdir: "{{ container_dir }}"
    executable: /bin/bash
  register: branch
  when: ("{{ lookup('env','GIT_BRANCH') }}" == "")

# Exporting container filesystem as tarball.

- name: Set artefact name with tag, if we could find one.
  set_fact:
    artefact_name: "{{ container_name }}_{{ tag.stdout }}.tar"
  when: tag.stdout != "undefined"

- name: Set artefact name with version hash, if we could not find a tag.
  set_fact:
    artefact_name: "{{ container_name }}_{{ version.stdout }}.tar"
  when: tag.stdout == "undefined"

- name: Export the container filesystem as an artefact.
  command: docker export --output={{ artefact_dir }}{{ artefact_name }} {{ container_name }}
  args:
    creates: "{{ artefact_dir }}{{ artefact_name }}"

# Storing container with tag=branch.

- name: Define the name used for the output Docker image using the branch.
  set_fact:
    output_image_name_branch: virtualmicromagnetics/{{ container_name }}:{{ branch.stdout }}
{'fraction_non_alphanumeric': 0.11173942546935083, 'fraction_numerical': 0.00045238633793259444, 'mean_word_length': 3.6206896551724137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '735668', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1352, 'n_words': 504}