Coder Social home page Coder Social logo

Comments (11)

jreilly-lukava avatar jreilly-lukava commented on June 27, 2024

Took a stab at some stuff and got at least a decent start going. Not sure I have enough to make a full blown PR for you with tests and all. It would probably make more since in config file so it could be usable by all the projects in my monorepo without having to repeat myself. Here's what I've got.

plugins.ts

diff --git a/packages/nx-semantic-release/src/executors/semantic-release/plugins.ts b/packages/nx-semantic-release/src/executors/semantic-release/plugins.ts
index 446b35f9d386c2f970c5bbea725161a55ccded42..d8c63c20bb68096ef4e4da65af8885f1200d542b 100644
--- a/packages/nx-semantic-release/src/executors/semantic-release/plugins.ts
+++ b/packages/nx-semantic-release/src/executors/semantic-release/plugins.ts
@@ -52,9 +52,18 @@ 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,
+      },
+    ],
     ...(options.changelog
       ? [
           [

scheme.json

diff --git a/packages/nx-semantic-release/src/executors/semantic-release/schema.json b/packages/nx-semantic-release/src/executors/semantic-release/schema.json
index c999e2b543e2a7c3e9aa7419f9bec1418bd99ece..cce599ef3e60badc47ff0354313fa2e2e60001a3 100644
--- a/packages/nx-semantic-release/src/executors/semantic-release/schema.json
+++ b/packages/nx-semantic-release/src/executors/semantic-release/schema.json
@@ -62,6 +62,10 @@
       "type": "string",
       "default": "chore(release): ${nextRelease.version} [skip ci]\\n\\n${nextRelease.notes}"
     },
+    "parserOpts": {
+      "description": "Parser options used by commit-analyzer and @semantic-release/release-notes-generator and @semantic-release/changelog",
+      "type": "object"
+    },
     "gitAssets": {
       "description": "Path to assets to include in git commit.",
       "type": "array",

semantic-release.ts

diff --git a/packages/nx-semantic-release/src/executors/semantic-release/semantic-release.ts b/packages/nx-semantic-release/src/executors/semantic-release/semantic-release.ts
index 486f7b5910e2edebf0663bc3602a105f5392a3c5..f01d26f65c337eafa6313b87e0a047456c606b19 100644
--- a/packages/nx-semantic-release/src/executors/semantic-release/semantic-release.ts
+++ b/packages/nx-semantic-release/src/executors/semantic-release/semantic-release.ts
@@ -16,6 +16,9 @@ export type SemanticReleaseOptions = Omit<release.Options, 'extends'> & {
   commitMessage: string;
   gitAssets?: string[];
   packageJsonDir?: string;
+  parserOpts?: {
+    [key: string]: string;
+  };
 };
 
 export async function semanticRelease(

from nx-semantic-release.

TheUnderScorer avatar TheUnderScorer commented on June 27, 2024

Hey jreilly-lukava,

thanks for the suggestion! Seems like having option to customize the parserOpts would be a good idea regardless.
I will try to look through your changes during a weekend and come up with a PR.

Thanks!

from nx-semantic-release.

jreilly-lukava avatar jreilly-lukava commented on June 27, 2024

I'm new to semantic-release so I've been beating my head against the wall for a long time on and off trying to implement something that worked for me. While the above would be useful for per project customization I found that I could add customization to a .releaserc.js or such that could contain global customization applied to every project, which works great for me. So I ended up with something like this.

.releaserc.js

module.exports = {
  branches: ['main'],
  preset: 'conventionalcommits',

  analyzeCommits: {
    parserOpts: {
      headerPattern: '^Merged PR (\\d+): (\\w*)(?:\\(([\\w$.\\-* ]*)\\))?: (.*)$',
      headerCorrespondence: ['pr', 'type', 'scope', 'subject']
    },
  },
  generateNotes: {
    linkReferences: true,
    linkCompare: false,
    parserOpts: {
      headerPattern: '^Merged PR (\\d+): (\\w*)(?:\\(([\\w$.\\-* ]*)\\))?: (.*)$',
      headerCorrespondence: ['pr', 'type', 'scope', 'subject']
    },
    writerOpts: {
      mainTemplate: readFileSync(join(__dirname, 'templates/template.hbs'), 'utf-8'),
      headerPartial: readFileSync(join(__dirname, 'templates/header.hbs'), 'utf-8'),
      commitPartial: readFileSync(join(__dirname, 'templates/commit.hbs'), 'utf-8'),
      footerPartial: readFileSync(join(__dirname, 'templates/footer.hbs'), 'utf-8'),
    }
  }
}

from nx-semantic-release.

jreilly-lukava avatar jreilly-lukava commented on June 27, 2024

I guess I still don't know what I'm doing :) Those setting in .releaserc.js are messing with the commit filtering. Back to the drawing board.

from nx-semantic-release.

TheUnderScorer avatar TheUnderScorer commented on June 27, 2024

Yeah, unfortunately seems like releaserc.js causes the semantic-release to ignore filtered commits from my plugin 😁.

I've got some POC for now that allows passing parserOpts and writerOpts basing on what you've done, next is adding some kind of configuration file. Feel free to test it to see if it works correctly for you!

from nx-semantic-release.

jreilly-lukava avatar jreilly-lukava commented on June 27, 2024

Wow, that was quicker than I expected. I really appreciate your effort! The changes work as I would expect them to. However after working with semantic-release there are still some pitfalls I've run into.

  • Duplicating all these config options across multiple projects in my nx monorepo is tedious, granted that may be what some people are looking for, per project options
  • Having to inline handlebar templates is a pain
  • I've come across other settings that I'd like to change also (for example, linkCompare: false, comparing tags (even if they are package specific, app-a-v1.0.0 to app-a-v1.1.0), isn't so useful if app-b has had a bunch of commits during that time.

I'm going to keep watching this repo though and am happy to help out in any way I can as I still don't have a good solution for this in my situtation.

from nx-semantic-release.

jreilly-lukava avatar jreilly-lukava commented on June 27, 2024

I managed coble something together using cosmiconfig with a .nx-releaserc.js style configuration. Should be pretty easy to extends things to read from the project config in angular/nx.json file first and then the config file, and lastly nothing if neither of those are configured. I don't have time to get a PR to you. If you want I could get you something to look at next week.

from nx-semantic-release.

TheUnderScorer avatar TheUnderScorer commented on June 27, 2024

I've come across other settings that I'd like to change also (for example, linkCompare: false, comparing tags (even if they are package specific, app-a-v1.0.0 to app-a-v1.1.0), isn't so useful if app-b has had a bunch of commits during that time.

I'm curious about this one (comparing tags), could you elaborate further? 😄

I managed coble something together using cosmiconfig with a .nx-releaserc.js style configuration. Should be pretty easy to extends things to read from the project config in angular/nx.json file first and then the config file, and lastly nothing if neither of those are configured. I don't have time to get a PR to you. If you want I could get you something to look at next week.

Sounds good! I will release what I have so far, because for now I also don't really have much time to dig into this config file stuff. Fell free to open a PR when you will have something, thanks!

Since this issue was about parserOpts/writerOpts that I've added, I will close it.
In some free time I will try to investigate adding more options that you've mentioned (ex. linkCompare) and adding better support for handlebar templates.

from nx-semantic-release.

TheUnderScorer avatar TheUnderScorer commented on June 27, 2024

🎉 This issue has been resolved in version 1.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

from nx-semantic-release.

jreilly-lukava avatar jreilly-lukava commented on June 27, 2024

I'm curious about this one (comparing tags), could you elaborate further? 😄

Sure. Take this compare link from the conventional-changelog monorepo. It's using the tags of conventional-commits-parser-v3.2.3 and conventional-commits-parser-v3.2.4 for it's comparison. But when you look at the list of commits you see commits like 5917ad2 which is isolated to another package and not even a package that is a dependency for the commits parser.

So it's for this reason I personally don't find much use for the compare link in monorepos.

from nx-semantic-release.

TheUnderScorer avatar TheUnderScorer commented on June 27, 2024

Ahh got it, makes sense!

from nx-semantic-release.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.