diff --git a/__snapshots__/generic.js b/__snapshots__/generic.js index 5f2687d3a..7d22ce9a0 100644 --- a/__snapshots__/generic.js +++ b/__snapshots__/generic.js @@ -51,6 +51,12 @@ public final class Version { public static String INLINE_MINOR = "3"; // {x-release-please-minor} public static String INLINE_PATCH = "4"; // {x-release-please-patch} + public static String INLINE_COMPONENT_VERSION = "2.3.4"; // {x-release-please-an-app-called-major-version} + public static String INLINE_COMPONENT_MAJOR = "2"; // {x-release-please-an-app-called-major-major} + public static String INLINE_COMPONENT_MAJOR_V = "v2"; // {x-release-please-an-app-called-major-major} + public static String INLINE_COMPONENT_MINOR = "3"; // {x-release-please-an-app-called-major-minor} + public static String INLINE_COMPONENT_PATCH = "4"; // {x-release-please-an-app-called-major-patch} + public static String RELEASE_DATE = "01-12-2023"; // {x-release-please-date} public static String RELEASE_INFO = "v2.3.4 01-12-2023"; // {x-release-please-version-date} } diff --git a/src/strategies/base.ts b/src/strategies/base.ts index 952c666cc..4a820ed41 100644 --- a/src/strategies/base.ts +++ b/src/strategies/base.ts @@ -424,6 +424,7 @@ export abstract class BaseStrategy implements Strategy { version, versionsMap, dateFormat: dateFormat, + component: this.component, }), }); break; diff --git a/src/updaters/generic.ts b/src/updaters/generic.ts index 83838e1a0..27ffab18e 100644 --- a/src/updaters/generic.ts +++ b/src/updaters/generic.ts @@ -20,10 +20,14 @@ const VERSION_REGEX = /(?\d+)\.(?\d+)\.(?\d+)(-(?[\w.]+))?(\+(?[-\w.]+))?/; const MAJOR_VERSION_REGEX = /\d+\b/; const SINGLE_VERSION_REGEX = /\b\d+\b/; -const INLINE_UPDATE_REGEX = - /x-release-please-(?major|minor|patch|version-date|version|date)/; -const BLOCK_START_REGEX = - /x-release-please-start-(?major|minor|patch|version-date|version|date)/; +const INLINE_UPDATE_REGEX = (component?: string) => + new RegExp( + `x-release-please(-${component})?-(?major|minor|patch|version-date|version|date)` + ); +const BLOCK_START_REGEX = (component?: string) => + new RegExp( + `x-release-please-start(-${component})?-(?major|minor|patch|version-date|version|date)` + ); const BLOCK_END_REGEX = /x-release-please-end/; const DATE_FORMAT_REGEX = /%[Ymd]/g; export const DEFAULT_DATE_FORMAT = '%Y-%m-%d'; @@ -45,6 +49,7 @@ export interface GenericUpdateOptions extends UpdateOptions { blockEndRegex?: RegExp; date?: Date; dateFormat?: string; + component?: string; } /** @@ -73,6 +78,9 @@ export interface GenericUpdateOptions extends UpdateOptions { * be considered for version replacement. You can also open these blocks * with `x-release-please-start-` to replace * single numbers + * + * In every case (except x-release-please-end), the component can be added + * to the directive, for example `x-release-please-myapp-version`. */ export class Generic extends DefaultUpdater { private readonly inlineUpdateRegex: RegExp; @@ -84,8 +92,10 @@ export class Generic extends DefaultUpdater { constructor(options: GenericUpdateOptions) { super(options); - this.inlineUpdateRegex = options.inlineUpdateRegex ?? INLINE_UPDATE_REGEX; - this.blockStartRegex = options.blockStartRegex ?? BLOCK_START_REGEX; + this.inlineUpdateRegex = + options.inlineUpdateRegex ?? INLINE_UPDATE_REGEX(options.component); + this.blockStartRegex = + options.blockStartRegex ?? BLOCK_START_REGEX(options.component); this.blockEndRegex = options.blockEndRegex ?? BLOCK_END_REGEX; this.date = options.date ?? new Date(); this.dateFormat = options.dateFormat ?? DEFAULT_DATE_FORMAT; diff --git a/test/updaters/fixtures/Version.java b/test/updaters/fixtures/Version.java index 04a4647cd..f92a2eb6e 100644 --- a/test/updaters/fixtures/Version.java +++ b/test/updaters/fixtures/Version.java @@ -50,6 +50,12 @@ public final class Version { public static String INLINE_MINOR = "2"; // {x-release-please-minor} public static String INLINE_PATCH = "3"; // {x-release-please-patch} + public static String INLINE_COMPONENT_VERSION = "1.2.3-SNAPSHOT"; // {x-release-please-an-app-called-major-version} + public static String INLINE_COMPONENT_MAJOR = "1"; // {x-release-please-an-app-called-major-major} + public static String INLINE_COMPONENT_MAJOR_V = "v1"; // {x-release-please-an-app-called-major-major} + public static String INLINE_COMPONENT_MINOR = "2"; // {x-release-please-an-app-called-major-minor} + public static String INLINE_COMPONENT_PATCH = "3"; // {x-release-please-an-app-called-major-patch} + public static String RELEASE_DATE = "11-12-2014"; // {x-release-please-date} public static String RELEASE_INFO = "v1.2.3 11-12-2014"; // {x-release-please-version-date} } diff --git a/test/updaters/generic.ts b/test/updaters/generic.ts index 489b7ee38..0e12385f9 100644 --- a/test/updaters/generic.ts +++ b/test/updaters/generic.ts @@ -35,6 +35,7 @@ describe('Generic', () => { version: Version.parse('v2.3.4'), date: currentDate, dateFormat: '%d-%m-%Y', + component: 'an-app-called-major', }); const newContent = pom.updateContent(oldContent); snapshot(newContent);