Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions __snapshots__/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down
1 change: 1 addition & 0 deletions src/strategies/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ export abstract class BaseStrategy implements Strategy {
version,
versionsMap,
dateFormat: dateFormat,
component: this.component,
}),
});
break;
Expand Down
22 changes: 16 additions & 6 deletions src/updaters/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ const VERSION_REGEX =
/(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(-(?<preRelease>[\w.]+))?(\+(?<build>[-\w.]+))?/;
const MAJOR_VERSION_REGEX = /\d+\b/;
const SINGLE_VERSION_REGEX = /\b\d+\b/;
const INLINE_UPDATE_REGEX =
/x-release-please-(?<scope>major|minor|patch|version-date|version|date)/;
const BLOCK_START_REGEX =
/x-release-please-start-(?<scope>major|minor|patch|version-date|version|date)/;
const INLINE_UPDATE_REGEX = (component?: string) =>
new RegExp(
`x-release-please(-${component})?-(?<scope>major|minor|patch|version-date|version|date)`
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I don't escape component here.
If that's required then we'll need a small custom helper (const escapeRegExp = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');) since RegExp.escape() is part of nodejs 24 and this project advertises "node": ">=18.0.0"

);
const BLOCK_START_REGEX = (component?: string) =>
new RegExp(
`x-release-please-start(-${component})?-(?<scope>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';
Expand All @@ -45,6 +49,7 @@ export interface GenericUpdateOptions extends UpdateOptions {
blockEndRegex?: RegExp;
date?: Date;
dateFormat?: string;
component?: string;
}

/**
Expand Down Expand Up @@ -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-<major|minor|patch|version-date>` 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;
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions test/updaters/fixtures/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
1 change: 1 addition & 0 deletions test/updaters/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading