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

Changes not staged for commit #1

Closed
antongolub opened this issue Mar 13, 2019 · 6 comments · Fixed by #2
Closed

Changes not staged for commit #1

antongolub opened this issue Mar 13, 2019 · 6 comments · Fixed by #2
Labels

Comments

@antongolub
Copy link
Collaborator

Hi there. Nice to know that someone else is trying to make semantic monorepos.

Anyway, the problem.

When sem-rel-git plugin is enabled, git push fails because of not staged changes.

release config

{
    "branch": "master",
    "plugins": [
      "@semantic-release/commit-analyzer",
      "@semantic-release/release-notes-generator",
      "@semantic-release/changelog",
      "@semantic-release/npm",
      [
        "@semantic-release/git",
        {
          "assets": [
            "src/**/*.{js,css}",
            "package.json"
          ],
          "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
        }
      ],
      "@semantic-release/github"
    ]
  }

build log

[11:24:10 AM] [@antongolub/release-testing-package-second] › ✖  An error occurred while running semantic-release: { Error: Command failed: git commit -m chore(release): 1.0.1 [skip ci]
## @antongolub/release-testing-package-second [1.0.1](https://github.com/antongolub/release-testing.git/compare/@antongolub/release-testing-package-second@1.0.0...@antongolub/release-testing-package-second@1.0.1) (2019-03-12)
### Performance Improvements
* tech release ([c7e9bfa](https://github.com/antongolub/release-testing.git/commit/c7e9bfa))
* tech release ([f911408](https://github.com/antongolub/release-testing.git/commit/f911408))
HEAD detached from d185edf
Changes not staged for commit:
	modified:   ../../bar/release-testing-package-fourth/CHANGELOG.md
	modified:   ../release-testing-package-first/CHANGELOG.md
	modified:   CHANGELOG.md
	modified:   ../release-testing-package-third/CHANGELOG.md

I have no idea, how to handle this case. Sem-rel core pushes tags right after prepare step

await plugins.prepare(context);

  if (options.dryRun) {
    logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`);
  } else {
    // Create the tag before calling the publish plugins as some require the tag to exists
    await tag(nextRelease.gitTag, {cwd, env});
    await push(options.repositoryUrl, {cwd, env});
    logger.success(`Created tag ${nextRelease.gitTag}`);
  }
@dhoulb
Copy link
Owner

dhoulb commented Mar 13, 2019

Hmmmmmm — I've done a very quick look into this and I think it's because multiple git CLI calls are being made simultaneously. I had to do some hacks to avoid this in the package to make sure the tag pushing calls were staggered — but I didn't do it for the prepare step.

This is because internally to semantic-release and @semantic-release/git, git push etc are called asyncronously (using the exec() method). The easy fix would be for semantic-release to just use exec.sync() instead.

I don't want to fix this in multi-semantic-release since this project is just a POC for learning and I don't want to invest time into it (I'd happily accept PRs though). 

I'm still hoping to get semantic-release to take my recommendations and bake in monorepo support natively! I'm hoping to get some availability to prep a PR for that at some point. I've noted the need to change execa() to execa.sync() (which would fix this issue), and it seems like that would need to be changed in @semantic-release/git too.

@antongolub
Copy link
Collaborator Author

antongolub commented Mar 14, 2019

Oook — I've tested the hypothesis of replacing execa calls withexeca.sync with dirty module hook.

const execa = require('execa')
const hook = require('require-in-the-middle')
const { sync, stdout, stderr, shell, shellSync } = execa

const _execa = (...args) => {
  const result =  new Promise((resolve, reject) => {
    try {
      resolve(sync(...args))
    } catch (e) {
      reject(e)
    }
  })

  result.stdout.pipe = () => {}
  result.stderr.pipe = () => {}
}


Object.assign(_execa, execa)
_execa.sync = sync
_execa.stdout = stdout
_execa.stderr = stderr
_execa.shell = shell
_execa.shellSync = shellSync

delete require.cache[require.resolve('execa')]

hook(['execa'], () => _execa)

require('multi-semantic-release/bin/cli')

And here's what happens after:

  • sem-rel asserts tagFormat
  • checks that working directory matches to the project root

Next I'll try to bypass these checks. Hold on.

@antongolub
Copy link
Collaborator Author

I've missed the return... and it definitely looks good now

@dhoulb
Copy link
Owner

dhoulb commented Mar 15, 2019

Anton thanks so much for testing, that's extremely useful to know!

It would be possible then to fix this in multi-semantic-release too by serializing the calls to plugins.prepare() with some hacky Promise manipulation. I don't know if that's worth doing, but it's great to have the hypothesis confirmed!

@dhoulb
Copy link
Owner

dhoulb commented Mar 18, 2019

🎉 This issue has been resolved in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

qiwibot referenced this issue in qiwi/multi-semantic-release Nov 3, 2019
# [1.1.0](v1.0.3...v1.1.0) (2019-11-03)

### Bug Fixes

* **package:** add missed sem-rel plugins ([f3c9318](f3c9318))
* **package:** update execa to be compatible with sem-rel 15.13.28 ([069bb4e](069bb4e)), closes [#7](#7)
* force a release ([1e3ece5](1e3ece5))

### Features

* add execasync CLI flag to make execa calls be always synchronous ([693438c](693438c)), closes [#1](#1)
dhoulb pushed a commit that referenced this issue Jun 2, 2020
dhoulb pushed a commit that referenced this issue Jun 2, 2020
# [2.5.0](qiwi/multi-semantic-release@v2.4.3...v2.5.0) (2020-05-20)

### Bug Fixes

* publish updated deps ([791f55a](qiwi/multi-semantic-release@791f55a)), closes [#1](qiwi/multi-semantic-release#1)

### Features

* add execa queued hook ([042933e](qiwi/multi-semantic-release@042933e))
* apply queuefy to plugin methods instead of execa ([9ae7d0d](qiwi/multi-semantic-release@9ae7d0d))
@dhoulb
Copy link
Owner

dhoulb commented Jun 2, 2020

🎉 This issue has been resolved in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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