From dd5ee78386ef19b7c60bd7f488ec1125b7836f50 Mon Sep 17 00:00:00 2001 From: Jonas L Date: Wed, 9 Aug 2023 11:34:12 +0200 Subject: [PATCH] feat: replace ansible version with collection version in hcloud user agent (#291) * feat: use collection version in hcloud user-agent * chore: add version sync pre-commit hook * chore: add changelog fragment --- .pre-commit-config.yaml | 8 ++++++++ README.md | 3 ++- .../fragments/use-collection-version-in-user-agent.yml | 2 ++ plugins/module_utils/hcloud.py | 4 ++-- plugins/module_utils/version.py | 1 + scripts/version-sync.sh | 7 +++++++ 6 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/use-collection-version-in-user-agent.yml create mode 100644 plugins/module_utils/version.py create mode 100755 scripts/version-sync.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1f593be..d60b820 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -87,3 +87,11 @@ repos: entry: scripts/integration-test-files.sh pass_filenames: false files: ^(scripts/integration-test-files.sh$|tests/integration) + + - id: check-version-variables + name: check version variables + description: Ensure the version variables are in sync + language: system + entry: scripts/version-sync.sh + pass_filenames: false + files: ^(scripts/version-sync.sh$|galaxy.yml|plugins/module_utils/version.py) diff --git a/README.md b/README.md index 963eeba..057622a 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,8 @@ ansible-test integration --color --local -vvv hcloud_server // Executed all int 5. Update the `version` in the ansible galaxy metadata file: ```sh sed -i "s/^version: .*/version: $HCLOUD_VERSION/" galaxy.yml - git add galaxy.yml + scripts/version-sync.sh + git add galaxy.yml plugins/module_utils/version.py ``` 6. Commit the changes: ```sh diff --git a/changelogs/fragments/use-collection-version-in-user-agent.yml b/changelogs/fragments/use-collection-version-in-user-agent.yml new file mode 100644 index 0000000..1eb09d3 --- /dev/null +++ b/changelogs/fragments/use-collection-version-in-user-agent.yml @@ -0,0 +1,2 @@ +minor_changes: + - Use the collection version in the hcloud user-agent instead of the ansible-core version. diff --git a/plugins/module_utils/hcloud.py b/plugins/module_utils/hcloud.py index 743cb39..17d0ddc 100644 --- a/plugins/module_utils/hcloud.py +++ b/plugins/module_utils/hcloud.py @@ -5,11 +5,11 @@ import traceback -from ansible.module_utils.ansible_release import __version__ from ansible.module_utils.basic import env_fallback, missing_required_lib from ansible.module_utils.common.text.converters import to_native from ..module_utils.vendor import hcloud +from .version import version HAS_REQUESTS = True HAS_DATEUTIL = True @@ -65,7 +65,7 @@ class AnsibleHCloud: token=self.module.params["api_token"], api_endpoint=self.module.params["endpoint"], application_name="ansible-module", - application_version=__version__, + application_version=version, ) def _mark_as_changed(self): diff --git a/plugins/module_utils/version.py b/plugins/module_utils/version.py new file mode 100644 index 0000000..1b23640 --- /dev/null +++ b/plugins/module_utils/version.py @@ -0,0 +1 @@ +version = "2.0.0" diff --git a/scripts/version-sync.sh b/scripts/version-sync.sh new file mode 100755 index 0000000..988f153 --- /dev/null +++ b/scripts/version-sync.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# Sync the collection version variable based on the version in the galaxy.yml file. + +galaxy_version="$(grep '^version:' galaxy.yml | cut -d ' ' -f 2)" + +sed --in-place "s|version = .*|version = \"$galaxy_version\"|" plugins/module_utils/version.py