Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit 'ansible-lint' version set to '0.1.dev1' instead of specified version #2713

Closed
gregaf300 opened this issue Nov 22, 2022 · 2 comments · Fixed by #2714
Closed

pre-commit 'ansible-lint' version set to '0.1.dev1' instead of specified version #2713

gregaf300 opened this issue Nov 22, 2022 · 2 comments · Fixed by #2714
Assignees
Labels

Comments

@gregaf300
Copy link

Summary

After attempting to use ansible-lint with pre-commit using the latest release of v6.8.7 the resolved
ansible-lint version via pre-commit is set to 0.1.dev1. Attempted on several different environments
(WSL, MacOS) that all result in the same issue.

Issue Type
  • Bug Report
Ansible and Ansible Lint details
ansible --version (ansible binary in pre-commit repo)

ansible [core 2.14.0]
  config file = /home/.ansible.cfg
  configured module search path = ['/home/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/.cache/pre-commit/repozwa3kqlh/py_env-python3.10/lib/python3.10/site-packages/ansible
  ansible collection location = /home/.ansible/collections:/usr/share/ansible/collections
  executable location = ./ansible
  python version = 3.10.7 (main, Oct  6 2022, 11:00:30) [GCC 9.4.0] (/home/.cache/pre-commit/repozwa3kqlh/py_env-python3.10/bin/python)
  jinja version = 3.1.2
  libyaml = True

ansible-lint --version (ansible-lint binary in pre-commit repo)

WARNING: PATH altered to include /home/.cache/pre-commit/repozwa3kqlh/py_env-python3.10/bin :: This is usually a sign of broken local setup, which can cause unexpected behaviors.
ansible-lint 0.1.dev1 using ansible 2.14.0
A new release of ansible-lint is available: 0.1.dev1 → 6.8.7 Upgrade by running: pip install --upgrade ansible-lint
  • ansible installation method: pip (via pre-commit setup pip)
  • ansible-lint installation method: pip (via pre-commit setup pip)
OS / ENVIRONMENT
Linux 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
STEPS TO REPRODUCE
  • Setup a '.pre-commit-config.yaml' hook using the supplied hook from the ansible-lint repository.
  • Ensure that the 'rev' field in the pre-commit repo is set to v6.8.7
  • Install the pre-commit hook into a git repository with pre-commit install
  • Run pre-commit run --all-files
# Offending pre-commit repo
  - repo: https://github.com/ansible/ansible-lint
    rev: v6.8.7
    hooks:
      - id: ansible-lint
        name: Ansible-lint
        description: This hook runs ansible-lint.
        entry: python3 -m ansiblelint -v --force-color
        language: python
        # do not pass files to ansible-lint, see:
        # https://github.com/ansible/ansible-lint/issues/611
        pass_filenames: false
        always_run: true
Desired Behavior

I expect the ansible-lint version to be upgraded to the target specified version
indicated by the 'rev' field within the '.pre-commit-config.yaml' file. In the specific
case outlined for this ticket, the ansible-lint version should be set to 6.8.7 instead of 0.1.dev1.

Possible security bugs should be reported via email to [email protected]

Actual Behavior

Please give some details of what is actually happening:

The expected version number for ansible-lint is not correctly set to 6.8.7, it is instead set to 0.1.dev1.

ansible-lint output:

Failed after min profile: 473 failure(s), 48 warning(s) on 229 files.
A new release of ansible-lint is available: 0.1.dev1 → 6.8.7 Upgrade by running: pip install --upgrade ansible-lint

Additional note:

  • The offending problem above shows up in the v6.8.3 release and later.
@ssbarnea
Copy link
Member

While I can confirm the bug I am not sure which project is the cause, linter, pre-commit or setuptools-scm.

Doing a simple test with a shallow clone did get the desired result locally.

git clone --depth 1 --branch v6.8.7 https://github.com/ansible/[email protected]
...
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

$ git log
commit 7be2420c3c6242009345a76896cf53d1e4e4fb2c (grafted, HEAD, tag: v6.8.7)
...

$ pip install .
...

# ansible-lint --version
ansible-lint 6.8.7 using ansible 2.14.0

Still, I can confirm that when running from inside pre-commit, the result is different.

@ssbarnea
Copy link
Member

I did look at the cloning logic of pre-commit tool which attempts to perform a shallow cloning first and only if this fails tries to make a full one. I manually repeating the steps and discovered that its operation does not pull any tags, so not surprise that any project using setuptools-scm would have wrong versioning:

Test using pre-commit internal cloning strategy

git init --template= ansible-lint
cd ansible-lint
git remote add origin https://github.com/ansible/ansible-lint
git -c protocol.version=2 fetch origin v6.8.7 --depth=1
git checkout FETCH_HEAD
git -c protocol.version=2 submodule update --init --recursive --depth=1
# done, now testing if we have any tags:
git tag --points-at HEAD
# ... ooops, no tag.

Test using official git shallow cloning:

git clone --depth=1 --branch v6.8.7  https://github.com/ansible/ansible-lint
cd ansible-lint
git tag --points-at HEAD
v6.8.7
# So it worked fine as tag is present!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants