Skip to content
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

refactor(ruleset)!: improve match code efficiency and properly handle status #1255

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ecrupper
Copy link
Contributor

@ecrupper ecrupper commented Feb 17, 2025

steps:
  - name: test
    image: alpine:latest
    ruleset:
      event: pull_request
      branch: [ hotfix-* ]
      operator: or
    commands:
      - echo blah

The above does not purge. It only gets skipped when the worker handles skipping. The compiler should be corrected here and return FALSE when the above is calculated with rule data == push on main for example

Further, I refactored the match code to be more efficient. I removed the unnecessary Parallel key, which will be addressed in a follow-up worker PR, which introduces stage status.

Added some bench mark testing which is just there for fun right now, but I used it to confirm the improvements by comparing these changes to main. Improvement of about half a second, which definitely adds up over parsing thousands of rulesets.

Another thing I added was separation of if and unless operators/matchers if defined. Otherwise, they'll inherit from the Ruleset like usual (non-breaking).

@ecrupper ecrupper requested a review from a team as a code owner February 17, 2025 21:08
Copy link

codecov bot commented Feb 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.65%. Comparing base (cf8aea3) to head (fc8d0a5).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1255      +/-   ##
==========================================
+ Coverage   56.59%   56.65%   +0.06%     
==========================================
  Files         629      629              
  Lines       35645    35598      -47     
==========================================
- Hits        20172    20167       -5     
+ Misses      14792    14764      -28     
+ Partials      681      667      -14     
Files with missing lines Coverage Δ
compiler/native/compile.go 70.37% <100.00%> (+0.06%) ⬆️
compiler/types/pipeline/container.go 83.67% <100.00%> (+0.75%) ⬆️
compiler/types/pipeline/ruleset.go 100.00% <100.00%> (+21.71%) ⬆️
compiler/types/pipeline/secret.go 94.59% <100.00%> (ø)
compiler/types/pipeline/stage.go 96.34% <100.00%> (ø)
compiler/types/yaml/buildkite/ruleset.go 83.81% <100.00%> (+1.99%) ⬆️
compiler/types/yaml/yaml/ruleset.go 66.21% <100.00%> (+3.21%) ⬆️

plyr4
plyr4 previously approved these changes Feb 17, 2025
KellyMerrick
KellyMerrick previously approved these changes Feb 17, 2025
@ecrupper ecrupper changed the title fix(ruleset): proper match for status with Or operator refactor(ruleset)!: improve match code efficiency and properly handle status Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants