Skip to content

Commit

Permalink
fix: backfill latest release with version found in manifest (#1131)
Browse files Browse the repository at this point in the history
  • Loading branch information
chingor13 committed Dec 1, 2021
1 parent 28d7727 commit 94859a0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,22 @@ export class Manifest {
}

const strategy = strategiesByPath[path];
const latestRelease = releasesByPath[path];
let latestRelease = releasesByPath[path];
if (
!latestRelease &&
this.releasedVersions[path].toString() !== '0.0.0'
) {
const version = this.releasedVersions[path];
const component = await strategy.getComponent();
logger.info(
`No latest release found for path: ${path}, component: ${component}, but a previous version (${version.toString()}) was specified in the manifest.`
);
latestRelease = {
tag: new TagName(version, component),
sha: '',
notes: '',
};
}
const releasePullRequest = await strategy.buildReleasePullRequest(
pathCommits,
latestRelease,
Expand Down
42 changes: 42 additions & 0 deletions test/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,48 @@ describe('Manifest', () => {
expect(pullRequests[0].version?.toString()).to.eql('1.0.0');
});

it('should read latest version from manifest if no release tag found', async () => {
mockReleases(github, []);
mockCommits(github, [
{
sha: 'aaaaaa',
message: 'fix: some bugfix',
files: ['path/a/foo'],
},
{
sha: 'cccccc',
message: 'fix: some bugfix',
files: ['path/a/foo'],
},
]);
const config = {
packages: {
'path/a': {
'release-type': 'simple',
component: 'pkg1',
},
'path/b': {
'release-type': 'simple',
component: 'pkg2',
},
},
};
const versions = {
'path/a': '1.2.3',
'path/b': '2.3.4',
};
sandbox
.stub(github, 'getFileContentsOnBranch')
.withArgs('release-please-config.json', 'main')
.resolves(buildGitHubFileRaw(JSON.stringify(config)))
.withArgs('.release-please-manifest.json', 'main')
.resolves(buildGitHubFileRaw(JSON.stringify(versions)));
const manifest = await Manifest.fromManifest(github, 'main');
const pullRequests = await manifest.buildPullRequests();
expect(pullRequests).lengthOf(1);
expect(pullRequests[0].version?.toString()).to.eql('1.2.4');
});

describe('with plugins', () => {
beforeEach(() => {
mockReleases(github, [
Expand Down

0 comments on commit 94859a0

Please sign in to comment.