Skip to content

Commit

Permalink
Insert antsibull version into the build-ansible.sh script (#563)
Browse files Browse the repository at this point in the history
* Insert antsibull version into the build-ansible.sh script.

* update package-files test_data for build-ansible.sh change

* Use proper placeholder instead of a real version.

* Fix spelling error.

Co-authored-by: Maxwell G <[email protected]>

---------

Co-authored-by: Maxwell G <[email protected]>
  • Loading branch information
felixfontein and gotmax23 authored Nov 24, 2023
1 parent c2a7bad commit 15f22e1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/563-version-build-ansible.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- "Adjust the ``pip install antsibull`` call in the ``build-ansible.sh`` script added to the ``ansible`` source distribution
to use the version of antsibull used to build the ansible release (https://github.com/ansible-community/antsibull/pull/563)."
5 changes: 4 additions & 1 deletion src/antsibull/build_ansible_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from antsibull.constants import MINIMUM_ANSIBLE_VERSIONS
from antsibull.python_metadata import BuildMetaMaker, LegacyBuildMetaMaker

from . import __version__ as antsibull_version
from .build_changelog import ReleaseNotes
from .changelog import ChangelogData, get_changelog
from .dep_closure import check_collection_dependencies
Expand Down Expand Up @@ -394,7 +395,9 @@ def write_build_script(
get_antsibull_data("build-ansible.sh.j2").decode("utf-8")
)
build_ansible_contents = build_ansible_tmpl.render(
version=ansible_version, ansible_core_version=ansible_core_version
version=ansible_version,
ansible_core_version=ansible_core_version,
antsibull_version=antsibull_version,
)

with open(build_ansible_filename, "w", encoding="utf-8") as f:
Expand Down
2 changes: 1 addition & 1 deletion src/antsibull/data/build-ansible.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MAJOR="{{ version.major }}"
# For idempotency, remove build data or built output first
rm -rf ansible-build-data built

pip3 install --user --upgrade antsibull
pip3 install --user --upgrade "antsibull=={{ antsibull_version }}"
git clone https://github.com/ansible-community/ansible-build-data.git
mkdir -p built collection-cache

Expand Down
2 changes: 1 addition & 1 deletion tests/test_data/package-files/7.5.0/build-ansible.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ MAJOR="7"
# For idempotency, remove build data or built output first
rm -rf ansible-build-data built

pip3 install --user --upgrade antsibull
pip3 install --user --upgrade "antsibull==(ANTSIBULL_VERSION)"
git clone https://github.com/ansible-community/ansible-build-data.git
mkdir -p built collection-cache
BUILD_DATA_DIR="ansible-build-data/${MAJOR}"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data/package-files/8.1.0/build-ansible.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ MAJOR="8"
# For idempotency, remove build data or built output first
rm -rf ansible-build-data built

pip3 install --user --upgrade antsibull
pip3 install --user --upgrade "antsibull==(ANTSIBULL_VERSION)"
git clone https://github.com/ansible-community/ansible-build-data.git
mkdir -p built collection-cache
BUILD_DATA_DIR="ansible-build-data/${MAJOR}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ MAJOR="8"
# For idempotency, remove build data or built output first
rm -rf ansible-build-data built

pip3 install --user --upgrade antsibull
pip3 install --user --upgrade "antsibull==(ANTSIBULL_VERSION)"
git clone https://github.com/ansible-community/ansible-build-data.git
mkdir -p built collection-cache
BUILD_DATA_DIR="ansible-build-data/${MAJOR}"
Expand Down
18 changes: 17 additions & 1 deletion tests/verify_package_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import aiohttp
from packaging.version import Version as PypiVer

import antsibull.build_ansible_commands
from antsibull.cli import antsibull_build
from antsibull.constants import MINIMUM_ANSIBLE_VERSIONS

Expand All @@ -38,6 +39,7 @@
SDIST_PATH = f"{PYPI_PATH}/source/a/ansible/ansible-{{version}}.tar.gz"

ANTSIBULL_BUILD = os.environ.get("ANTSIBULL_BUILD", "antsibull-build")
PLACEHOLDER_ANTSIBULL_VERSION = "(ANTSIBULL_VERSION)"


@dataclasses.dataclass
Expand Down Expand Up @@ -154,7 +156,11 @@ def generate_package_files(
if force_generate_setup_cfg
else contextlib.nullcontext()
)
with cm, cm2:
with cm, cm2, patch_object(
antsibull.build_ansible_commands,
"antsibull_version",
PLACEHOLDER_ANTSIBULL_VERSION,
):
if r := antsibull_build.run(
[
"antsibull-build",
Expand Down Expand Up @@ -189,6 +195,16 @@ def patch_dict(mapping: MutableMapping, key: Any, value: Any) -> Iterator[None]:
mapping[key] = old


@contextlib.contextmanager
def patch_object(object: Any, attr: str, new_value: Any) -> Iterator[None]:
old_value = getattr(object, attr)
try:
setattr(object, attr, new_value)
yield
finally:
setattr(object, attr, old_value)


def write_file_list(
version: str, source_dir: Path, build_dir: Path | None = None
) -> DIST_TUPLE:
Expand Down

0 comments on commit 15f22e1

Please sign in to comment.