Skip to content

Commit

Permalink
feat: Support passing parserOpts and writerOpts
Browse files Browse the repository at this point in the history
  • Loading branch information
TheUnderScorer committed Mar 18, 2022
1 parent f176d1c commit 00bc505
Show file tree
Hide file tree
Showing 19 changed files with 265 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ After running this, the executor will do the following:
| plugins | PluginSpec[] | | no | Additional plugins for semantic-release. Note: these plugins will be added before @semantic-release/git, which means that you can assets generated by them to git as well. Supports the same format as [semantic-release](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#plugins) |
| branches | BranchSpec[] | | no | Branches configuration for workflow release. Supports the same format as [semantic-release](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#branches) |
| packageJsonDir | string | ${PROJECT_DIR} | no | Path to package.json file (usable only if npm is true). Note: it should point to directory in which package.json can be found, not to file itself. |
| parserOpts | object | | no | Parser options used by commit-analyzer and @semantic-release/release-notes-generator and @semantic-release/changelog |
| writerOpts | object | | no | Writer options used by commit-analyzer and @semantic-release/release-notes-generator |

#### Build target

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,19 @@ export const resolvePlugins = (

const emptyArray = [] as unknown as release.PluginSpec;
const defaultPlugins: release.PluginSpec[] = [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
[
'@semantic-release/commit-analyzer',
{
parserOpts: options.parserOpts,
}
],
[
'@semantic-release/release-notes-generator',
{
parserOpts: options.parserOpts,
writerOpts: options.writerOpts,
}
],

...(options.changelog
? [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"type": "string",
"default": ""
},
"parserOpts": {
"description": "Parser options used by commit-analyzer and @semantic-release/release-notes-generator and @semantic-release/changelog",
"type": "object"
},
"writerOpts": {
"description": "Writer options used by commit-analyzer and @semantic-release/release-notes-generator",
"type": "object"
},
"tagFormat": {
"description": "Tag format to use.",
"type": "string"
Expand Down Expand Up @@ -81,8 +89,12 @@
"type": "array",
"items": {
"oneOf": [
{"type": "string"},
{"type": "object"}
{
"type": "string"
},
{
"type": "object"
}
]
}
}
Expand All @@ -94,27 +106,53 @@
"type": "array",
"items": {
"oneOf": [
{ "type": "string", "maxLength": 100, "minLength": 1 },
{
"type": "string",
"maxLength": 100,
"minLength": 1
},
{
"type": "object",
"properties": {
"name": { "type": "string", "maxLength": 100, "minLength": 1 },
"name": {
"type": "string",
"maxLength": 100,
"minLength": 1
},
"channel": {
"oneOf": [
{ "type": "string", "maxLength": 100, "minLength": 1 },
{ "const": false }
{
"type": "string",
"maxLength": 100,
"minLength": 1
},
{
"const": false
}
]
},
"range": { "type": "string", "maxLength": 100, "minLength": 1 },
"range": {
"type": "string",
"maxLength": 100,
"minLength": 1
},
"prerelease": {
"oneOf": [
{ "type": "string", "maxLength": 100, "minLength": 1 },
{ "type": "boolean" }
{
"type": "string",
"maxLength": 100,
"minLength": 1
},
{
"type": "boolean"
}
]
}
},
"additionalProperties": false,
"required": ["name"]
"required": [
"name"
]
}
]
},
Expand All @@ -123,8 +161,14 @@
"master",
"main",
"next",
{ "name": "beta", "prerelease": true },
{ "name": "alpha", "prerelease": true }
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
}
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,32 @@ describe('Semantic release', () => {
await checkAppB();
await checkCommonLib();
});

// TODO Add config file (nx-semantic-release.json)
it('should support passing writerOpts and parserOpts', async () => {
await exec('npx nx run app-c:semantic-release', {
verbose: true,
env: removeCiEnv(),
});

const changelog = readTestAppChangelog('app-c');

expect(changelog).not.toContain('### Features');
expect(changelog).toContain(`### BREAKING CHANGES
* Test`);

assertReleaseNotes({
notes: changelog,
shouldContain: ['add app-c', 'add rest'],
shouldNotContain: [
'add app-a',
'add app-b',
'update test.txt',
'update test.txt again',
'add description',
],
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type SemanticReleaseOptions = Omit<release.Options, 'extends'> & {
commitMessage: string;
gitAssets?: string[];
packageJsonDir?: string;
parserOpts?: Record<string, unknown>;
writerOpts?: Record<string, unknown>
};

export async function semanticRelease(
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-semantic-release/src/tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export const remoteReposDirectory = path.join(remoteServerDirectory, 'repos');

export const remoteGitPath = path.join(remoteReposDirectory, 'project.git');

export const testProjects = ['app-a', 'app-b', 'common-lib'] as const;
export const testProjects = ['app-a', 'app-b', 'app-c', 'common-lib'] as const;
2 changes: 2 additions & 0 deletions packages/nx-semantic-release/src/tests/setup-test-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const setupCommands: Array<string | (() => Promise<void>)> = [
'git commit -m "feat: add app-a"',
'git add apps/app-b',
'git commit -m "feat: add app-b"',
'git add apps/app-c',
'git commit -m "feat: add app-c" -m "CHANGE: Test"',
'git add libs/lib-a libs/lib-a-dependency',
'git commit -m "feat: add app-a libs"',
'git add libs/common-lib',
Expand Down
18 changes: 18 additions & 0 deletions test-repos/app/apps/app-c/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
15 changes: 15 additions & 0 deletions test-repos/app/apps/app-c/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
displayName: 'app-c',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/app-c',
};
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const environment = {
production: true,
};
3 changes: 3 additions & 0 deletions test-repos/app/apps/app-c/src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const environment = {
production: false,
};
1 change: 1 addition & 0 deletions test-repos/app/apps/app-c/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello World!');
10 changes: 10 additions & 0 deletions test-repos/app/apps/app-c/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["node"]
},
"exclude": ["**/*.spec.ts", "**/*.test.ts"],
"include": ["**/*.ts"]
}
13 changes: 13 additions & 0 deletions test-repos/app/apps/app-c/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
9 changes: 9 additions & 0 deletions test-repos/app/apps/app-c/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
}
24 changes: 18 additions & 6 deletions test-repos/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions test-repos/app/workspace.dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,78 @@
},
"tags": []
},
"app-c": {
"root": "apps/app-c",
"sourceRoot": "apps/app-c/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/node:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/app-c",
"main": "apps/app-c/src/main.ts",
"tsConfig": "apps/app-c/tsconfig.app.json",
"assets": ["apps/app-c/src/assets"]
},
"configurations": {
"production": {
"optimization": true,
"extractLicenses": true,
"inspect": false,
"fileReplacements": [
{
"replace": "apps/app-c/src/environments/environment.ts",
"with": "apps/app-c/src/environments/environment.prod.ts"
}
]
}
}
},
"serve": {
"executor": "@nrwl/node:execute",
"options": {
"buildTarget": "app-c:build"
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/app-c/**/*.ts"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/apps/app-c"],
"options": {
"jestConfig": "apps/app-c/jest.config.js",
"passWithNoTests": true
}
},
"semantic-release": {
"executor": "@theunderscorer/nx-semantic-release:semantic-release",
"options": {
"dryRun": false,
"buildTarget": "app-c:build",
"repositoryUrl": "../../git-server/repos/project.git",
"github": false,
"ci": false,
"outputPath": "dist/apps/app-b",
"commitMessage": "chore(app-c): release ${nextRelease.version} [skip ci]\\n\\n${nextRelease.notes}",
"branches": ["*"],
"packageJsonDir": "${PROJECT_DIR}/stuff",
"parserOpts": {
"noteKeywords": ["CHANGE"]
},
"writerOpts": {
"groupBy": false
}
}
}
},
"tags": []
},
"common-lib": {
"root": "libs/common-lib",
"sourceRoot": "libs/common-lib/src",
Expand Down

0 comments on commit 00bc505

Please sign in to comment.