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
8 changes: 7 additions & 1 deletion src/bin/release-please.ts
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ interface HandleError {
}

function extractManifestOptions(
argv: GitHubArgs & (PullRequestArgs | ReleaseArgs)
argv: GitHubArgs & (PullRequestArgs | ReleaseArgs) & Partial<VersioningArgs>
): ManifestOptions {
const manifestOptions: ManifestOptions = {};
if ('fork' in argv && argv.fork !== undefined) {
Expand Down Expand Up @@ -907,6 +907,12 @@ function extractManifestOptions(
if ('draftPullRequest' in argv && argv.draftPullRequest !== undefined) {
manifestOptions.draftPullRequest = argv.draftPullRequest;
}
if ('latestTagVersion' in argv && argv.latestTagVersion) {
manifestOptions.latestTagVersion = argv.latestTagVersion;
}
if ('latestTagSha' in argv && argv.latestTagSha) {
manifestOptions.lastReleaseSha = argv.latestTagSha;
}
return manifestOptions;
}

Expand Down
31 changes: 23 additions & 8 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ interface ReleaserConfigJson {
export interface ManifestOptions {
bootstrapSha?: string;
lastReleaseSha?: string;
latestTagVersion?: string;
alwaysLinkLocal?: boolean;
separatePullRequests?: boolean;
plugins?: PluginType[];
Expand Down Expand Up @@ -437,6 +438,15 @@ export class Manifest {
parseConfig(github, configFile, targetBranch, path, releaseAs),
parseReleasedVersions(github, manifestFile, targetBranch),
]);

// Override releasedVersions if latestTagVersion is provided via CLI
if (manifestOptionOverrides?.latestTagVersion) {
const targetPath = path || ROOT_PROJECT_PATH;
releasedVersions[targetPath] = Version.parse(
manifestOptionOverrides.latestTagVersion
);
}

return new Manifest(
github,
targetBranch,
Expand Down Expand Up @@ -492,14 +502,19 @@ export class Manifest {
});
const component = await strategy.getBranchComponent();
const releasedVersions: ReleasedVersions = {};
const latestVersion = await latestReleaseVersion(
github,
targetBranch,
version => isPublishedVersion(strategy, version),
config,
component,
manifestOptions?.logger
);
let latestVersion: Version | undefined;
if (manifestOptions?.latestTagVersion) {
latestVersion = Version.parse(manifestOptions.latestTagVersion);
} else {
latestVersion = await latestReleaseVersion(
github,
targetBranch,
version => isPublishedVersion(strategy, version),
config,
component,
manifestOptions?.logger
);
}
if (latestVersion) {
releasedVersions[path] = latestVersion;
}
Expand Down
71 changes: 71 additions & 0 deletions test/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,61 @@
expect(manifest.repositoryConfig['node-packages'].draftPullRequest).to.be
.false;
});
it('should override releasedVersions with latestTagVersion', async () => {
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
);
getFileContentsStub
.withArgs('release-please-config.json', 'main')
.resolves(
buildGitHubFileContent(fixturesPath, 'manifest/config/simple.json')
)
.withArgs('.release-please-manifest.json', 'main')
.resolves(

Check failure on line 932 in test/manifest.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎··········buildGitHubFileRaw('{".":"·0.0.0"}')⏎········` with `buildGitHubFileRaw('{".":"·0.0.0"}')`
buildGitHubFileRaw('{".":" 0.0.0"}')
);
const manifest = await Manifest.fromManifest(
github,
github.repository.defaultBranch,
undefined,
undefined,
{latestTagVersion: '1.2.3'}
);
expect(manifest.releasedVersions['.']).to.not.be.undefined;
expect(manifest.releasedVersions['.'].toString()).to.eql('1.2.3');
});
it('should override releasedVersions for specific path with latestTagVersion', async () => {
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
);
getFileContentsStub
.withArgs('release-please-config.json', 'main')
.resolves(
buildGitHubFileContent(fixturesPath, 'manifest/config/config.json')
)
.withArgs('.release-please-manifest.json', 'main')
.resolves(
buildGitHubFileContent(
fixturesPath,
'manifest/versions/versions.json'
)
);
const manifest = await Manifest.fromManifest(
github,
github.repository.defaultBranch,
undefined,
undefined,
{latestTagVersion: '5.0.0'},
'packages/gcf-utils'
);
expect(manifest.releasedVersions['packages/gcf-utils']).to.not.be
.undefined;
expect(

Check failure on line 972 in test/manifest.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎········manifest.releasedVersions['packages/gcf-utils'].toString()⏎······).to.eql('5.0.0'` with `manifest.releasedVersions['packages/gcf-utils'].toString()).to.eql(⏎········'5.0.0'⏎······`
manifest.releasedVersions['packages/gcf-utils'].toString()
).to.eql('5.0.0');
});
});

describe('fromConfig', () => {
Expand Down Expand Up @@ -1525,6 +1580,22 @@
scope.done();
sinon.assert.callCount(sleepStub, 5);
});
it('should use latestTagVersion from manifestOptions if provided', async () => {
// No mocks for commits/releases needed since latestTagVersion bypasses discovery
const manifest = await Manifest.fromConfig(
github,
'target-branch',
{
releaseType: 'simple',
},
{
latestTagVersion: '2.3.4',
}
);
expect(Object.keys(manifest.repositoryConfig)).lengthOf(1);
expect(Object.keys(manifest.releasedVersions)).lengthOf(1);
expect(manifest.releasedVersions['.'].toString()).to.equal('2.3.4');
});
});

describe('buildPullRequests', () => {
Expand Down
Loading