1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[PR #7339/39895a6d backport][stable-7] pnpm: version should not be latest when state is latest (#7347)

pnpm: version should not be latest when state is latest (#7339)

* (fix) don't set version at latest at state: latest

If version is forcefully set at latest when state is latest, the package
will always be changed, as there is no version "latest" will ever be
detected. It is better to keep it None.

* (fix) fixed tests to reflect recent changes

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

* (feat) added changelog fragment for pull #7339

* (fix) apply correct punctuation to changelog

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 39895a6d38)

Co-authored-by: Aritra Sen <125266845+aretrosen@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2023-10-04 16:47:32 +00:00 committed by GitHub
parent 625d22391f
commit b279694779
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 10 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- pnpm - set correct version when state is latest or version is not mentioned. Resolves previous idempotency problem (https://github.com/ansible-collections/community.general/pull/7339).

View file

@ -189,6 +189,8 @@ class Pnpm(object):
self.alias_name_ver = (self.alias_name_ver or "") + self.name self.alias_name_ver = (self.alias_name_ver or "") + self.name
if self.version is not None: if self.version is not None:
self.alias_name_ver = self.alias_name_ver + "@" + str(self.version) self.alias_name_ver = self.alias_name_ver + "@" + str(self.version)
else:
self.alias_name_ver = self.alias_name_ver + "@latest"
def _exec(self, args, run_in_check_mode=False, check_rc=True): def _exec(self, args, run_in_check_mode=False, check_rc=True):
if not self.module.check_mode or (self.module.check_mode and run_in_check_mode): if not self.module.check_mode or (self.module.check_mode and run_in_check_mode):
@ -413,9 +415,6 @@ def main():
if state == "absent" and name is None: if state == "absent" and name is None:
module.fail_json(msg="Package name is required for uninstalling") module.fail_json(msg="Package name is required for uninstalling")
if state == "latest":
version = "latest"
if globally: if globally:
_rc, out, _err = module.run_command(executable + ["root", "-g"], check_rc=True) _rc, out, _err = module.run_command(executable + ["root", "-g"], check_rc=True)
path, _tail = os.path.split(out.strip()) path, _tail = os.path.split(out.strip())

View file

@ -1,3 +1,4 @@
---
#################################################################### ####################################################################
# WARNING: These are designed specifically for Ansible tests # # WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles # # and should not be used as examples of how to write Ansible roles #
@ -13,7 +14,7 @@
# Setup steps # Setup steps
- name: Run tests on OSes - name: Run tests on OSes
include_tasks: run.yml ansible.builtin.include_tasks: run.yml
vars: vars:
ansible_system_os: "{{ ansible_system | lower }}" ansible_system_os: "{{ ansible_system | lower }}"
nodejs_version: "{{ item.node_version }}" nodejs_version: "{{ item.node_version }}"

View file

@ -127,11 +127,6 @@
- pnpm_reinstall is success - pnpm_reinstall is success
- not (pnpm_reinstall is changed) - not (pnpm_reinstall is changed)
- name: Manually delete package
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/node_modules/{{ package }}"
state: absent
- name: Reinstall package - name: Reinstall package
pnpm: pnpm:
path: "{{ remote_tmp_dir }}" path: "{{ remote_tmp_dir }}"
@ -146,7 +141,7 @@
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- pnpm_fix_install is success - pnpm_fix_install is success
- pnpm_fix_install is changed - pnpm_fix_install is not changed
- name: Install package with version, without executable path - name: Install package with version, without executable path
pnpm: pnpm:
@ -293,6 +288,22 @@
- pnpm_reinstall is success - pnpm_reinstall is success
- not (pnpm_reinstall is changed) - not (pnpm_reinstall is changed)
- name: Updating package globally, without explicit executable path
pnpm:
name: "{{ package }}"
state: latest
global: true
environment:
PATH: "{{ pnpm_bin_path }}:{{ node_bin_path }}:{{ ansible_env.PATH }}"
PNPM_HOME: "{{ pnpm_bin_path }}"
register: pnpm_reinstall
- name: Assert that there is no change
ansible.builtin.assert:
that:
- pnpm_reinstall is success
- pnpm_reinstall is not changed
- name: Remove package without dependency globally - name: Remove package without dependency globally
pnpm: pnpm:
name: "{{ package }}" name: "{{ package }}"