Skip to content

Commit

Permalink
fix: allow setting release-type at root of manifest config (#1159)
Browse files Browse the repository at this point in the history
* test: add failing test for setting release-type at root config level

* fix: set default release type at end of resolution
  • Loading branch information
chingor13 committed Dec 22, 2021
1 parent c8e3faa commit fc73b6d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,9 +840,11 @@ export class Manifest {
* @param {ReleaserPackageConfig} config Parsed configuration from JSON file.
* @returns {ReleaserConfig}
*/
function extractReleaserConfig(config: ReleaserPackageConfig): ReleaserConfig {
function extractReleaserConfig(
config: ReleaserPackageConfig
): Partial<ReleaserConfig> {
return {
releaseType: config['release-type'] || 'node', // for backwards-compatibility
releaseType: config['release-type'],
bumpMinorPreMajor: config['bump-minor-pre-major'],
bumpPatchForMinorPreMajor: config['bump-patch-for-minor-pre-major'],
changelogSections: config['changelog-sections'],
Expand Down Expand Up @@ -1014,11 +1016,11 @@ async function latestReleaseVersion(
}

function mergeReleaserConfig(
defaultConfig: ReleaserConfig,
pathConfig: ReleaserConfig
) {
defaultConfig: Partial<ReleaserConfig>,
pathConfig: Partial<ReleaserConfig>
): ReleaserConfig {
return {
releaseType: pathConfig.releaseType ?? defaultConfig.releaseType,
releaseType: pathConfig.releaseType ?? defaultConfig.releaseType ?? 'node',
bumpMinorPreMajor:
pathConfig.bumpMinorPreMajor ?? defaultConfig.bumpMinorPreMajor,
bumpPatchForMinorPreMajor:
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/manifest/config/root-release-type.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"release-type": "java-yoshi",
"packages": {
".": {
"package-name": "foo"
},
"node-package": {
"release-type": "node"
}
}
}
31 changes: 30 additions & 1 deletion test/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('Manifest', () => {
});

describe('fromManifest', () => {
it('it should parse config and manifest from repostiory', async () => {
it('should parse config and manifest from repostiory', async () => {
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
Expand All @@ -151,6 +151,35 @@ describe('Manifest', () => {
expect(Object.keys(manifest.repositoryConfig)).lengthOf(8);
expect(Object.keys(manifest.releasedVersions)).lengthOf(8);
});
it('should read the default release-type from manifest', async () => {
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
);
getFileContentsStub
.withArgs('release-please-config.json', 'main')
.resolves(
buildGitHubFileContent(
fixturesPath,
'manifest/config/root-release-type.json'
)
)
.withArgs('.release-please-manifest.json', 'main')
.resolves(
buildGitHubFileContent(
fixturesPath,
'manifest/versions/versions.json'
)
);
const manifest = await Manifest.fromManifest(
github,
github.repository.defaultBranch
);
expect(manifest.repositoryConfig['.'].releaseType).to.eql('java-yoshi');
expect(manifest.repositoryConfig['node-package'].releaseType).to.eql(
'node'
);
});
});

describe('fromConfig', () => {
Expand Down

0 comments on commit fc73b6d

Please sign in to comment.