- 
                Notifications
    
You must be signed in to change notification settings  - Fork 29
 
          feat(lint-pr-title): rewrite in Typescript and handle merge_group events
          #233
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    aa3e8e9    to
    1493338      
    Compare
  
    6ffcec7    to
    a4982bc      
    Compare
  
    29c8e61    to
    d9c27eb      
    Compare
  
    merge_group events
      66eff4c    to
    205a034      
    Compare
  
    a04bee7    to
    a52af87      
    Compare
  
    
              
                    guicaulada
  
              
              approved these changes
              
                  
                    Sep 23, 2024 
                  
              
              
            
            
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just one small nit.
a52af87    to
    fc0443e      
    Compare
  
    …vents
This is a big update. The initial motivation was to support `merge_group` events
but this required some other changes.
We use [merge queues] in this repository, and CI is currently failing for merges
because this action doesn't support the event. We can't ensure that commits
going into `main` have messages in the correct format. We'd like to use
[`release-please`][release-please] to have releases, and this requires
conventional commit messages, so this lack of support is blocking us from having
a proper release strategy.
When linting for a merge group event, the title is no longer the thing that you
want to check. The commits themselves are what will end up in the main branch.
Getting the commits which will be pushed from the merge group is a bit tricky.
As for PRs, there are multiple strategies which can be used (squash, merge,
rebase). There can also be multiple PRs in a merge group. The PRs to be merged
might well be behind the target branch and so rebased by GitHub. We need to be
able to handle all of these cases in order to lint the correct commits.
Essentially we call a GitHub API to figure out what the commits in our merge
group branch are. In the case there are multiple PRs in a merge group, each will
get a branch based on the previous (imagine a chain). In this case we will lint
each PR's commits separately, and each will get its own results. This is all
covered by tests. Tests are a new addition to this action too.
Now, the final part. The Typescript rewrite. Trying to add the `merge_group`
event without the help of types proved to be too hard. In order to get more
typing support, I switched to using the upstream libraries from the `commitlint`
project too. This broke the build. That's for one main reason: in `commitlint`
configuration files an `extends` keyword can be given.
```json
{
  "extends": ["@commitlint/config-conventional"]
}
```
Notice that's a string. It ends up resolving to a `require` call in the
resulting code. `node` (JavaScript) Actions have to have their dependencies
bundled, but the bundler has no way to know to bundle this module, and even if
it did the dynamic `require` would still refer to a module that isn't installed,
since it would be in the bundle.
To get around all of this, we're switching off the `node` runtime and using
[`bun`][bun] directly. This isn't detectable from the perspective of the user -
good - but for working on the action it has a couple of benefits:
- There is no transpilation/building/bundling step. We can run the Typescript
  directly. That fixes the above problem.
- We don't need a `build` action to ensure we remembered to run `yarn build`
  before committing. The need to bundle code and have generated code in the
  repository is gone.
[bun]: https://bun.sh
[merge queues]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/merging-a-pull-request-with-a-merge-queue
[release-please]: https://github.com/googleapis/release-please
    fc0443e    to
    6ee7e12      
    Compare
  
    
  This was referenced Sep 23, 2024 
      
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
This is a big update. The initial motivation was to support
merge_groupevents but this required some other changes.We use merge queues in this repository, and CI is currently failing for merges because this action doesn't support the event. We can't ensure that commits going into
mainhave messages in the correct format. We'd like to userelease-pleaseto have releases, and this requires conventional commit messages, so this lack of support is blocking us from having a proper release strategy.When linting for a merge group event, the title is no longer the thing that you want to check. The commits themselves are what will end up in the main branch. Getting the commits which will be pushed from the merge group is a bit tricky. As for PRs, there are multiple strategies which can be used (squash, merge, rebase). There can also be multiple PRs in a merge group. The PRs to be merged might well be behind the target branch and so rebased by GitHub. We need to be able to handle all of these cases in order to lint the correct commits. Essentially we call a GitHub API to figure out what the commits in our merge group branch are. In the case there are multiple PRs in a merge group, each will get a branch based on the previous (imagine a chain). In this case we will lint each PR's commits separately, and each will get its own results. This is all covered by tests. Tests are a new addition to this action too.
Now, the final part. The Typescript rewrite. Trying to add the
merge_groupevent without the help of types proved to be too hard. In order to get more typing support, I switched to using the upstream libraries from thecommitlintproject too. This broke the build. That's for one main reason: incommitlintconfiguration files anextendskeyword can be given.{ "extends": ["@commitlint/config-conventional"] }Notice that's a string. It ends up resolving to a
requirecall in the resulting code.node(JavaScript) Actions have to have their dependencies bundled, but the bundler has no way to know to bundle this module, and even if it did the dynamicrequirewould still refer to a module that isn't installed, since it would be in the bundle.To get around all of this, we're switching off the
noderuntime and usingbundirectly. This isn't detectable from the perspective of the user - good - but for working on the action it has a couple of benefits:buildaction to ensure we remembered to runyarn buildbefore committing. The need to bundle code and have generated code in the repository is gone.