Giter Club home page Giter Club logo

semver's Introduction

@jscutlery/semver NPM package @jscutlery/semver coverage status

@jscutlery/semver

Nx plugin for versioning using SemVer and CHANGELOG generation powered by Conventional Commits.

Setup

Install

npm install -D @jscutlery/semver
nx g @jscutlery/semver:install

This package allows you to manage your Nx workspace using one of two modes: Synced or Independent.

Independent mode (default)

Allow multiple projects to be versioned independently. This way you release only what you want and consumers don't get updates they don't need. This allows small, rapid and incremental adoption of your packages.

Synced mode

Allow multiple projects to be versioned in a synced/locked mode. Use this if you want to automatically tie all package versions together. This mode is useful when you are working with only one product. One issue with this approach is that a major change in any project will result in all projects having a new major version.

Usage

Release

Independent mode

Release project independently by running:

nx run my-project:version [...options]

You can leverage the affected command to only version changed packages:

nx affected --target version [...options]

Synced mode

Release workspace by running:

nx run workspace:version [...options]

When run, this executor does the following

  1. Retrieve the current version by looking at the last git tag.
  2. Bump package.json version based on the commits.
  3. Generates CHANGELOG based on the commits (uses conventional-changelog-angular under the hood).
  4. Creates a new commit including the package.json file and updated CHANGELOG.
  5. Creates a new tag with the new version number.
  6. Pushes the version to the remote repository.
  7. Runs post-targets hook to publish the version on NPM, GitHub or GitLab.

Available options

name type default description
--dryRun boolean false run with dry mode
--noVerify boolean false skip git hooks
--push boolean false push the release to the remote repository
--syncVersions boolean false lock/sync versions between projects
--skipRootChangelog boolean false skip generating root changelog
--skipProjectChangelog boolean false skip generating project changelog
--origin string 'origin' push against git remote repository
--baseBranch string 'main' push against git base branch
--changelogHeader string undefined custom Markdown header for changelogs
--releaseAs string undefined specify the level of change (details)
--preid string undefined specify the prerelease identifier (eg: alpha, beta) (details)
--tagPrefix string undefined specify the tag prefix (details)
--postTargets string[] [] specify the list of target to execute post-release (details)
--trackDeps boolean false bump dependent packages (bump A if A depends on B) (details)
--allowEmptyRelease boolean false force a patch increment even if library source didn't change
--skipCommitTypes string[] [] treat commits with specified types as non invoking version bump (details)
--skipCommit boolean false skips generating a new commit, leaves all changes in index, tag would be put on last commit (details)
--commitMessageFormat string undefined format the auto-generated message commit (details)
--preset string | object 'angular' customize Conventional Changelog options (details)
--commitParserOptions object undefined customize the commit parserConfig (details)

Guides

Overwrite default configuration

You can customize the default configuration using the definition file:

{
  "executor": "@jscutlery/semver:version",
  "options": {
    "baseBranch": "master",
    "preset": "atom",
    "tagPrefix": "{projectName}@"
  }
}

Customizing Conventional Changelog

This tool comes with a list of pre-configured presets:

Complete list of presets

The preset is highly configurable, following the conventional-changelog-config-spec. As an example, suppose you're using GitLab, rather than GitHub, you might modify the following variables:

{
  "executor": "@jscutlery/semver:version",
  "options": {
    "preset": {
      "commitUrlFormat": "{{host}}/{{owner}}/{{repository}}/commit/{{hash}}",
      "compareUrlFormat": "{{host}}/{{owner}}/{{repository}}/compare/{{previousTag}}...{{currentTag}}",
      "issueUrlFormat": "{{host}}/{{owner}}/{{repository}}/issues/{{id}}",
      "types": [
        { "type": "feat", "section": "โœจ Features" },
        { "type": "fix", "section": "๐Ÿž Bug Fixes" },
        { "type": "chore", "hidden": true }
      ]
    }
  }
}

Note

When customizing a preset it will implicitly use the conventionalcommits preset and override the default settings with the given configuration.

It is possible to customize any preset by passing its name.

{
  "executor": "@jscutlery/semver:version",
  "options": {
    "preset": {
      "name": "angular",
      "types": [
        { "type": "feat", "section": "โœจ Features" },
        { "type": "fix", "section": "๐Ÿž Bug Fixes" }
      ]
    }
  }
}

See the conventional-changelog-config-spec for available configuration options.

Customizing the commit parser

You may customize the config for the commit parser. This can be helpful when you are using an adapted version of conventional commit for instance.

{
  "executor": "@jscutlery/semver:version",
  "options": {
    "commitParserOptions": {
      "headerPattern": "^([A-Z]{3,}-\\d{1,5}):? (chore|build|ci|docs|feat|fix|perf|refactor|test)(?:\\(([\\w-]+)\\))?\\S* (.+)$",
      "headerCorrespondence": ["ticketReference", "type", "scope", "subject"]
    }
  }
}

See the conventional-commits-parse specification for available configuration options.

Version calculation

This package is tag-based, which means it never reads the package.json to retrieve the current version. Instead, it looks for a tag matching the --tagPrefix (i.e demo-x.y.z). Then, if no tag is found it fallbacks to 0.0.0, and calculates the initial version based on all changes since the first commit. In the other case, if there are matching tags, it retrieves the last one and calculates the new version from it.

Important

To detect a new version this package looks into the commit history and checks if any source files changed since the last version. Note that merge commits are ignored by the tool when calculating next version to bump.

Major zero version 0.x.y is for initial development. Anything may change at any time so the consumer won't get any new minor version using the caret or tilde compatibility range, for instance version 0.3.1 won't be resolved if the consumer wants ^0.2.0.

Specify the level of change

The --releaseAs option allows you to release a project with a version that is incremented by a specified level.

Level can be one of major, minor, patch, premajor, preminor, prepatch, or prerelease, for instance:

nx run workspace:version --releaseAs=major
nx run workspace:version --releaseAs=minor
nx run workspace:version --releaseAs=patch
nx run workspace:version --releaseAs=prerelease --preid=alpha
nx run workspace:version --releaseAs=prerelease --preid=beta

Initial prerelease version

When using the --releaseAs=prerelease option, the initial prerelease version takes into account the commit history to determine the recommended bump type. As an illustration, let's assume the current version is 1.0.0, and the commit history includes the following:

  • Commit 1: feat(my-project): abc
  • Commit 2: fix(my-project): def

Running the following command:

nx version my-project --releaseAs=prerelease --preid=alpha

Would yield the version 1.1.0-alpha.0. Subsequent executions of the command would result in incremented prerelease versions, such as 1.1.0-alpha.1.

Tag prefix customization

The --tagPrefix option allows you to customize the tag prefix.

In sync mode only one tag is created for the whole workspace, the tag prefix is set to v by default, which is resolved for instance to v0.0.1.

In independent mode, the tag prefix uses the contextual project name, the default value is {projectName}- which is resolved for instance to my-project-0.0.1. Note that each project in the workspace is versioned with its tag.

Commit message customization

The --commitMessageFormat option allows you to customize the commit message. By default, the commit message is formatted as the following:

chore({projectName}): release version {version}

Contextual variables resolved by this option:

  • version the current release version (for instance 1.0.0)
  • projectName the project name to be versioned (for instance my-project)

Note that it's the right place to add common keywords to skip CI workflows, for example: [skip ci] for GitHub, eg:

release: bump {projectName} to {version} [skip ci]

Skipping release for specific types of commits

To avoid releasing a new version if something non-influencing on release was changed (for example, documentation), you can provide skipCommitTypes option. In this case, any commit with a specified type would be ignored when calculating if there is a need to bump version. For example, if you had only one commit from the last version:

docs(project): update documentation about new feature

would not cause a new release (because --skipCommitTypes=docs,ci was specified).

And two commits:

docs(project): update documentation about new feature
fix(project): get rig of annoying bug

would produce a patch bump.

Note

Please keep in mind that changelog would be generated by conventional-changelog which ignores some types by design (i.e. docs, test and others).

Skipping commit

In some cases, your release process relies only on tags and you don't want a new commit with version bumps and changelog updates to be made. To achieve this, you can provide the --skipCommit flag and changes made by the library would stay in the index without committing. The tag for the new version would be put on the last existing commit.

Triggering executors post-release

The --postTargets option allows you to run targets post-release. This is particularly handful for publishing packages on a registry or scheduling any other task.

Here is a configuration example using @jscutlery/semver:github to create a GitHub Release and ngx-deploy-npm:deploy to publish on NPM:

{
  "targets": {
    "build": {
      /* ... */
    },
    "version": {
      "executor": "@jscutlery/semver:version",
      "options": {
        "push": true,
        "postTargets": ["build", "npm", "github"]
      }
    },
    "github": {
      "executor": "@jscutlery/semver:github",
      "options": {
        "tag": "{tag}",
        "notes": "{notes}"
      }
    },
    "npm": {
      "executor": "ngx-deploy-npm:deploy",
      "options": {
        "access": "public",
        "distFolderPath": "dist/packages/my-package"
      }
    }
  }
}

Contextual variables resolved by this option:

  • projectName versioned project name
  • version semver version
  • tag formatted git tag
  • notes release notes
  • previousTag previous version tag
  • dryRun dry run mode

Note

The specified targets are going to be executed as is, without triggering any dependencies. It will not trigger the target's dependsOn and Nx caching is not considered

Built-in post-targets

Tracking dependencies

The --trackDeps option indicates that direct dependencies in the project's dependency graph should be taken into account when incrementing the version. If no version-incrementing changes are present in the project but are present in one or more dependencies, then the project will receive a patch version increment.

If you wish to track changes at any depth of your dependency graph, then you should do the following:

  1. Enable versioning for each project in the dependency graph
  2. Set the trackDeps option to true on each of the projects
  3. Make sure that version is run on projects in the right order by configuring version's target dependencies in nx.json:
{
  "targetDefaults": {
    "version": {
      "dependsOn": ["^version"]
    }
  }
}

This setup will cause a cascade of version increments starting at the deepest changed dependency, then continuing up the graph until the indicated project is reached. Additionally, if used in conjunction with nx run-many --all, or nx affected, then it will avoid attempting to version dependencies multiple times.

Warning

Be aware that this feature has known limitations.

CI/CD usage

GitHub Actions

Here is an example running semver in a GitHub workflow:

name: release

on:
  - workflow_dispatch

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Use Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '16'
      - name: Setup Git
        run: |
          git config user.name "GitHub Bot"
          git config user.email "[email protected]"
      - run: yarn install --frozen-lockfile
      - name: Version
        shell: bash
        run: yarn nx affected --base=last-release --target=version
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Tag last-release
        shell: bash
        run: |
          git tag -f last-release
          git push origin last-release --force

Note that secrets.GITHUB_TOKEN is automatically provided by the GitHub Actions, you don't need to set up anything.

GitLab CI

Here is an example running semver in the GitLab CI:

stages:
  - release

release:
  rules:
    - if: $CI_COMMIT_BRANCH == "master"
      when: manual
  stage: release
  image: node:16.13.2
  before_script:
    - git config --global user.name "GitLab Bot"
    - git config --global user.email "[email protected]"
    - git remote set-url origin http://gitlab-ci-token:${DEPLOY_KEY}@gitlab.com/org/project.git
  script:
    - yarn install --frozen-lockfile
    - yarn nx affected --target=version --base=last-release
    - git tag -f last-release
    - git push origin last-release --force -o ci.skip

Note that you might need to configure a deploy key in order to push to your remote repository.

Nx Release migration

If you want to migrate to Nx Release, run the following command:

nx g @jscutlery/semver:migrate-nx-release

By executing this generator, the existing @jscutlery/semver configuration will be removed, and Nx Release will be appropriately configured for your projects.

Note

The migration process does not currently support the sync mode. Complex or highly customized configurations may require additional manual adjustments after running the migration generator. After running this generator, you will need to adjust any custom scripts or CI workflows related to versioning and releases to align with the new Nx release workflow.

For more details on using Nx Release, refer to the official Nx documentation.

Compatibility overview with Nx

Version Required Package
v5.0.0 @nx/devkit ^18.0.0
v4.0.0 @nx/devkit ^17.0.0
v3.0.0 @nx/devkit ^16.0.0
v2.28.0 @nrwl/devkit ^15.0.0
v2.23.0 @nrwl/devkit ^14.0.0
v2.12.0 @nrwl/workspace ^13.0.0
v2.4.0 @nrwl/workspace ^12.0.0
v1.0.0 @nrwl/workspace ^11.0.0

Changelog

For new features or breaking changes see the changelog.

Contributors

This project follows the all-contributors specification.

Younes Jaaidi
Younes Jaaidi

๐Ÿ› ๐Ÿ’ป ๐Ÿ“– ๐Ÿ’ก ๐Ÿค”
Edouard Bozon
Edouard Bozon

๐Ÿ› ๐Ÿ’ป ๐Ÿ“– ๐Ÿ’ก ๐Ÿค”
Gleb Mikheev
Gleb Mikheev

๐Ÿค”
Richard Lea
Richard Lea

๐Ÿ’ป
Katona
Katona

๐Ÿ› ๐Ÿ’ป
ntziolis
ntziolis

๐Ÿ›
RicardoJBarrios
RicardoJBarrios

๐Ÿ’ป ๐Ÿค”
Sylvain Arnouts
Sylvain Arnouts

๐Ÿ›
GethsLeader
GethsLeader

๐Ÿ’ป ๐Ÿค”
Shahar Kazaz
Shahar Kazaz

๐Ÿ’ป
Miloลก Lajtman
Miloลก Lajtman

๐Ÿ› ๐Ÿ’ป
Charley Bodkin
Charley Bodkin

๐Ÿ›
Jeffrey Bosch
Jeffrey Bosch

๐Ÿ’ป
RaviTejaVattem
RaviTejaVattem

๐Ÿ’ป
Abishek PY
Abishek PY

๐Ÿ’ป ๐Ÿ“–
Stefan Schneider
Stefan Schneider

๐Ÿ’ป
Travis Jones
Travis Jones

๐Ÿ’ป ๐Ÿ“– ๐Ÿค”
Hichri Hassen
Hichri Hassen

๐Ÿ›
Gareth John
Gareth John

๐Ÿ’ป
Diego Juliao
Diego Juliao

๐Ÿ› ๐Ÿ’ป ๐Ÿค”
Charlie Francis
Charlie Francis

๐Ÿ›
Pierre Huyghe
Pierre Huyghe

๐Ÿ’ป
William Sedlacek
William Sedlacek

๐Ÿ’ป ๐Ÿค”
Tycho Bokdam
Tycho Bokdam

๐Ÿค”
nicolashzmor
nicolashzmor

๐Ÿ›
Raรบl Juliรกn Lรณpez Caรฑa
Raรบl Juliรกn Lรณpez Caรฑa

๐Ÿ› ๐Ÿ’ป
Miguel Suarez
Miguel Suarez

๐Ÿ’ป
Katya Pavlenko
Katya Pavlenko

๐Ÿ› ๐Ÿ’ป ๐Ÿค”
Hoon Oh
Hoon Oh

๐Ÿ’ป ๐Ÿค”
Kurt Hoyt
Kurt Hoyt

๐Ÿ›
Riain Condon
Riain Condon

๐Ÿ’ป ๐Ÿ“– ๐Ÿ’ก
lukelukes
lukelukes

๐Ÿ›
Ian Luca
Ian Luca

๐Ÿ’ป ๐Ÿค”
Matthias Stemmler
Matthias Stemmler

๐Ÿ›
Giora Guttsait
Giora Guttsait

๐Ÿ›
Derek Burgman
Derek Burgman

๐Ÿ› ๐Ÿ’ป
James
James

๐Ÿ› ๐Ÿ’ป
ndrsg
ndrsg

๐Ÿ’ป ๐Ÿค” ๐Ÿ›
Fabian Schneider
Fabian Schneider

๐Ÿ› ๐Ÿ’ป
JD
JD

๐Ÿ“–
Daniel Beck
Daniel Beck

๐Ÿ’ป ๐Ÿ“–
Florian Guitton
Florian Guitton

๐Ÿ’ป
Sam Yong
Sam Yong

๐Ÿ› ๐Ÿ’ป
Jamie Thompson
Jamie Thompson

๐Ÿ›
Michael Be
Michael Be

๐Ÿ“–

License

This project is MIT licensed.

semver's People

Contributors

cakeinpanic avatar chigix avatar dereekb avatar dianjuar avatar edbzn avatar fabsrc avatar gethsleader avatar jdawber avatar jefiozie avatar kaoz70 avatar lucavb avatar mauris avatar mikelgo avatar miluoshi avatar nachovazquez avatar ndrsg avatar nowseemee avatar ravitejavattem avatar renovate-bot avatar renovate[bot] avatar riain0 avatar ricardojbarrios avatar rjlopezdev avatar shaharkazaz avatar tripss avatar tuffz avatar vj-abishek avatar wsedlacek avatar yjaaidi avatar zamiell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

semver's Issues

Versioning only for applications based on library changes

A few colleagues were looking for a solution to bump our application version based not only changes in the application code but also any libraries that it is dependent on. Is that possible with this module or will it only ever bump the version of the individual library or app when changed?

This sounds like a strange request. What we're looking to achieve is a way to kinda semantically version our overall application but most of the functionality of these is actually maintained in seperate libraries.

Thanks for this lib, was easy to get up and running and works like a charm.

Allow post bump actions using angular/nx targets

Users (including us) want to publish apps/docs/packages, and maybe do other stuff when semver bumps something.
As discussed with @edbzn, instead of implementing a custom plugin system or trying to hack our way to be compatible with semantic-release plugins, let's allow users to run any Angular/Nx target after bump.

This could look something like this:

{
  "name": "workspace",
  "root": ".",
  "architect": {
    "version": {
      "builder": "@jscutlery/semver:version",
      "options": {
        "configs": [
          {
            "name": "rx-state",
            "type": "independent"        
          },
          {
            "name": "cdk",
            "type": "group",
            "path": "packages/cdk",
            "projects": [
              "packages/cdk/operators",
              "packages/cdk/helpers" // or a wildcard "packages/cdk/*"
            ],
            "postTargets": [
              "helpers:deploy",
              {
                "name": "operators:deploy",
                "options": {
                  "my-deploy-option": "{{ version }}-jscutlery",
                  "is-dry-run": "{{ dryRun }}"
                }
              }
            ]
          }
        ]
      }
    }
   }
}

In the future, we could add a preTargets option.

By the way, should we call the option postTargets or postBump in order to add options like preChangelog and postChangelog in the future?

git push --atomic failed

I'm getting this error every time I try to run nx run workspace:version. The tag gets pushed to the remote repo, but the commits don't get uploaded. Any idea on how to solve this?

โˆš tagging release v1.11.15
i Run `git push --follow-tags origin main` to publish
git push --atomic failed, attempting non-atomic push
[object Object]
error Command failed with exit code 1.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Update to `@angular-devkit/[email protected]` break the builder

Bumping @angular-devkit/build-angular from 0.1100.5 to 0.1100.6 break the CLI and log the following error when running nx run semver:version:

Unable to resolve @jscutlery/semver:version.
Cannot find module '/home/edouard/work/jscutlery/semver/packages/semver/src/builders/version/builder'
Require stack:
- /home/edouard/work/jscutlery/semver/node_modules/@nrwl/tao/src/shared/workspace.js
- /home/edouard/work/jscutlery/semver/node_modules/@nrwl/tao/src/commands/run.js
- /home/edouard/work/jscutlery/semver/node_modules/@nrwl/tao/index.js
- /home/edouard/work/jscutlery/semver/node_modules/@nrwl/cli/lib/run-cli.js

Does it is related to Nx, or the angular-devkit itself? While this being resolved I revert the update.

`--version` flag is not being forwarded to nx builder

Current Behavior

When using the nx cli and passing --version=prerelease that option never makes it into my builder. It's as if I never passed the option

npx nx run workspace:version --version=prerelease --preid=beta --dry-run

> nx run workspace:version --preid=beta --dry-run --dryRun

Expected Behavior

passing in --version=x would actually get recognized as an option by the builder

Nx Issue?

I'm not quite sure if this is an issue with semver or with nx. I'm curious because it seems like an issue with nx from what I've dug into (as the option never even reaches the runBuilder function in runtime), but I can't believe that I'm the only user who is facing this issue. I have opened an issue in the nrwl/nx repo and will see if they have thoughts, but I'm curious if anyone else here has run into or seen this issue.

Environment


  Node : 12.22.1
  OS   : darwin x64
  yarn : 1.22.10
  
  nx : Not Found
  @nrwl/angular : 12.0.8
  @nrwl/cli : 12.0.8
  @nrwl/cypress : 12.0.8
  @nrwl/devkit : 12.0.8
  @nrwl/eslint-plugin-nx : 12.0.8
  @nrwl/express : Not Found
  @nrwl/jest : 12.0.8
  @nrwl/linter : 12.0.8
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : 12.0.8
  @nrwl/react : Not Found
  @nrwl/schematics : Not Found
  @nrwl/tao : 11.2.12
  @nrwl/web : Not Found
  @nrwl/workspace : 12.0.8
  @nrwl/storybook : Not Found
  @nrwl/gatsby : Not Found
  typescript : 4.1.5

Document how to use it in a CI environment

The main goal is to automate the release process and automation comes with continuous integration btw. We should document how to do this. We can start with GitHub actions.

Unable to use Plugin

Hi there I have tried to use this plug and added the following to my config asper documentation .

"version": {
"builder": "@jscutlery/semver:version",
"options": {
"push": true,
"remote": "origin",
"baseBranch": "origin/master"
}
}

all I get is the following is logged with nothing happening : nx run my-ap:version --dry-run . No package update or logs

ng-add schematic

The user should be able to add @jscutlery/semver in a workspace using a schematic.

  • install the package
  • ask options (remote, branch, push and syncVersions)
  • update the workspace.json or angular.json accordingly

Allow changing the default header in the changelog

Hi!

Great work guys, super powerful plugin!

I would like to suggest allowing the user to provide a custom header for the change log.

Currently it defaults to:


Changelog

This file was generated using @jscutlery/semver.


While this is great to promote this plugin and excelent as the default header, users should be able to provide their own header and not being force to promote something.

In the majority of the use cases users will probably not opt out, but some would like to have this option.

Thanks!

Copy root README.md to dist

It could be useful for some usecases, firstly for this package which have poor documentation on npm.

It could be an option --copy-root-readme

image

Bug: Fails when inital version is 0.0.1

When creating a new angular lib via nx the default initial version number of the package is 0.0.1 instead of 0.0.0. This causes the plugin to fail when executing nx run mylib:version.

When manually setting the version of to 0.0.0 the command starts working as expected.

Root cause is the following line:

since: version !== '0.0.0' ? `${tagPrefix}${version}` : null,

Suggestion:

  • either add an inital flag in the executer that does something like this:
    since: initial || version !== '0.0.0' ? `${tagPrefix}${version}` : null,
  • or at least fail with a more descriptive error telling the users to either:
    • update the version number of the respective package to 0.0.0
    • or create a tag for the current version number manually

Replace syncVersions by version grouping

This is a follow-up to the following discussion #98.

Given a repo with 3 packages a, b & c, one should be able to sync versions for a & b but still keep independent versioning for c; meaning that changing a would have to bump b as well.

The solution we agreed to is to use the project structure for grouping (using folders).

By creating a "group" project in workspace config, like we already do in sync mode with a root path set to the group folder. This way, Nx cache, and Nx dep graph might work.
This will just run the sync mode with a filter of projects that are in the group path. we also have to be careful about the root changelog.

Example:

{
  "name": "lumberjack",
  "root": "packages/lumberjack",
  "architect": {
    "version": {
      "builder": "@jscutlery/semver:version"
    },
  },
},
{
  "name": "spectacular",
  "root": "packages/spectacular",
  "architect": {
    "version": {
      "builder": "@jscutlery/semver:version"
    },
  },
},
{
  "name": "angular-group",
  "root": "packages/angular",
  "architect": {
    "version": {
      "builder": "@jscutlery/semver:version"
    },
  },
},
{
  "name": "angular-cdk",
  "root": "packages/angular/cdk",
  "architect": {"build": "..."}
},

2021-04-29 update

{
  "name": "workspace",
  "root": ".",
  "architect": {
    "version": {
      "builder": "@jscutlery/semver:version",
      "options": {
        "configs": [
          {
            "name": "rx-state",
            "type": "independent",
            // path is optional for independent versioning
            // as we can just pick the projectRoot in workspace.json
            // "path": "packages/rx-state", // we need this for git log & changelog path & root package.json
          },
          {
            "name": "cdk",
            "type": "group",
            "path": "packages/cdk",
            "packages": [
              "packages/cdk/operators",
              "packages/cdk/helpers", // or even a wildcard "packages/cdk/*"
            ]
          }
        ]
      }
    }
  }
}

  • If group root is "." then it's a workspace sync versioning so tag is vMAJOR.MINOR.PATCH
  • If group root is not "." then it's a group so tag is group-name-MAJOR.MINOR.PATCH
  • It would be nice to be compatible with both the current configuration syntax and the new one so we can rollout this new feature progressively in 2.x. The migration script can come later with 3.0 when the legacy syntax is not supported anymore.
  • Throw an error if a package has semver version while it's also in a group.
  • Consider adding a tagPrefix/--tag-prefix option in case a grouping folder needs to be renamed--for whatever reason--without breaking the version tags (maybe we should open a distinct issue)

cc. @LayZeeDK, @NachoVazquez, @santoshyadavdev, and @SerkanSipahi.

Bump version only if necessary

version schematic should add a latest git tag. This can be used as a base when running version on affected projects: nx affected --target version --base latest

v1.3.1 Failing silently on large monorepo

I have a monorepo with 750+ libraries. When I run

nx run workspace:version

The command finishes without any error but there was no version bump and no change logs generated

Dedicated sub CHANGELOGs with Sync mode

For now we only have one root CHANGELOG for the monorepo. There is some interest of having sub CHANGELOGs :

  • more concise and readable
  • optimized for release bots (eg @releasebutler)
  • ?

Fun fact: Lerna made this feature early, before they included a root CHANGELOG as an enhancement, see this.

It could be a new option for the version builder. We can use the standard-changelog package to generate sub CHANGELOGs.

Git index.lock file exists | --root-changelog not working

I believe this is a 2-part issue.

Our project contains 1000+ libraries. When I run nx run workspace:version, the semver plugin starts generating CHANGELOG.md files for every library. At some point it stops with the following error:

Error: Command failed: git add /Users/crash/git/iko-travel-spa/libs/shared/ui-date-time-picker-form/CHANGELOG.md
fatal: Unable to create '/Users/crash/git/iko-travel-spa/.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

    at ChildProcess.exithandler (child_process.js:308:12)
    at ChildProcess.emit (events.js:314:20)
    at maybeClose (internal/child_process.js:1022:16)
    at Socket.<anonymous> (internal/child_process.js:444:11)
    at Socket.emit (events.js:314:20)
    at Pipe.<anonymous> (net.js:675:12)

I am not running any other process of Git.

The second part of this issue is that, according to your documentation, it should just create / update a single
CHANGELOG.md file located in project root. I've tried updating the call by including:

nx run workspace:version --root-changelog=true

with no success.

I think there is definitely an error happening when there are too many projects and the lock file wasn't removed fast enough between change log generations. But this error is caused by the fact that the plugin should be generating only one change log but instead generates 1K+, in the case of my project.

Please let me know if I can provide you with anything else.

package.json of the libs is not updated

I am not sure if it is a bug or feature. When running:

nx run workspace:version

the changelog of the libs is udpated but no version bump is happening for the package.json in that lib.

    "workspace": {
      "architect": {
        "version": {
          "builder": "@jscutlery/semver:version",
          "options": {
            "syncVersions": true
          }
        }
      },
      "root": "."
    }

Combine semver with GitHub release

We are currently using semantic-release but semver could be the perfect replacement. However there is on scenario that I am struggling with: Besides creating the changelog we also want to publish a GitHub release

  • The problem is that semver will end the process with creating a tag.
  • If I now e.g. want to use the gh cli to create a release I would be in trouble because the tag has already been created

Is there a smart way out of that?

Any way get current version in package executor of web:lib?

I am trying to get the current version of the library to use it in the outputPath path of package executor. Is there a way to get the version in workspace.json to do something like

"package": {
  "executor": "@nrwl/web:package",
  "options": {
    "project": "package.json",
    "outputPath": "dist/libs/element-base/{version}",
    "entryFile": "libs/element-base/src/index.ts",
    "tsConfig": "libs/element-base/tsconfig.lib.json"
  }
}

Feature Request: Bump versions explicitly based on passed in parameters

It would be great to be able to bump versions explicitly based on a passed in parameter. This is similar in nature to Lerna's version command.

I think this command could look like:

# would patch all affected packages
nx affected --target version --semver-type patch
# would patch all packages
nx run workspace:version --semver-type patch

Missing workspace.json

When executing nx run workspace:version --sync-versions true --root-changelog false in my nx repo I get the following warning:

(node:7184) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'project/workspace.json'
(Use `node --trace-warnings ...` to show where the warning was created)
(node:7184) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:7184) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

NX version: "@nrwl/workspace": "11.1.5"

Prompt for projects list when user chooses independent mode

ng-add schematics should prompt user to select the projects to version.

syncVersions only create a new changelog for affected libraries

I guess the following "works as designed" but can cause problems:

When using the following setting:

    "workspace": {
      "architect": {
        "version": {
          "builder": "@jscutlery/semver:version",
          "options": {
            "syncVersions": true
          }
        }
      },
      "root": "."
    }

the changelog is only created for some libraries - probably affected ? But when keeping all the versions in sync I always need to publish a new version of all libs - no matter if they are affected or not. So the package.json should be updated in any case and probably an empty changelog as well? At least that is the standard behaviour when using something like standard-changelog

FR: Add commitlint, husky and commitizen

The use of standard-version is tightly coupled to the use of conventional-changelog-angular, and the use of these libraries has become a de facto standard to enforce correct use. It would be nice to allow the installation and configuration of these libraries, even if it is optional.

  • commitlint: check commit messages to follow the conventional commit pattern
  • husky: hook into git events and run code at specific points
  • commitizen: helper for writing conventional commit messages

I'm now testing the setup of these libraries with semver to ensure that all works well together.

The project ngx-semantic-version is doing something similar, but focused in Angular apps.

When --version option is used, bump even if no changes

We shouldn't check if there are changes or not when --version is used.

--version usage probably means there is an operator (human or machine) outside of semver so we don't need the idempotency security that avoid releasing empty versions.

Cf. we might need a --force option some day.

NPM publish

It could be useful to publish to npm directly using this package. It could be a new builder.

Does semver invalidate Nx caches when the CHANGELOG.md files are created?

Hi,

I would like to verify my workflow:

Steps:

  1. Build entire project in develop branch successfully
  2. Run your semver plugin
  3. Push to master
  4. Build everything again in develop branch

At Step 4., has the semver plugin invalidated all the caches for the libraries where it updated the CHANGELOG.md file?

If yes, is there a way to avoid doing that?

Thank you

Can independent mode run over all libraries at once and produce single commit (not multiple)?

Guys, i'm sorry for be so bothersome ๐Ÿ™„

Sync mode update all changelogs and package.json versions at once (with one single version) and produce single "bump" commit.
Indepdendent mode goes for each library and produce multiple "bump" commit for each library.

Is it possible to run independent mode like sync mode (over all apps and libs) and produce single commit not multiple?

Thank you!) ๐Ÿบ

Migrations script is not detected by Nx

Running nx migrate @jscutlery/semver doesn't detect migrations. The package.json and migrations.json look good though.

Here is the output:

Fetching meta data about packages.
It may take a few minutes.
Fetching @jscutlery/[email protected]

>  NX  The migrate command has run successfully.

- package.json has been updated
- there are no migrations to run, so migrations.json has not been created.

>  NX  Next steps:

- Make sure package.json changes make sense and then run 'yarn'
- To learn more go to https://nx.dev/latest/core-concepts/updating-nx
- You may run "nx connect-to-nx-cloud" to get faster builds, Github integration, and more. Check out https://nx.app

  • once fixed, we have to document the nx migrate command.

Custom rulset for "conventional-changelog-angular" settings

In our current release process we have modified the ruleset in some aspects like this:

{
    "preset": "angular",
    "releaseRules": [
        { "breaking": true, "release": "minor" },
        { "tag": "Breaking", "release": "minor"}
    ]
}

Is it possible to pass a custom config to semver as well?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.