-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feature: reference workflowpattern package to add workflow filtering #1709
feature: reference workflowpattern package to add workflow filtering #1709
Conversation
…is function, and we need to determine a way to pass the payload down to the function in order to check it using filters.@
…ter and the *ignore variant (e.g. 'paths' and 'paths-ignore') are both set. Define the function signature in workflow_pattern so that I can easily reference the signature for Skip()/Filter(). Add TODOs.
@ae-ou this pull request has failed checks 🛠 |
Codecov Report
@@ Coverage Diff @@
## master #1709 +/- ##
==========================================
+ Coverage 61.22% 62.49% +1.27%
==========================================
Files 46 51 +5
Lines 7141 8282 +1141
==========================================
+ Hits 4372 5176 +804
- Misses 2462 2715 +253
- Partials 307 391 +84
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
return false | ||
} | ||
|
||
tw := new(workflowpattern.StdOutTraceWriter) |
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.
We probably want a logrus tracewriter for consistent logging
it shoud respect --json
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.
Hello. I'm looking back at this PR now.
It doesn't look like there's any implementation of your workflowpattern.TraceWriter
interface in the Logrus package - their Info function uses the Info(args ...interface{})
stub.
The workflowpattern.TraceWriter
Interface doesn't seem to be used anywhere else in nektos/act - should the interface be altered to comply with the Logrus.Info(args ...interface{})
function stub, or did you initially plan to create an implementation of workflowpattern.TraceWriter
that wraps around Logrus?
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.
I wrote workflow pattern in a way to avoid any non golang stdlib.
For example if we want to change the logging system, this package doesn't need to change.
fmt.Sprintf can create a string you can pass to logrus similar to what the default impl. does.
I expect the caller of the package to create a small adapter struct.
I can create a logrus adapter for you, it's not time expensive.
Maybe just add an interface adapter for logrus like LogrusLogger(some custom interface with the logging signatures of logrus) returns the existing interface without logrus import.
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.
Actually we can just append a f to Info in this package and it is an exact match of a logrus logger instance
Logrus.Infof should not be used, use the logger instance of act. Not a static wrapper of the standard logger
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.
I've updated the TraceWriter
interface so that Info
is now Infof
.
Logrus.Infof should not be used, use the logger instance of act. Not a static wrapper of the standard logger
Apologies if I'm being a bit dense, but I'm not sure that I'm following you. Do you want me to do dependency inversion here? As in - specify the TraceWriter
interface as a parameter for my functions/as an attribute on the Workflow
struct (which my functions receive), so that I can then pass in a concrete Logrus instance (since it now lines up with the interface) from upstream?
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.
I mean pass common.Logger(ctx)
to the workflow pattern package as Tracewriter if possible (it returns a logrus logger object).
The logrus package has Infof Both as an interface Method and as an static package function, but the logrus interface has name FieldLogger/Ext1Logger not logrus.
Sorry for the confusion.
You can keep logrus interfaces in all other packages, because they are already using logrus directly.
I have had thought about this a while ago. I would initially apply the path filter only to watch mode. |
No idea, maybe the workflowplanner can add a filter function to pass a function to decide which workflow to remove from the workflowplanner object, after logging the exact reason why it won't run. Then you can reference the full payload object to decide if you want to skip it.
No idea, the planner wasn't my idea. It seems act merges all workflows into a single planner object. |
@ae-ou this pull request has failed checks 🛠 |
@ae-ou this pull request has failed checks 🛠 |
@ae-ou this pull request is now in conflict 😩 |
Description
This is a followup to #1618 by @ChristopherHX - which added in a package to accommodate filtering. This PR works to invoke the filtering when the
act
command is executed.This PR is in a draft state - there are a number of questions that I'm not in a position to answer (which are outlined in the "Questions" section below), and I can't complete this PR without these questions being answered. Feedback/answers to my questions are much appreciated.
Changes Thusfar
FindFilterPatterns()
function to theWorkflow
struct.pull_request
orpush
), it then traverses the nodes inWorkFlow.RawOn
and builds up a struct (FilterPatterns
) containing slices of filters.ShouldFilterWorkflow()
function to theWorkflow
struct.FindFilterPatterns()
to get the filters patterns (relating to the specified event) on the workflow, it then compiles these patterns into Regex, and compares the provided event against the patterns (to determine whether the workflow should be added to the plan).workflowpattern.FilterInputsFunc
)workflowpattern.Skip()
andworkflowpattern.Filter()
implement.Notes
RawOn
to a struct, so that we could directly unmarshal any filters found in the workflow into this struct.RawOn
.TODO
comments in my code - some of these are the basis for questions below.Questions
event
to theShouldFilterWorkflow()
function? Since I will probably callShouldFilterWorkflow()
within the functions onmodel.workflowPlanner
struct, should I store a copy of theevent
on this struct?runner.runnerImpl.configure()
function builds up aneventJson
attribute, but none of these functions/structs are exported.cmd.newRunCommand()
), we haven't calledr, err := runner.New(config)
, so this structure wouldn't be available to theplanner
- even if the attribute was exported.model.GithubContext
struct appears to relate to the Github event, but there's no function to unmarshal a JSON file into the struct.workflowPlanner.PlanJob()
? Filters are a workflow-level attribute (and a Job exists as a component of a workflow file) but some users may wish to invoke a job without the context of its wider workflow.FindFilterPatterns()
andShouldFilterWorkflow()
) to return errors instead of callinglog.Fatal()
?log.Fatal()
in line with the other functions in themodel
package, as I saw very fewerror
return values on function signatures.log.Fatal
inpkg/*
#1705) which is working on replacinglog.Fatal()
-e
flag) that don't satisfy the conditions on their workflow file, the addition of filtering may break the workflows for those users. Is there a preferred way to communicate this change to those users?