'npm version patch: clean working directory not clean

I hae a problem running npm version patch on Azure Pipelines. Initially, I discovered that SonarCloud scanner drops unwanted files in the repository. I git-ignored the directory

Consider the following fragment

          - script: git checkout -f $(Build.SourceBranchName)
            displayName: Force checkout of current branch

          - script: git status
            displayName: Git status

          - script: git reset --hard
            displayName: Git reset

          - task: Npm@1
            displayName: Tag repository and set release version
            inputs:
              command: custom
              customCommand: version patch

          - script: git push origin $(Build.SourceBranchName) --tags
            displayName: Git push with tags
  1. Required in order to push a subsequent commit
  2. Displays a summary of the repository
  3. Unhappy with git-status ok, I force cleaning the repo
  4. Makes a commit and a tag out of the repository
  5. Pushes branch and tag

git-status output

Starting: Git status
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.201.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
git status
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/447a869a-56d7-4a29-a4c0-9a49b5ffce74.sh
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
Finishing: Git status

git-reset output

Starting: Git reset
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.201.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
git reset --hard
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/85fedcd4-9756-4d38-aa3d-d41c03032565.sh
HEAD is now at ad6aebf Pipelines
Finishing: Git reset

npm-version output

Starting: Tag repository and set release version
==============================================================================
Task         : npm
Description  : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
Version      : 1.202.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/npm
==============================================================================
/opt/hostedtoolcache/node/16.15.0/x64/bin/npm --version
8.5.5
/opt/hostedtoolcache/node/16.15.0/x64/bin/npm config list
; "project" config from /home/vsts/work/1/s/.npmrc

message = ":[npm-autoversion]: %s" 

; "env" config from environment

cache = "/home/vsts/work/1/.npm" 
userconfig = "/home/vsts/work/1/npm/7212.npmrc" 

; node bin location = /opt/hostedtoolcache/node/16.15.0/x64/bin/node
; cwd = /home/vsts/work/1/s
; HOME = /home/vsts
; Run `npm config ls -l` to show all defaults.
/opt/hostedtoolcache/node/16.15.0/x64/bin/npm version patch
npm ERR! Git working directory not clean.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vsts/work/1/.npm/_logs/2022-05-19T13_01_16_005Z-debug-0.log
##[warning]Couldn't find a debug log in the cache or working directory
##[error]Error: Npm failed with return code: 1
Finishing: Tag repository and set release version

Question: how is it possible that npm fails to make a version bump if I am triple-sure that the repository is clean?



Solution 1:[1]

You can use explain API but you'd have to feed matching documents one by one. Look for the field with "description":"freq, occurrences of term within document"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ilvar