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
This commit is contained in:
Jonas L 2023-08-09 11:34:12 +02:00 committed by GitHub
parent 59fe4339d4
commit dd5ee78386
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 3 deletions

View file

@ -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)

View file

@ -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

View file

@ -0,0 +1,2 @@
minor_changes:
- Use the collection version in the hcloud user-agent instead of the ansible-core version.

View file

@ -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):

View file

@ -0,0 +1 @@
version = "2.0.0"

7
scripts/version-sync.sh Executable file
View file

@ -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