mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2026-04-09 09:34:18 +00:00
feat!: tag released
This commit is contained in:
parent
f9d3daa396
commit
0735972145
33 changed files with 216 additions and 42 deletions
|
|
@ -28,4 +28,6 @@ export class ActionConfig {
|
|||
public userFormatType: string = "csv";
|
||||
/** Prevents pre-v1.0.0 version from automatically incrementing the major version. If enabled, when the major version is 0, major releases will be treated as minor and minor as patch. Note that the versionType output is unchanged. */
|
||||
public enablePrereleaseMode: boolean = false;
|
||||
}
|
||||
/** Prerelease name. If set, the version will be suffixed with the prerelease name and increment. */
|
||||
public prereleaseName: string = "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,4 +25,4 @@ export const cmd = async (command: string, ...args: any): Promise<string> => {
|
|||
}
|
||||
|
||||
return output;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export class VersionResult {
|
|||
* @param changed - True if the version was changed, otherwise false
|
||||
* @param isTagged - True if the commit had a tag that matched the `versionTag` format
|
||||
* @param authors - Authors formatted according to the format mode (e.g. JSON, CSV, YAML, etc.)
|
||||
* @param currentCommit - The current commit hash
|
||||
* @param currentCommit - The current commit hash
|
||||
* @param previousCommit - The previous commit hash
|
||||
* @param previousVersion - The previous version
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -8,11 +8,13 @@ export class DefaultTagFormatter implements TagFormatter {
|
|||
private tagPrefix: string;
|
||||
private namespace: string;
|
||||
private namespaceSeperator: string;
|
||||
private prereleaseName: string;
|
||||
|
||||
constructor(config: ActionConfig) {
|
||||
this.namespace = config.namespace;
|
||||
this.tagPrefix = config.tagPrefix;
|
||||
this.namespaceSeperator = '-'; // maybe make configurable in the future
|
||||
this.prereleaseName = config.prereleaseName;
|
||||
}
|
||||
|
||||
public Format(versionInfo: VersionInformation): string {
|
||||
|
|
@ -31,6 +33,10 @@ export class DefaultTagFormatter implements TagFormatter {
|
|||
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]${this.namespaceSeperator}${this.namespace}`;
|
||||
}
|
||||
|
||||
if (!!this.prereleaseName) {
|
||||
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]-${this.prereleaseName}.*[0-9]`;
|
||||
}
|
||||
|
||||
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]`;
|
||||
}
|
||||
|
||||
|
|
@ -71,6 +77,10 @@ export class DefaultTagFormatter implements TagFormatter {
|
|||
return new RegExp(`^${tagPrefix}[0-9]+\.[0-9]+\.[0-9]+${namespaceSeperator}${namespace}$`).test(tag);
|
||||
}
|
||||
|
||||
if (!!this.prereleaseName) {
|
||||
return new RegExp(`^${this.tagPrefix}[0-9]+\.[0-9]+\.[0-9]+-${this.prereleaseName}\.[0-9]+$`).test(tag);
|
||||
}
|
||||
|
||||
return new RegExp(`^${tagPrefix}[0-9]+\.[0-9]+\.[0-9]+$`).test(tag);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,33 @@ const execute = (workingDirectory: string, command: string, env?: any) => {
|
|||
}
|
||||
};
|
||||
|
||||
test('Prerelease is detected and tagged correctly', async () => {
|
||||
const repo = createTestRepo({ tagPrefix: 'v', versionFormat: "${major}.${minor}.${patch}-rc.${increment}", prereleaseName: "rc" });
|
||||
|
||||
repo.makeCommit('Initial Commit');
|
||||
repo.exec('git tag v1.0.0-rc.0');
|
||||
var result = await repo.runAction();
|
||||
expect(result.formattedVersion).toBe('1.0.0-rc.0');
|
||||
expect(result.isTagged).toBe(true);
|
||||
|
||||
repo.makeCommit('Second Commit');
|
||||
result = await repo.runAction();
|
||||
expect(result.formattedVersion).toBe('1.0.1-rc.0')
|
||||
expect(result.isTagged).toBe(false);
|
||||
|
||||
repo.makeCommit('Third Commit (MINOR)');
|
||||
result = await repo.runAction();
|
||||
expect(result.formattedVersion).toBe('1.1.0-rc.0');
|
||||
expect(result.isTagged).toBe(false);
|
||||
|
||||
repo.makeCommit('Fourth Commit (MINOR)');
|
||||
repo.exec('git tag v1.1.0-rc.0')
|
||||
result = await repo.runAction();
|
||||
console.log(result.formattedVersion)
|
||||
expect(result.formattedVersion).toBe('1.1.0-rc.1');
|
||||
expect(result.isTagged).toBe(true);
|
||||
}, timeout);
|
||||
|
||||
test('Empty repository version is correct', async () => {
|
||||
const repo = createTestRepo(); // 0.0.0+0
|
||||
var result = await repo.runAction();
|
||||
|
|
@ -814,11 +841,11 @@ test('Prerelease tags are ignored on current commit', async () => {
|
|||
repo.makeCommit(`Commit ${i++}`);
|
||||
await validate('0.1.0+1');
|
||||
repo.exec('git tag v1.0.0-rc2');
|
||||
await validate('0.1.0+1');
|
||||
await validate('0.1.0+1');
|
||||
repo.makeCommit(`Commit ${i++}`);
|
||||
await validate('0.1.0+2');
|
||||
await validate('0.1.0+2');
|
||||
repo.exec('git tag v1.0.0-rc3');
|
||||
await validate('0.1.0+2');
|
||||
await validate('0.1.0+2');
|
||||
repo.makeCommit(`Commit ${i++}`);
|
||||
await validate('0.1.0+3');
|
||||
repo.exec('git tag v1.0.0');
|
||||
|
|
@ -897,4 +924,4 @@ test('Tagged commit is flagged as release', async () => {
|
|||
result = await repo.runAction();
|
||||
expect(result.formattedVersion).toBe('1.1.0-prerelease.1');
|
||||
expect(result.isTagged).toBe(true);
|
||||
}, timeout);
|
||||
}, timeout);
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ export async function run() {
|
|||
searchCommitBody: core.getInput('search_commit_body') === 'true',
|
||||
userFormatType: core.getInput('user_format_type'),
|
||||
enablePrereleaseMode: core.getInput('enable_prerelease_mode') === 'true',
|
||||
prereleaseName: core.getInput('prerelease_name'),
|
||||
};
|
||||
|
||||
if (config.versionFormat === '' && core.getInput('format') !== '') {
|
||||
|
|
@ -66,4 +67,4 @@ export async function run() {
|
|||
setOutput(result);
|
||||
}
|
||||
|
||||
run();
|
||||
run();
|
||||
|
|
|
|||
|
|
@ -44,4 +44,4 @@ export class BumpAlwaysVersionClassifier extends DefaultVersionClassifier {
|
|||
|
||||
return new VersionClassification(type, 0, true, major, minor, patch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,4 +6,4 @@ export class CommitInfoSet {
|
|||
public changed: boolean,
|
||||
public commits: CommitInfo[]
|
||||
){}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,4 +91,4 @@ export class DefaultCommitsProvider implements CommitsProvider {
|
|||
return new CommitInfoSet(changed, commits);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,4 +22,4 @@ export class DefaultCurrentCommitResolver implements CurrentCommitResolver {
|
|||
let lastCommitAll = (await cmd('git', 'rev-list', '-n1', '--all')).trim();
|
||||
return lastCommitAll === '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export class DefaultLastReleaseResolver implements LastReleaseResolver {
|
|||
let currentTag = (await cmd(
|
||||
`git tag --points-at ${current} ${releasePattern}`
|
||||
)).trim();
|
||||
|
||||
|
||||
currentTag = tagFormatter.IsValid(currentTag) ? currentTag : '';
|
||||
const isTagged = currentTag !== '';
|
||||
|
||||
|
|
@ -73,4 +73,4 @@ export class DefaultLastReleaseResolver implements LastReleaseResolver {
|
|||
return new ReleaseInformation(major, minor, patch, root.trim(), currentMajor, currentMinor, currentPatch, isTagged);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,4 +21,4 @@ test('Regular expressions can be used as minor tag direct', async () => {
|
|||
expect(result.minor).toBe(1);
|
||||
expect(result.patch).toBe(0);
|
||||
expect(result.increment).toBe(0);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -112,4 +112,4 @@ export class DefaultVersionClassifier implements VersionClassifier {
|
|||
|
||||
return new VersionClassification(type, increment, changed, major, minor, patch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
/** Represents information about a user (e.g. committer, author, tagger) */
|
||||
export class UserInfo {
|
||||
/**
|
||||
* Creates a new instance
|
||||
* Creates a new instance
|
||||
* @param name - User's name
|
||||
* @param email - User's email
|
||||
* @param commits - Number of commits in the scope evaluated
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue