mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-07-07 19:18:54 +00:00
[PR #12152/b34ef22c backport][stable-13] add go module to manage Go packages via go install (#12269)
add go module to manage Go packages via go install (#12152)
* add golang_package module to manage Go packages via go install
Adds a new module to install, update, and remove Go packages
using go install. Supports inline version pinning in package
names (e.g. pkg/tool/cmd with version suffix).
Assisted-by: Claude Opus 4.6
* fix copyright year and BOTMETA alphabetical order
* fix environment keyword docs, add integration test aliases
- Use C(environment) instead of O(ignore:environment) for task keyword
- Add tests/integration/targets/golang_package/aliases for CI
- Fix setup.yml: handle Alpine/ArchLinux/FreeBSD package names, skip Go < 1.16
- Pin tests to x/tools v0.24.1 (only version compatible with Go 1.16-1.25)
* test signing trace
---------
(cherry picked from commit b34ef22c82)
Co-authored-by: Shreyash <shrbhosa@redhat.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
9e690837bd
commit
3cba1cd735
8 changed files with 436 additions and 0 deletions
6
tests/integration/targets/golang_package/aliases
Normal file
6
tests/integration/targets/golang_package/aliases
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
azp/posix/2
|
||||
destructive
|
||||
7
tests/integration/targets/golang_package/meta/main.yml
Normal file
7
tests/integration/targets/golang_package/meta/main.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
dependencies:
|
||||
- setup_pkg_mgr
|
||||
10
tests/integration/targets/golang_package/tasks/main.yml
Normal file
10
tests/integration/targets/golang_package/tasks/main.yml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- import_tasks: setup.yml
|
||||
- block:
|
||||
- import_tasks: test_general.yml
|
||||
- import_tasks: test_version.yml
|
||||
when: has_go | default(false)
|
||||
27
tests/integration/targets/golang_package/tasks/setup.yml
Normal file
27
tests/integration/targets/golang_package/tasks/setup.yml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Determine Go package name
|
||||
set_fact:
|
||||
golang_package_name: >-
|
||||
{{ 'go' if ansible_facts.os_family in ['Alpine', 'Archlinux', 'FreeBSD'] else 'golang' }}
|
||||
|
||||
- block:
|
||||
- name: Install Go
|
||||
package:
|
||||
name: "{{ golang_package_name }}"
|
||||
state: present
|
||||
|
||||
- name: Check Go version
|
||||
command: go version
|
||||
register: go_version_output
|
||||
changed_when: false
|
||||
|
||||
- name: Set has_go if Go >= 1.19
|
||||
set_fact:
|
||||
has_go: true
|
||||
when: (go_version_output.stdout | regex_search('go(\d+\.\d+)', '\\1') | first) is version('1.19', '>=')
|
||||
when:
|
||||
- ansible_facts.distribution != 'MacOSX'
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# x/tools v0.24.1 is the only version that works on both Go 1.16-1.24 AND Go 1.25+.
|
||||
# See https://github.com/golang/go/issues/74462 for details.
|
||||
|
||||
- name: Ensure stringer is absent
|
||||
community.general.golang_package:
|
||||
state: absent
|
||||
name: golang.org/x/tools/cmd/stringer
|
||||
register: uninstall_absent
|
||||
|
||||
- name: Install stringer
|
||||
community.general.golang_package:
|
||||
name: golang.org/x/tools/cmd/stringer
|
||||
version: v0.24.1
|
||||
register: install_result
|
||||
|
||||
- name: Install stringer again (idempotent)
|
||||
community.general.golang_package:
|
||||
name: golang.org/x/tools/cmd/stringer
|
||||
version: v0.24.1
|
||||
register: install_idem
|
||||
|
||||
- name: Uninstall stringer
|
||||
community.general.golang_package:
|
||||
state: absent
|
||||
name: golang.org/x/tools/cmd/stringer
|
||||
register: uninstall_result
|
||||
|
||||
- name: Uninstall stringer again (idempotent)
|
||||
community.general.golang_package:
|
||||
state: absent
|
||||
name: golang.org/x/tools/cmd/stringer
|
||||
register: uninstall_idem
|
||||
|
||||
- name: Check assertions
|
||||
assert:
|
||||
that:
|
||||
- uninstall_absent is not changed
|
||||
- install_result is changed
|
||||
- install_idem is not changed
|
||||
- uninstall_result is changed
|
||||
- uninstall_idem is not changed
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# x/tools v0.24.1 is the only version that works on both Go 1.16-1.24 AND Go 1.25+.
|
||||
# See https://github.com/golang/go/issues/74462 for details.
|
||||
|
||||
- name: Install stringer at specific version (version param)
|
||||
community.general.golang_package:
|
||||
name: golang.org/x/tools/cmd/stringer
|
||||
version: v0.24.1
|
||||
register: install_version
|
||||
|
||||
- name: Install stringer at same version (idempotent)
|
||||
community.general.golang_package:
|
||||
name: golang.org/x/tools/cmd/stringer
|
||||
version: v0.24.1
|
||||
register: install_version_idem
|
||||
|
||||
- name: Clean up stringer
|
||||
community.general.golang_package:
|
||||
name: golang.org/x/tools/cmd/stringer
|
||||
state: absent
|
||||
|
||||
- name: Install stringer at specific version (inline @version)
|
||||
community.general.golang_package:
|
||||
name: golang.org/x/tools/cmd/stringer@v0.24.1
|
||||
register: install_inline_version
|
||||
|
||||
- name: Install stringer at same inline version (idempotent)
|
||||
community.general.golang_package:
|
||||
name: golang.org/x/tools/cmd/stringer@v0.24.1
|
||||
register: install_inline_version_idem
|
||||
|
||||
- name: Clean up stringer
|
||||
community.general.golang_package:
|
||||
name: golang.org/x/tools/cmd/stringer
|
||||
state: absent
|
||||
|
||||
- name: Check assertions
|
||||
assert:
|
||||
that:
|
||||
- install_version is changed
|
||||
- install_version_idem is not changed
|
||||
- install_inline_version is changed
|
||||
- install_inline_version_idem is not changed
|
||||
Loading…
Add table
Add a link
Reference in a new issue