Skip to content

Commit

Permalink
feat: added option to skip stage
Browse files Browse the repository at this point in the history
  • Loading branch information
mta-trackunit committed Nov 29, 2024
1 parent 58c7086 commit 9ff9580
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ nx run workspace:version [...options]
| **`--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](https://github.com/jscutlery/semver#skipping-release-for-specific-types-of-commits)) |
| **`--skipCommit`** | `boolean` | `false` | skips generating a new commit, leaves all changes in index, tag would be put on last commit ([details](https://github.com/jscutlery/semver#skipping-commit)) |
| **`--skipStage`** | `boolean` | `false` | skips add to git stage, useful when you want to run nx cmd in parallel ([details](https://github.com/jscutlery/semver#skipping-stage)) |
| **`--commitMessageFormat`** | `string` | `undefined` | format the auto-generated message commit ([details](https://github.com/jscutlery/semver#commit-message-customization)) |
| **`--preset`** | `string \| object` | `'angular'` | customize Conventional Changelog options ([details](https://github.com/jscutlery/semver#customizing-conventional-changelog)) |
| **`--commitParserOptions`** | `object` | `undefined` | customize the commit parserConfig ([details](https://github.com/jscutlery/semver#customizing-the-commit-parser)) |
Expand Down Expand Up @@ -284,6 +285,10 @@ In some cases, your release process relies only on tags and you don't want a new
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.

### Skipping Stage

In case you want to run nx cmd in parallel, you can provide the `--skipStage` flag and it will not add to git stage - since that requires a git-lock, this has to be used together with `--skipCommit` and `--skipTag` and not with `--push`, all for the same reason they will require a git-lock.

### 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.
Expand Down
3 changes: 3 additions & 0 deletions packages/semver/src/executors/version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default async function version(
allowEmptyRelease,
skipCommitTypes,
skipCommit,
skipStage,
commitParserOptions,
} = _normalizeOptions(options);

Expand Down Expand Up @@ -135,6 +136,7 @@ export default async function version(
commitMessage,
dependencyUpdates,
skipCommit,
skipStage,
workspace: context.projectsConfigurations,
};

Expand Down Expand Up @@ -241,6 +243,7 @@ function _normalizeOptions(options: VersionBuilderSchema) {
commitMessageFormat: options.commitMessageFormat as string,
commitParserOptions: options.commitParserOptions,
skipCommit: options.skipCommit as boolean,
skipStage: options.skipStage as boolean,
preset: (options.preset === 'conventional'
? 'conventionalcommits'
: options.preset || 'angular') as PresetOpt,
Expand Down
1 change: 1 addition & 0 deletions packages/semver/src/executors/version/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface VersionBuilderSchema {
postTargets: string[];
allowEmptyRelease?: boolean;
skipCommitTypes?: string[];
skipStage?: boolean;
commitMessageFormat?: string;
preset: PresetOpt | 'conventional'; // @TODO: Remove 'conventional' in the next major release.
commitParserOptions?: CommitParserOptions;
Expand Down
5 changes: 5 additions & 0 deletions packages/semver/src/executors/version/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
"type": "boolean",
"default": false
},
"skipStage": {
"description": "Allows to skip adding files to git stage.",
"type": "boolean",
"default": false
},
"skipCommitTypes": {
"description": "Specify array of commit types to be ignored when calculating next version bump.",
"type": "array",
Expand Down
17 changes: 17 additions & 0 deletions packages/semver/src/executors/version/utils/git.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ describe('git', () => {
addToStage({
paths: ['packages/demo/file.txt', 'packages/demo/other-file.ts'],
dryRun: false,
skipStage: false,
}),
);

Expand All @@ -185,13 +186,29 @@ describe('git', () => {
);
});

it('should skip add to git stage if skipStage is true', async () => {
jest.spyOn(cp, 'exec').mockReturnValue(of('ok'));

await lastValueFrom(
addToStage({
paths: ['packages/demo/file.txt', 'packages/demo/other-file.ts'],
dryRun: false,
skipStage: true,
}),
{ defaultValue: undefined },
);

expect(cp.exec).not.toBeCalled();
});

it('should skip git add if paths argument is empty', async () => {
jest.spyOn(cp, 'exec').mockReturnValue(of('ok'));

await lastValueFrom(
addToStage({
paths: [],
dryRun: false,
skipStage: false,
}),
{ defaultValue: undefined },
);
Expand Down
4 changes: 4 additions & 0 deletions packages/semver/src/executors/version/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,16 @@ export function tryPush({
export function addToStage({
paths,
dryRun,
skipStage,
}: {
paths: string[];
dryRun: boolean;
skipStage: boolean;
}): Observable<void> {
if (paths.length === 0) {
return EMPTY;
} else if (skipStage) {
return EMPTY;
}

const gitAddOptions = [...(dryRun ? ['--dry-run'] : []), ...paths];
Expand Down
9 changes: 8 additions & 1 deletion packages/semver/src/executors/version/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface CommonVersionOptions {
tagPrefix: string;
changelogHeader: string;
skipCommit: boolean;
skipStage: boolean;
commitMessage: string;
projectName: string;
skipProjectChangelog: boolean;
Expand All @@ -50,6 +51,7 @@ export function versionWorkspace({
projectName,
tag,
skipCommit,
skipStage,
projectRoot,
...options
}: {
Expand All @@ -70,6 +72,7 @@ export function versionWorkspace({
noVerify,
projectName,
skipCommit,
skipStage,
tag,
...options,
}),
Expand All @@ -90,6 +93,7 @@ export function versionWorkspace({
addToStage({
paths,
dryRun,
skipStage,
}),
),
concatMap(() =>
Expand Down Expand Up @@ -124,6 +128,7 @@ export function versionProject({
tagPrefix,
projectName,
skipCommit,
skipStage,
tag,
...options
}: {
Expand All @@ -138,6 +143,7 @@ export function versionProject({
commitMessage,
dryRun,
skipCommit,
skipStage,
noVerify,
tagPrefix,
tag,
Expand All @@ -153,7 +159,7 @@ export function versionProject({
dependencyUpdates: options.dependencyUpdates,
}).pipe(
concatMap((changelogPath) =>
addToStage({ paths: [changelogPath], dryRun }),
addToStage({ paths: [changelogPath], dryRun, skipStage }),
),
)
: of(undefined),
Expand All @@ -170,6 +176,7 @@ export function versionProject({
? addToStage({
paths: [packageFile],
dryRun,
skipStage,
})
: of(undefined),
),
Expand Down

0 comments on commit 9ff9580

Please sign in to comment.