Skip to content

Commit

Permalink
feat(release): conventional-commits, git-tag, and single generator
Browse files Browse the repository at this point in the history
  • Loading branch information
fahslaj committed Oct 16, 2023
1 parent 2cc1561 commit b91946c
Show file tree
Hide file tree
Showing 12 changed files with 629 additions and 167 deletions.
16 changes: 13 additions & 3 deletions docs/generated/packages/js/generators/release-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@
},
"specifier": {
"type": "string",
"description": "Exact version or semver keyword to apply to the selected release group. NOTE: This should be set on the release group level, not the project level."
"description": "Exact version or semver keyword to apply to the selected release group. Overrides specifierSource."
},
"releaseGroupName": {
"type": "string",
"description": "The name of the release group being versioned in the current execution."
},
"specifierSource": {
"type": "string",
"default": "prompt",
"description": "Which approach to use to determine the semver specifier used to bump the version of the project.",
"enum": ["prompt", "conventional-commits"]
},
"preid": {
"type": "string",
Expand All @@ -34,15 +44,15 @@
"type": "string",
"default": "disk",
"description": "Which approach to use to determine the current version of the project.",
"enum": ["registry", "disk"]
"enum": ["registry", "disk", "git-tag"]
},
"currentVersionResolverMetadata": {
"type": "object",
"description": "Additional metadata to pass to the current version resolver.",
"default": {}
}
},
"required": ["projects", "projectGraph", "specifier"],
"required": ["projects", "projectGraph", "releaseGroupName"],
"presets": []
},
"description": "DO NOT INVOKE DIRECTLY WITH `nx generate`. Use `nx release version` instead.",
Expand Down
148 changes: 148 additions & 0 deletions e2e/release/src/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
runCLI,
runCommandAsync,
runCommandUntil,
tmpProjPath,
uniq,
updateJson,
} from '@nx/e2e/utils';
Expand Down Expand Up @@ -546,5 +547,152 @@ describe('nx release', () => {

// port and process cleanup
await killProcessAndPorts(process.pid, verdaccioPort);

// Add custom nx release config to control version resolution
updateJson<NxJsonConfiguration>('nx.json', (nxJson) => {
nxJson.release = {
groups: {
default: {
// @proj/source will be added as a project by the verdaccio setup, but we aren't versioning or publishing it, so we exclude it here
projects: ['*', '!@proj/source'],
version: {
generator: '@nx/js:release-version',
generatorOptions: {
// Resolve the latest version from the git tag
currentVersionResolver: 'git-tag',
currentVersionResolverMetadata: {
tagVersionPrefix: 'xx',
},
},
},
},
},
};
return nxJson;
});

// Add a git tag to the repo
execSync(`git tag -a xx1100.0.0 -m xx1100.0.0`, {
cwd: tmpProjPath(),
});

const versionOutput3 = runCLI(`release version minor`);
expect(
versionOutput3.match(/Running release version for project: my-pkg-\d*/g)
.length
).toEqual(3);
expect(
versionOutput3.match(
/Reading data for package "@proj\/my-pkg-\d*" from my-pkg-\d*\/package.json/g
).length
).toEqual(3);

// It should resolve the current version from the git tag once...
expect(
versionOutput3.match(
new RegExp(
`Resolved the current version as 1100.0.0 from git tag "xx1100.0.0"`,
'g'
)
).length
).toEqual(1);
// ...and then reuse it twice
expect(
versionOutput3.match(
new RegExp(
`Using the current version 1100.0.0 already resolved from git tag "xx1100.0.0"`,
'g'
)
).length
).toEqual(2);

expect(
versionOutput3.match(
/New version 1100.1.0 written to my-pkg-\d*\/package.json/g
).length
).toEqual(3);

// Only one dependency relationship exists, so this log should only match once
expect(
versionOutput3.match(
/Applying new version 1100.1.0 to 1 package which depends on my-pkg-\d*/g
).length
).toEqual(1);

createFile(
`${pkg1}/my-file.txt`,
'update for conventional-commits testing'
);

// Add custom nx release config to control version resolution
updateJson<NxJsonConfiguration>('nx.json', (nxJson) => {
nxJson.release = {
groups: {
default: {
// @proj/source will be added as a project by the verdaccio setup, but we aren't versioning or publishing it, so we exclude it here
projects: ['*', '!@proj/source'],
version: {
generator: '@nx/js:release-version',
generatorOptions: {
specifierSource: 'conventional-commits',
currentVersionResolver: 'git-tag',
currentVersionResolverMetadata: {
tagVersionPrefix: 'xx',
},
},
},
},
},
};
return nxJson;
});

const versionOutput4 = runCLI(`release version`);

expect(
versionOutput4.match(/Running release version for project: my-pkg-\d*/g)
.length
).toEqual(3);
expect(
versionOutput4.match(
/Reading data for package "@proj\/my-pkg-\d*" from my-pkg-\d*\/package.json/g
).length
).toEqual(3);

// It should resolve the current version from the git tag once...
expect(
versionOutput4.match(
new RegExp(
`Resolved the current version as 1100.0.0 from git tag "xx1100.0.0"`,
'g'
)
).length
).toEqual(1);
// ...and then reuse it twice
expect(
versionOutput4.match(
new RegExp(
`Using the current version 1100.0.0 already resolved from git tag "xx1100.0.0"`,
'g'
)
).length
).toEqual(2);

expect(versionOutput4.match(/Skipping versioning/g).length).toEqual(3);

execSync(
`git add ${pkg1}/my-file.txt && git commit -m "feat!: add new file"`,
{
cwd: tmpProjPath(),
}
);

const versionOutput5 = runCLI(`release version`);

expect(
versionOutput5.match(
/New version 1101.0.0 written to my-pkg-\d*\/package.json/g
).length
).toEqual(3);
}, 500000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('release-version', () => {
projectGraph,
specifier: 'major',
currentVersionResolver: 'disk',
releaseGroupName: 'default',
});
expect(readJson(tree, 'libs/my-lib/package.json').version).toEqual('1.0.0');

Expand All @@ -66,6 +67,7 @@ describe('release-version', () => {
projectGraph,
specifier: 'minor',
currentVersionResolver: 'disk',
releaseGroupName: 'default',
});
expect(readJson(tree, 'libs/my-lib/package.json').version).toEqual('1.1.0');

Expand All @@ -74,6 +76,7 @@ describe('release-version', () => {
projectGraph,
specifier: 'patch',
currentVersionResolver: 'disk',
releaseGroupName: 'default',
});
expect(readJson(tree, 'libs/my-lib/package.json').version).toEqual('1.1.1');

Expand All @@ -82,6 +85,7 @@ describe('release-version', () => {
projectGraph,
specifier: '1.2.3', // exact version
currentVersionResolver: 'disk',
releaseGroupName: 'default',
});
expect(readJson(tree, 'libs/my-lib/package.json').version).toEqual('1.2.3');
});
Expand All @@ -92,6 +96,7 @@ describe('release-version', () => {
projectGraph,
specifier: 'major',
currentVersionResolver: 'disk',
releaseGroupName: 'default',
});

expect(readJson(tree, 'libs/my-lib/package.json')).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -137,6 +142,7 @@ describe('release-version', () => {
projectGraph,
specifier: 'major',
currentVersionResolver: 'disk',
releaseGroupName: 'default',
})
).rejects.toThrowErrorMatchingInlineSnapshot(`
"The project "my-lib" does not have a package.json available at libs/my-lib/package.json.
Expand Down
Loading

0 comments on commit b91946c

Please sign in to comment.