ietf-tools / semver-action

GitHub Action to calculate the next release version based on conventional commits
BSD 3-Clause "New" or "Revised" License
56 stars 22 forks source link

Support convention from Pull Request #40

Closed jsong336 closed 9 months ago

jsong336 commented 9 months ago

Hi,

I am wondering if server-action could support similar convention for pull request as well. I know this is more based on Conventional Commit but I see a lot of use case for something similar for pull request. After all, pull request will become merge commit : ) Maybe something like this

const target = core.getInput('target').trim(); 
...
 // PARSE COMMITS
  const majorChanges = []
  const minorChanges = []
  const patchChanges = []

  if (target === "commit") {
    for (const commit of commits) {
      ...
    }
  } else if (target === "pull_request"){
    const { eventName } = github.context;  
    if (eventName !== "pull_request") {
      return core.setFailed(`Expected pull_request type but current event is ${eventName}`);
    }
    const pullRequest = context?.payload?.pull_request; 
    if (!pullRequest){
      return core.setFailed(`Cannot find pull request title.`)
    }
    try {
      const cAst = cc.toConventionalChangelogFormat(cc.parser(pullRequest.title))
      if (bumpTypes.major.includes(cAst.type)) {
        majorChanges.push(pullRequest.title)
        core.info(`[MAJOR] Pull Request: ${pullRequest.title} of type ${cAst.type} will cause a major version bump.`)
      } else if (bumpTypes.minor.includes(cAst.type)) {
        minorChanges.push(pullRequest.title)
        core.info(`[MINOR] Pull Request: ${pullRequest.title} of type ${cAst.type} will cause a minor version bump.`)
      } else if (bumpTypes.patchAll || bumpTypes.patch.includes(cAst.type)) {
        patchChanges.push(pullRequest.title)
        core.info(`[PATCH] Pull Request: ${pullRequest.title} of type ${cAst.type} will cause a patch version bump.`)
      } else {
        core.info(`[SKIP] Pull Request ${pullRequest.title} of type ${cAst.type} will not cause any version bump.`)
      }
      for (const note of cAst.notes) {
        if (note.title === 'BREAKING CHANGE') {
          majorChanges.push(pullRequest.title)
          core.info(`[MAJOR] Pull Request ${pullRequest.title} has a BREAKING CHANGE mention, causing a major version bump.`)
        }
      }
    } catch (err) {
      core.info(`[INVALID] Skipping Pull Request: ${pullRequest.title} as it doesn't follow conventional commit format.`)
    }
  } else {
    return core.setFailed(`${target} is not know target.`)
  }
NGPixel commented 9 months ago

You really shouldn't bump versions during a pull request workflow...

When merging pull requests, you can either use merge, which will create an extra commit that isn't valid conventional commit, but that's fine as it will be ignored and keep parsing the other commits from the PR. Otherwise you can use squash merge which lets you define the commit message and make it conventional commit compliant.

In either cases, the bump would occur once merged in the target branch, not during any PR workflows...

Closing as no plan to support the behavior you're proposing.