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

Unclear how to get the generated version into each application's build with nx affected #34

Closed
mklueh opened this issue Dec 11, 2022 · 3 comments
Assignees

Comments

@mklueh
Copy link

mklueh commented Dec 11, 2022

Hello,

I'm trying to understand how to use this plugin. Let's say I just want to show somewhere in my application what the current version is, then I need to pass the version information into each application's build.

My current setup is something like this:

      - name: Semantic Release
        run: nx nx affected --target=semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Deploying changed apps
         run: nx affected --target=build-and-deploy
            

How would that be possible? Is the version info stored somewhere in context of the app, or would I have to combine semantic release and build + deploy into one single script myself?

@TheUnderScorer
Copy link
Owner

Hey @mklueh!

Usually, this can be achieved by creating package.json in your application directory. For example:

{
  "name": "my-app",
  "version": "1.0.0"
  "private" true
}

You will also need to set npm: true in your semantic-release configuration. Because the private is set to true, it won't be published to NPM, but during release the version in package.json will be bumped, and you will be able to access it in your app like this:

import { version } from './package.json';

console.log(version);

I hope that it helps!

@TheUnderScorer TheUnderScorer self-assigned this Dec 11, 2022
@mklueh
Copy link
Author

mklueh commented Dec 12, 2022

@TheUnderScorer thank you! I'll try that

@mklueh
Copy link
Author

mklueh commented Dec 20, 2022

@TheUnderScorer I've finally managed to try it and failed to far. The only thing that is changed and pushed is the changelog, but not the versions.

My config is within the package.json and in all my package.jsons private is set to true and I've tried setting npm: true in the root package.json as well as the application one's with no effect. The version is set to 0.0.1 in the application only.

It seems the npm plugin is not running after the changelog plugin, despite having explicitly installed it

[8:09:59 AM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/changelog"
[8:09:59 AM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/changelog"
[8:09:59 AM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/git"
[8:09:59 AM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/git"

Edit: my mistake

I've set the option in nxrelease config instead of the executor options

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

No branches or pull requests

2 participants