jscutlery / semver

Nx plugin to automate semantic versioning and CHANGELOG generation.
MIT License
719 stars 83 forks source link

Question about `post-targets` and n`gx-deploy-npm:deploy` #760

Closed eXigentCoder closed 6 months ago

eXigentCoder commented 6 months ago

Hey there,

Firstly thanks so much, this library is awesome! My question is do the post-targets all run in parallel or in series? I took a look at the code and i'm not familiar with rxjs but I suspect it's in parallel?

The reason I ask is that my GitHub Action for my NX monorepo workflow is as follows:

  1. Version all affected local npm packages using your library. Sometimes there is no need for a version bump
  2. Push the commit + tags back to the origin (commit messages have [skip ci] so doesn't fire off a new GitHub Action).
  3. Build the package.json dependencies for the local npm libraries so that they have the latest versions of cross dependencies in them
  4. publish all affected local libraries to npm. ⬅️ This step is failing because it's trying to push a version that already exists as there is no change to some of the libs.

I wanted to look at using the post-targets as described in this issue to kick off my build-package-json target and then the publish target, but if they happen in parallel It might build the package before dependencies have been injected.

Right now I have just added continue-on-error: true to my publish action, but it's not great since if it fails to publish for a legitimate reason the build will still succeed.

Also, just to confirm, both my version and publish targets have configurations within them, I can't see a way to specify which configuration the post-target should use, but from looking at the code I think it will inherit whichever configuration the version target was using, is that correct?

Would love some clarification/advice here, thanks!

edbzn commented 6 months ago

Hi @eXigentCoder,

My question is do the post-targets all run in parallel or in series? I took a look at the code and i'm not familiar with rxjs but I suspect it's in parallel?

By design post-targets run in series to avoid race-conditions.

I wanted to look at using the post-targets as https://github.com/bikecoders/ngx-deploy-npm/issues/70 to kick off my build-package-json target and then the publish target, but if they happen in parallel It might build the package before dependencies have been injected.

Yes, it's exactly why we introduced post-targets, they only run on versioned projects so I think it's what you need in your case.

I can't see a way to specify which configuration the post-target should use, but from looking at the code I think it will inherit whichever configuration the version target was using, is that correct?

You can pass a configuration to your post-target like this: "postTargets": ["my-proj:target:config"].

Hope it helps.

eXigentCoder commented 6 months ago

Awesome stuff, thanks so much and keep up the great work, appreciate it! ❤️