conventional-changelog / standard-version

:trophy: Automate versioning and CHANGELOG generation, with semver.org and conventionalcommits.org
ISC License
7.65k stars 788 forks source link

Does not commit bumped version number in package.json on Bitbucket pipelines #434

Open danobot opened 5 years ago

danobot commented 5 years ago

I am having trouble using this in Bitbucket pipeline. It is consistently committing the changelog witout committing the package.json and the bumped version number.(Resulting in the same release version each time). I tried:

It works perfectly in local environment, I am not sure what I am missing.

Version: 7.0.0

Release Commit: image

Package.json

"scripts": {
    "release": "standard-version --no-verify --prerelease beta"
}, 
...
 "standard-version": {
    "scripts": {
      "postbump": "git add package.json",
      "precommit": "echo \"[skip ci]\""
    },
    "skip": {
      "tag": true
    }
  }

Bitbucket PIpeline


# Check our guides at https://confluence.atlassian.com/x/14UWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: node:10.15.3

pipelines:
  default:
    - step:
        caches:
          - node
        script: # Modify the commands below to build your repository.
          - echo "Hi"
  branches:
    master:
      - step:
          caches:
            - node
          script:
            - npm install
            - npm run release
            - git push origin master
tokenvolt commented 5 years ago

I'm having the same issue, but with GitLab CI. Version is not getting bumped in package.json. It is reproduced with standard-version@^7.0.0.

tokenvolt commented 5 years ago

Nevermind it was a bug on our side, due to incorrect .gitignore

zgreen commented 4 years ago

Had the exact same issue in a bitbucket pipeline; package.json was never updated, even though it worked perfectly locally. I have no idea why. If I had to guess, I'd say it's a bitbucket issue.

In the end, I wrote a script to do it. Since standard-release does set the proper git tags, you can read those and update package.json appropriately:

// updatePkg.js
const fs = require("fs-extra");
const child_process = require("child_process");
const pkg = require("../package.json");

const main = async () => {
  const tag = child_process
    .execSync(`git describe --abbrev=0`, { encoding: "utf8" })
    .trim();
  pkg.version = tag.slice(1);
  try {
    await fs.writeJson("./package.json", pkg, { spaces: 2 });
  } catch (err) {
    throw err;
  }
  console.log(`package.json updated, version ${pkg.version}`);
  child_process.execSync(
    `git commit -am "chore(package.json): bump version [skip ci]"`
  );
  console.log("package.json update commited");
  child_process.execSync("git push");
  console.log("package.json update pushed");
};

main();

And the pipeline:

release: &release
  step:
    name: Release
    script:
      - npm i
      - npm run release
      - git push --follow-tags
      - npm run update:pkg
      - pipe: atlassian/npm-publish:0.2.5
        variables:
          NPM_TOKEN: $NPM_TOKEN
fbergstrm commented 3 years ago

Had the same issue with .gitignore, and to save some time for anyone else having this issue it was that our .gitignore contained the row build to ignore the build folder.

Bitbucket pipeline cloned the repo into /opt/atlassian/pipelines/agent/build. And the whole folder was ignored including the package.json and package-lock.json files.

Hope it saves some time if anyone else has the same issue.

And this issue could possibly be closed? It would however be an good idea to have an warning message abut any ignored files.

cabauman commented 2 years ago

Nice find @fbergstrm. This burned me too. But why would the changelog modifications not be ignored as well?

EDIT

Okay, found out why. The gitignore check is only made in bump.js; not in changelog.js

amoshydra commented 2 years ago

This looks like a bug. From my understanding, gitignore rule should be applied to the git repository only?

This is our jenkin path (reproducible in local with this folder structure)

/var/lib/jenkins/workspace/package.json
/var/lib/jenkins/workspace/.git
/var/lib/jenkins/workspace/.gitignore

.gitignore contains

lib

In this environment bump.js will skip updating package.json. The dotGit.ignore evaluates /var/lib/jenkins/workspace/package.json as should be ignored.


From what I understand, this is not the usual behaviour in git. In usual git environment, gitignore rules is only applied to files and folder located starting from where the .gitignore file is located.

This can be verified via:

git status --ignore
amoshydra commented 2 years ago

Looks like a duplicate of

https://github.com/conventional-changelog/standard-version/issues/253