Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor build-release role tests.yml #432

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/antsibull-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
python3 -m pip install poetry ansible-core
poetry install
poetry update
ansible-galaxy collection install 'git+https://github.com/ansible-collections/community.general.git'
working-directory: antsibull

- name: "Test building a release: ${{ matrix.name }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
breaking_changes:
- The ``build-release`` role now depends on the ``community.general`` collection (https://github.com/ansible-community/antsibull/pull/432).
minor_changes:
- Perform minor refactoring of the ``build-release`` role, mostly concerning ``tasks/tests.yml``. This reduces use of ``shell`` and ``set_fact``, makes the role more robust, and replaces short names with FQCNs (https://github.com/ansible-community/antsibull/pull/432).
2 changes: 1 addition & 1 deletion playbooks/build-single-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
gather_facts: no
tasks:
- name: Include build-release role
include_role:
ansible.builtin.include_role:
name: build-release
12 changes: 6 additions & 6 deletions playbooks/nested-ansible-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
register: _parsed_runtime

- name: Validate collection availability
assert:
ansible.builtin.assert:
that:
- query("community.general.collection_version", item) != [none]
success_msg: "{{ item }}: available"
Expand All @@ -27,7 +27,7 @@
register: _collection_availability

- name: Validate module availability
assert:
ansible.builtin.assert:
that:
- item is community.general.a_module
success_msg: "{{ item }}: found"
Expand All @@ -37,16 +37,16 @@
register: _module_availability

- name: Retrieve unavailable collections and modules
set_fact:
ansible.builtin.set_fact:
_unavailable_collections: "{{ _collection_availability.results | selectattr('failed', '==', true) | selectattr('item', '!=', 'testns.testcoll') }}"
_unavailable_modules: "{{ _module_availability.results | selectattr('failed', '==', true) | selectattr('item', '!=', 'testns.testcoll.ping') }}"

- name: Print unavailable collections
debug:
ansible.builtin.debug:
msg: "The following collections are not available: {{ _unavailable_collections | map(attribute='item') | join(', ') }}"

- name: Print unavailable modules
debug:
ansible.builtin.debug:
msg: "The following modules are not available: {{ _unavailable_modules | map(attribute='item') | join(', ') }}"

- name: Clone the ansible git repository
Expand All @@ -60,6 +60,6 @@
environment:
ANSIBLE_ROLES_PATH: "{{ antsibull_ansible_git_dir }}/test/integration/targets"
# Note: this didn't work prior to ansible-base 2.10.4: https://github.com/ansible/ansible/pull/71824
command: >-
ansible.builtin.command: >-
{{ antsibull_ansible_venv }}/bin/ansible -vv localhost -m include_role -a "name=include_vars"
changed_when: false
16 changes: 8 additions & 8 deletions roles/build-release/tasks/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
register: _antsibull_build_file_stat

- name: Allow prereleases for alpha versions
set_fact:
ansible.builtin.set_fact:
_allow_prereleases: "--allow-prereleases"
when: antsibull_ansible_version is regex("^\d+.\d+.\d+(a\d+)$")

- name: Update version ranges in the build file for alpha and beta releases
command: >-
ansible.builtin.command: >-
{{ antsibull_build_command }} new-ansible {{ antsibull_ansible_version }}
--data-dir {{ antsibull_data_dir }}
{{ _allow_prereleases | default('') }}
Expand All @@ -30,12 +30,12 @@
or not _antsibull_build_file_stat.stat.exists

- name: Set up feature freeze for b2 through rc1
set_fact:
ansible.builtin.set_fact:
_feature_freeze: "--feature-frozen"
when: antsibull_ansible_version is regex("^\d+.\d+.\d+(b2|b3|rc1)$")

- name: Prepare a release with new dependencies
command: >-
ansible.builtin.command: >-
{{ antsibull_build_command }} prepare {{ antsibull_ansible_version }}
--data-dir {{ antsibull_data_dir }}
{{ _feature_freeze | default('') }}
Expand All @@ -49,7 +49,7 @@
creates: "{{ antsibull_data_dir }}/{{ _deps_file }}"

- name: Remove existing release tarball and wheel if they exist
file:
ansible.builtin.file:
path: "{{ item }}"
state: absent
when: antsibull_force_rebuild | bool
Expand All @@ -59,7 +59,7 @@

# If the release archive is already there it won't be re-built if we run again
- name: Build a release with existing deps
command: >-
ansible.builtin.command: >-
{{ antsibull_build_command }} rebuild-single {{ antsibull_ansible_version }}
--data-dir {{ antsibull_data_dir }}
--sdist-dir {{ antsibull_sdist_dir }}
Expand All @@ -77,7 +77,7 @@

# We can use this to test that the release on PyPi matches later (for example)
- name: Record the sha256sum for the built tarball
command: sha256sum {{ _release_archive }}
ansible.builtin.command: sha256sum {{ _release_archive }}
changed_when: false
register: _tarball_checksum

Expand All @@ -98,7 +98,7 @@
register: _galaxy_reqs

- name: Template a galaxy-requirements.yaml file
copy:
ansible.builtin.copy:
dest: "{{ antsibull_data_dir }}/galaxy-requirements.yaml"
content: |
# Collections included in Ansible {{ antsibull_ansible_version }}
Expand Down
2 changes: 1 addition & 1 deletion roles/build-release/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- include_tasks: tests.yaml

- name: Release instructions
debug:
ansible.builtin.debug:
msg: >-
Build tested and complete!
A changelog as well as a porting guide have probably been generated at {{ antsibull_data_dir }}.
Expand Down
90 changes: 38 additions & 52 deletions roles/build-release/tasks/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
when: antsibull_venv_cleanup | bool

- name: Get Ansible python fact
setup:
ansible.builtin.setup:
filter: ansible_python

- name: Set a python version fact appropriate for the venv site-packages
set_fact:
ansible.builtin.set_fact:
_python_version: "python{{ ansible_python.version.major }}.{{ ansible_python.version.minor }}"

- name: Install the release tarball in a virtualenv so we can test it
Expand All @@ -22,68 +22,53 @@

# Note: the version of ansible-core doesn't necessarily match the deps file since the version requirement is >=
- block:
# Note: the value is either _ansible_base_version or _ansible_core_version depending on the version
# ex: https://github.com/ansible-community/ansible-build-data/blob/main/4/ansible-4.4.0.deps
- name: Retrieve the expected minimum version of ansible-core
shell: >-
grep -E "_ansible_(base|core)_version" {{ antsibull_data_dir }}/{{ _deps_file }} | awk '{print $2}'
changed_when: false
register: _expected_ansible_core
- name: Include deps_file
ansible.builtin.include_vars:
file: "{{ antsibull_data_dir }}/{{ _deps_file }}"
name: _deps

- name: Retrieve the installed version of ansible-core
shell: >-
{{ antsibull_ansible_venv }}/bin/pip show ansible-core | awk '/Version/ {print $2}'
changed_when: false
register: _installed_ansible_core
- name: Query installed pip packages
community.general.pip_package_info:
gotmax23 marked this conversation as resolved.
Show resolved Hide resolved
clients: "{{ antsibull_venv_pip_bin }}"
register: _pip_pkgs

- name: Validate the version of ansible-core
ansible.builtin.assert:
that:
- _installed_ansible_core.stdout is _antsibull_packaging_version(_expected_ansible_core.stdout, '>=')
success_msg: "ansible-core {{ _installed_ansible_core.stdout }} matches (or exceeds) {{ _deps_file }}"
fail_msg: "ansible-core {{ _installed_ansible_core.stdout }} does not match {{ _deps_file }}"
- antsibull_venv_pip_ansible_core_version is _antsibull_packaging_version(antsibull_expected_ansible_core, '>=')
success_msg: "ansible-core {{ antsibull_venv_pip_ansible_core_version }} matches (or exceeds) {{ _deps_file }}"
fail_msg: "ansible-core {{ antsibull_venv_pip_ansible_core_version }} does not match {{ _deps_file }}"

- block:
- name: Retrieve expected versions of Ansible and collections
command: cat {{ antsibull_data_dir }}/{{ _deps_file }}
changed_when: false
register: _expected_versions

- name: Retrieve collections that should be included in the package
shell: cat {{ antsibull_data_dir }}/ansible.in | egrep -v "^#"
shell: cat {{ antsibull_data_dir }}/ansible.in | grep -vE "^#"
gotmax23 marked this conversation as resolved.
Show resolved Hide resolved
changed_when: false
register: _included_collections

- name: Retrieve the installed version of ansible with pip
shell: >-
{{ antsibull_ansible_venv }}/bin/pip show ansible | awk '/Version/ {print $2}'
changed_when: false
register: _ansible_version_pypi

- name: Retrieve the builtin reported version of ansible
command: >-
ansible.builtin.command: >-
{{ antsibull_ansible_venv }}/bin/python3 -c 'from ansible_collections.ansible_release import ansible_version; print(ansible_version)'
changed_when: false
register: _ansible_version_builtin

- name: Validate the version of ansible
ansible.builtin.assert:
that:
- "'_ansible_version: {{ _ansible_version_pypi.stdout }}' in _expected_versions.stdout"
- _ansible_version_pypi.stdout == _ansible_version_builtin.stdout
success_msg: "ansible {{ _ansible_version_pypi.stdout }} matches {{ _deps_file }} as well as 'ansible_collections.ansible_release'"
fail_msg: "ansible {{ _ansible_version_pypi.stdout }} does not match {{ _deps_file }} or 'ansible_collections.ansible_release'"
- antsibull_venv_pip_ansible_version == _deps['_ansible_version']
- antsibull_venv_pip_ansible_version == _ansible_version_builtin.stdout
success_msg: "ansible {{ antsibull_venv_pip_ansible_version }} matches {{ _deps_file }} as well as 'ansible_collections.ansible_release'"
fail_msg: "ansible {{ antsibull_venv_pip_ansible_version }} does not match {{ _deps_file }} or 'ansible_collections.ansible_release'"

- when: antsibull_ansible_version is _antsibull_packaging_version('6.0.0rc1', '>=')
block:
- name: Retrieve the builtin reported version of ansible from the ansible-community CLI tool
command: >-
ansible.builtin.command: >-
{{ antsibull_ansible_venv }}/bin/ansible-community --version
changed_when: false
register: _ansible_version_builtin_2

- name: Verify that the version output matches the one we expect
assert:
ansible.builtin.assert:
that:
- _ansible_version_builtin_2.stdout == ("Ansible community version " ~ antsibull_ansible_version)

Expand All @@ -92,45 +77,46 @@
# In case we happen to be testing with devel, don't print a warning about it
ANSIBLE_DEVEL_WARNING: false
# Until https://github.com/ansible/ansible/pull/70173 is backported and released
ANSIBLE_COLLECTIONS_PATH: "{{ antsibull_ansible_venv }}/lib/{{ _python_version }}/site-packages/ansible_collections"
ANSIBLE_COLLECTIONS_PATH: "{{ antsibull_collections_path }}"
# List collections, remove empty lines, headers, file paths and format the results in the same way as the deps file
shell: >-
{{ antsibull_ansible_venv }}/bin/ansible-galaxy collection list | egrep -v '^$|^#|---|Collection.*Version' | awk '{ print $1 ": " $2 }'
ansible.builtin.command:
cmd: "{{ antsibull_ansible_venv }}/bin/ansible-galaxy collection list --format json"
changed_when: false
register: _installed_collections
register: _installed_collections_json

- name: Validate that the installed collections are the expected ones
ansible.builtin.assert:
that:
- item in _expected_versions.stdout
- item['value']['version'] == _deps[item['key']]
success_msg: "{{ item }} matches {{ _deps_file }}"
fail_msg: "{{ item }} does not match {{ _deps_file }}"
loop: "{{ _installed_collections.stdout_lines }}"
loop: "{{ antsibull_installed_collections | dict2items }}"

- name: Validate that included collections are packaged
ansible.builtin.assert:
that:
- item in _installed_collections.stdout
- item in antsibull_installed_collections
success_msg: "{{ item }} is in ansible.in and inside the package"
fail_msg: "{{ item }} is in ansible.in but not inside the package. Maybe run 'antsibull-build new-ansible --data-dir={{ antsibull_data_dir }}' to update ansible.in and then rebuild ?"
loop: "{{ _included_collections.stdout_lines }}"

- block:
- name: Run nested tests
vars:
ansible_collections_path: "{{ antsibull_sdist_dir }}/ansible_collections"
environment:
ANSIBLE_COLLECTIONS_PATH: "{{ ansible_collections_path }}"
block:
- name: Create a temporary COLLECTIONS_PATH
file:
path: "{{ antsibull_sdist_dir }}/ansible_collections"
ansible.builtin.file:
path: "{{ ansible_collections_path }}"
state: directory

- name: Install community.general for tests using 'a_module' and 'collection_version'
environment:
ANSIBLE_COLLECTIONS_PATH: "{{ antsibull_sdist_dir }}/ansible_collections"
command: >-
ansible.builtin.command: >-
{{ antsibull_ansible_venv }}/bin/ansible-galaxy collection install community.general

- name: Run nested Ansible tests with the Ansible we just built
environment:
ANSIBLE_COLLECTIONS_PATH: "{{ antsibull_sdist_dir }}/ansible_collections"
command: >-
ansible.builtin.command: >-
{{ antsibull_ansible_venv }}/bin/ansible-playbook -i 'localhost,' --connection=local
-e antsibull_sdist_dir="{{ antsibull_sdist_dir }}"
-e antsibull_ansible_venv="{{ antsibull_ansible_venv }}"
Expand Down
13 changes: 13 additions & 0 deletions roles/build-release/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
# Note: the value is either _ansible_base_version or _ansible_core_version depending on the version
# ex: https://github.com/ansible-community/ansible-build-data/blob/main/4/ansible-4.4.0.deps
# Variables that start with `_` are intermediate variables that are `register`ed in the playbook.
antsibull_expected_ansible_core: "{{ _deps['_ansible_core_version'] | default(_deps['_ansible_base_version']) }}"
antsibull_venv_pip_bin: "{{ antsibull_ansible_venv }}/bin/pip"
antsibull_venv_pip_pkgs: "{{ _pip_pkgs['packages'][antsibull_venv_pip_bin] }}"
antsibull_venv_pip_ansible_version: "{{ antsibull_venv_pip_pkgs['ansible'][0]['version'] }}"
antsibull_venv_pip_ansible_core_version: "{{ antsibull_venv_pip_pkgs['ansible-core'][0]['version'] }}"

antsibull_collections_path: "{{ antsibull_ansible_venv }}/lib/{{ _python_version }}/site-packages/ansible_collections"
_antsibull_installed_collections: "{{ _installed_collections_json['stdout'] | from_json }}"
antsibull_installed_collections: "{{ _antsibull_installed_collections[antsibull_collections_path] }}"