Skip to content

Commit

Permalink
feat: when changes-branch is provided use it to fetch manifest and co…
Browse files Browse the repository at this point in the history
…nfig file
  • Loading branch information
dgellow committed Sep 8, 2023
1 parent 5129dda commit e36644b
Show file tree
Hide file tree
Showing 41 changed files with 89 additions and 61 deletions.
2 changes: 1 addition & 1 deletion __snapshots__/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports['Strategy buildReleasePullRequest should pass changelogHost to default b
---
## 1.0.0 (1983-10-10)
## 0.0.1 (1983-10-10)
### Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions __snapshots__/dotnet-yoshi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ exports['DotnetYoshi buildReleasePullRequest returns release PR changes with def
---
## Version 1.0.0, released 1983-10-10
## Version 0.0.1, released 1983-10-10
### Bug fixes
Expand Down Expand Up @@ -39,7 +39,7 @@ _More technical details can be found at [stainless-api/release-please](https://g
`

exports['DotnetYoshi buildUpdates builds common files 1'] = `
## Version 1.0.0, released 1983-10-10
## Version 0.0.1, released 1983-10-10
### Bug fixes
Expand Down
6 changes: 3 additions & 3 deletions __snapshots__/go-yoshi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ exports['GoYoshi buildReleasePullRequest combines google-api-go-client autogener
---
## 0.1.0 (1983-10-10)
## 0.0.1 (1983-10-10)
### Features
Expand All @@ -22,7 +22,7 @@ exports['GoYoshi buildReleasePullRequest filters out submodule commits 1'] = `
---
## 0.1.0 (1983-10-10)
## 0.0.1 (1983-10-10)
### Bug Fixes
Expand All @@ -41,7 +41,7 @@ exports['GoYoshi buildReleasePullRequest filters out touched files not matching
---
## 0.1.0 (1983-10-10)
## 0.0.1 (1983-10-10)
### Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions __snapshots__/java-yoshi-mono-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exports['JavaYoshiMonoRepo buildUpdates omits non-breaking chores from changelog
"breakingChangeNote": "update a very important dep"
}
],
"version": "0.1.0",
"version": "0.0.1",
"language": "JAVA",
"artifactName": "cloud.google.com:foo",
"id": "abc-123-efd-qwerty",
Expand All @@ -46,7 +46,7 @@ exports['JavaYoshiMonoRepo buildUpdates updates changelog.json 1'] = `
"scope": "deps"
}
],
"version": "0.1.0",
"version": "0.0.1",
"language": "JAVA",
"artifactName": "cloud.google.com:foo",
"id": "abc-123-efd-qwerty",
Expand Down
2 changes: 1 addition & 1 deletion __snapshots__/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports['Node buildReleasePullRequest updates changelog.json if present 1'] = `
"scope": "deps"
}
],
"version": "1.0.0",
"version": "0.0.1",
"language": "JAVASCRIPT",
"artifactName": "node-test-repo",
"id": "abc-123-efd-qwerty",
Expand Down
2 changes: 1 addition & 1 deletion __snapshots__/php-yoshi.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ exports['PHPYoshi buildReleasePullRequest returns release PR changes with defaul
---
## 1.0.0
## 0.0.1
<details><summary>google/client1 1.2.4</summary>
Expand Down
2 changes: 1 addition & 1 deletion __snapshots__/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports['Python buildUpdates updates changelog.json if present 1'] = `
"scope": "deps"
}
],
"version": "0.1.0",
"version": "0.0.1",
"language": "PYTHON",
"artifactName": "google-cloud-automl",
"id": "abc-123-efd-qwerty",
Expand Down
3 changes: 2 additions & 1 deletion src/changelog-notes/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ export class DefaultChangelogNotes implements ChangelogNotes {
};
});

return conventionalChangelogWriter
const result = conventionalChangelogWriter
.parseArray(changelogCommits, context, preset.writerOpts)
.trim();
return result;
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,13 @@ export class Manifest {
path?: string,
releaseAs?: string
): Promise<Manifest> {
const changesBranch = manifestOptionOverrides.changesBranch ?? targetBranch;
const [
{config: repositoryConfig, options: manifestOptions},
releasedVersions,
] = await Promise.all([
parseConfig(github, configFile, targetBranch, path, releaseAs),
parseReleasedVersions(github, manifestFile, targetBranch),
parseConfig(github, configFile, changesBranch, path, releaseAs),
parseReleasedVersions(github, manifestFile, changesBranch),
]);
return new Manifest(
github,
Expand Down Expand Up @@ -743,8 +744,6 @@ export class Manifest {
openPullRequests.find(pr => pr.headBranchName === branchName) ||
snoozedPullRequests.find(pr => pr.headBranchName === branchName);

this.logger.debug({existingPR});

const releasePullRequest = await strategy.buildReleasePullRequest({
commits: pathCommits,
latestRelease,
Expand Down
3 changes: 2 additions & 1 deletion src/strategies/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ If you instead want to use the version number \`${newVersion}\` generated from c
latestRelease,
commits
);

if (this.changelogEmpty(releaseNotesBody)) {
this.logger.info(
`No user facing commits found since ${
Expand Down Expand Up @@ -751,7 +752,7 @@ If you instead want to use the version number \`${newVersion}\` generated from c
return Version.parse(this.initialVersion);
}

return Version.parse('1.0.0');
return Version.parse('0.0.1');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/strategies/go-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class GoYoshi extends BaseStrategy {
}

protected initialReleaseVersion(): Version {
return Version.parse('0.1.0');
return Version.parse('0.0.1');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/strategies/java-yoshi-mono-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export class JavaYoshiMonoRepo extends Java {
}

protected initialReleaseVersion(): Version {
return Version.parse('0.1.0');
return Version.parse('0.0.1');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/strategies/java-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class JavaYoshi extends Java {
}

protected initialReleaseVersion(): Version {
return Version.parse('0.1.0');
return Version.parse('0.0.1');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/strategies/krm-blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ export class KRMBlueprint extends BaseStrategy {
}

protected initialReleaseVersion(): Version {
return Version.parse('0.1.0');
return Version.parse('0.0.1');
}
}
2 changes: 1 addition & 1 deletion src/strategies/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,6 @@ export class Python extends BaseStrategy {
}

protected initialReleaseVersion(): Version {
return Version.parse('0.1.0');
return Version.parse('0.0.1');
}
}
2 changes: 1 addition & 1 deletion src/strategies/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class Rust extends BaseStrategy {
}

protected initialReleaseVersion(): Version {
return Version.parse('0.1.0');
return Version.parse('0.0.1');
}

async getDefaultPackageName(): Promise<string | undefined> {
Expand Down
2 changes: 1 addition & 1 deletion src/strategies/terraform-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@ export class TerraformModule extends BaseStrategy {
}

protected initialReleaseVersion(): Version {
return Version.parse('0.1.0');
return Version.parse('0.0.1');
}
}
47 changes: 37 additions & 10 deletions test/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,33 @@ describe('Manifest', () => {
expect(Object.keys(manifest.repositoryConfig)).lengthOf(8);
expect(Object.keys(manifest.releasedVersions)).lengthOf(8);
});
it('should fetch config and manifest from changes-branch when specified', async () => {
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
);
getFileContentsStub
.withArgs('release-please-config.json', 'next')
.resolves(
buildGitHubFileContent(fixturesPath, 'manifest/config/config.json')
)
.withArgs('.release-please-manifest.json', 'next')
.resolves(
buildGitHubFileContent(
fixturesPath,
'manifest/versions/versions.json'
)
);
const manifest = await Manifest.fromManifest(
github,
github.repository.defaultBranch,
undefined,
undefined,
{changesBranch: 'next'}
);
expect(Object.keys(manifest.repositoryConfig)).lengthOf(8);
expect(Object.keys(manifest.releasedVersions)).lengthOf(8);
});
it('should limit manifest loading to the given path', async () => {
const getFileContentsStub = sandbox.stub(
github,
Expand Down Expand Up @@ -2235,9 +2262,9 @@ describe('Manifest', () => {

const getFileContentsOnBranchStub = sandbox
.stub(github, 'getFileContentsOnBranch')
.withArgs('release-please-config.json', 'main')
.withArgs('release-please-config.json', 'next')
.resolves(buildGitHubFileRaw(JSON.stringify(config)))
.withArgs('.release-please-manifest.json', 'main')
.withArgs('.release-please-manifest.json', 'next')
.resolves(
buildGitHubFileRaw(
JSON.stringify({
Expand Down Expand Up @@ -2473,9 +2500,9 @@ version = "3.0.0"

const getFileContentsOnBranchStub = sandbox
.stub(github, 'getFileContentsOnBranch')
.withArgs('release-please-config.json', 'main')
.withArgs('release-please-config.json', 'next')
.resolves(buildGitHubFileRaw(JSON.stringify(config)))
.withArgs('.release-please-manifest.json', 'main')
.withArgs('.release-please-manifest.json', 'next')
.resolves(
buildGitHubFileRaw(
JSON.stringify({
Expand Down Expand Up @@ -2594,9 +2621,9 @@ version = "3.0.0"

const getFileContentsOnBranchStub = sandbox
.stub(github, 'getFileContentsOnBranch')
.withArgs('release-please-config.json', 'main')
.withArgs('release-please-config.json', 'next')
.resolves(buildGitHubFileRaw(JSON.stringify(config)))
.withArgs('.release-please-manifest.json', 'main')
.withArgs('.release-please-manifest.json', 'next')
.resolves(
buildGitHubFileRaw(
JSON.stringify({
Expand Down Expand Up @@ -2725,9 +2752,9 @@ version = "3.0.0"

const getFileContentsOnBranchStub = sandbox
.stub(github, 'getFileContentsOnBranch')
.withArgs('release-please-config.json', 'main')
.withArgs('release-please-config.json', 'next')
.resolves(buildGitHubFileRaw(JSON.stringify(config)))
.withArgs('.release-please-manifest.json', 'main')
.withArgs('.release-please-manifest.json', 'next')
.resolves(
buildGitHubFileRaw(
JSON.stringify({
Expand Down Expand Up @@ -2828,7 +2855,7 @@ version = "3.0.0"
const manifest = await Manifest.fromManifest(github, 'main');
const pullRequests = await manifest.buildPullRequests([], []);
expect(pullRequests).lengthOf(1);
expect(pullRequests[0].version?.toString()).to.eql('1.0.0');
expect(pullRequests[0].version?.toString()).to.eql('0.0.1');
});

it('should allow specifying a last release sha', async () => {
Expand Down Expand Up @@ -2921,7 +2948,7 @@ version = "3.0.0"
const manifest = await Manifest.fromManifest(github, 'main');
const pullRequests = await manifest.buildPullRequests([], []);
expect(pullRequests).lengthOf(1);
expect(pullRequests[0].version?.toString()).to.eql('1.0.0');
expect(pullRequests[0].version?.toString()).to.eql('0.0.1');
});

it('should allow customizing pull request title with root package', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/strategies/dart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Dart', () => {
),
];
it('returns release PR changes with defaultInitialVersion', async () => {
const expectedVersion = '1.0.0';
const expectedVersion = '0.0.1';
const strategy = new Dart({
targetBranch: 'main',
github,
Expand Down
4 changes: 2 additions & 2 deletions test/strategies/dotnet-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ describe('DotnetYoshi', () => {
.resolves(buildGitHubFileContent(fixturesPath, 'apis.json'));
});
it('returns release PR changes with defaultInitialVersion', async () => {
const expectedVersion = '1.0.0';
const expectedVersion = '0.0.1';
const expectedTitle =
'Release Google.Cloud.SecurityCenter.V1 version 1.0.0';
'Release Google.Cloud.SecurityCenter.V1 version 0.0.1';
const strategy = new DotnetYoshi({
targetBranch: 'main',
github,
Expand Down
2 changes: 1 addition & 1 deletion test/strategies/elixir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('Elixir', () => {
});
describe('buildReleasePullRequest', () => {
it('returns release PR changes with defaultInitialVersion', async () => {
const expectedVersion = '1.0.0';
const expectedVersion = '0.0.1';
const strategy = new Elixir({
targetBranch: 'main',
github,
Expand Down
2 changes: 1 addition & 1 deletion test/strategies/expo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Expo', () => {

describe('buildReleasePullRequest', () => {
it('returns release PR changes with defaultInitialVersion', async () => {
const expectedVersion = '1.0.0';
const expectedVersion = '0.0.1';

const getFileContentsStub = sandbox.stub(
github,
Expand Down
2 changes: 1 addition & 1 deletion test/strategies/go-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('GoYoshi', () => {
});
describe('buildReleasePullRequest', () => {
it('returns release PR changes with defaultInitialVersion', async () => {
const expectedVersion = '0.1.0';
const expectedVersion = '0.0.1';
const strategy = new GoYoshi({
targetBranch: 'main',
github,
Expand Down
2 changes: 1 addition & 1 deletion test/strategies/go.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Go', () => {
});
describe('buildReleasePullRequest', () => {
it('returns release PR changes with defaultInitialVersion', async () => {
const expectedVersion = '1.0.0';
const expectedVersion = '0.0.1';
const strategy = new Go({
targetBranch: 'main',
github,
Expand Down
2 changes: 1 addition & 1 deletion test/strategies/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Helm', () => {
});
describe('buildReleasePullRequest', () => {
it('returns release PR changes with defaultInitialVersion', async () => {
const expectedVersion = '1.0.0';
const expectedVersion = '0.0.1';
const strategy = new Helm({
targetBranch: 'main',
github,
Expand Down
2 changes: 1 addition & 1 deletion test/strategies/java-yoshi-mono-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('JavaYoshiMonoRepo', () => {
});
describe('buildReleasePullRequest', () => {
it('returns release PR changes with defaultInitialVersion', async () => {
const expectedVersion = '0.1.0';
const expectedVersion = '0.0.1';
const strategy = new JavaYoshiMonoRepo({
targetBranch: 'main',
github,
Expand Down
2 changes: 1 addition & 1 deletion test/strategies/java-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('JavaYoshi', () => {
});
describe('buildReleasePullRequest', () => {
it('returns release PR changes with defaultInitialVersion', async () => {
const expectedVersion = '0.1.0';
const expectedVersion = '0.0.1';
const strategy = new JavaYoshi({
targetBranch: 'main',
github,
Expand Down
Loading

0 comments on commit e36644b

Please sign in to comment.