1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-07-06 02:28:53 +00:00

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
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

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

Co-authored-by: Cursor <cursoragent@cursor.com>

* test signing trace

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Shreyash 2026-06-14 15:36:39 +05:30 committed by GitHub
parent f4339d8c0d
commit b34ef22c82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 436 additions and 0 deletions

View 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

View 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

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

View 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'

View file

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

View file

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