-
Notifications
You must be signed in to change notification settings - Fork 156
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
Support skipping stages by path pattern or commit message prefix #4922
Conversation
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
…stage Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
s.logger.Error("failed to report stage status", zap.Error(err)) | ||
return model.StageStatus_STAGE_FAILURE | ||
} | ||
lp.Infof("The stage was successfully skipped due to the skip configuration of the stage.") |
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.
lp.Infof("The stage was successfully skipped due to the skip configuration of the stage.") | |
lp.Info("The stage was successfully skipped due to the skip configuration of the stage.") |
nits. There is no need to use formater here 👀
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.
Thanks, I fixed it now. e2e35f4
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
IMO, I agree with khanhtc1202. Because we have no need to hide functions from other controller codes. |
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.
Sorry for the late review 🙏 Added some comments.
stageConfig := in.StageConfig | ||
var skipOptions config.SkipOptions | ||
switch stageConfig.Name { | ||
case model.StageAnalysis: | ||
skipOptions = stageConfig.AnalysisStageOptions.SkipOn | ||
case model.StageWait: | ||
skipOptions = stageConfig.WaitStageOptions.SkipOn | ||
case model.StageWaitApproval: | ||
skipOptions = stageConfig.WaitApprovalStageOptions.SkipOn | ||
case model.StageScriptRun: | ||
skipOptions = stageConfig.ScriptRunStageOptions.SkipOn | ||
default: | ||
return false, nil |
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.
[imo] How about adding the func StageConfig.GetSkipConfig()
in the config package?
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 think the current one is enough because
StageConfig.GetSkipConfig()
will be used only inskipstage
package- adding the func to each stage model seems redundant
WDYT?
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.
OK, I got it 👍
func commitMessageHasAnyPrefix(commitMessage string, prefixes []string) bool { | ||
for _, prefix := range prefixes { | ||
if strings.HasPrefix(commitMessage, prefix) { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
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.
[imo] It might not be a func, just put it in the skipByCommitMessagePrefixes
?
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.
You mean we need to mock repo.ChangedFiles
in skipByCommitMessagePrefixes
?
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 feel commitMessageHasAnyPrefix
doesn't have much logic, so IMO, it would be nice to gather the logic to the skipByCommitMessagePrefixes
.
You mean we need to mock repo.ChangedFiles in skipByCommitMessagePrefixes?
When testing, we might need to mock as you said.
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.
@ffjlabo thanks, I merged the func and used mock in tests.
TBH, I missed git.mock.go https://github.com/pipe-cd/pipecd/blob/master/pkg/git/gittest/git.mock.go
func hasOnlyPathsToSkip(skipPatterns []string, changedFiles []string) (bool, error) { | ||
matcher, err := filematcher.NewPatternMatcher(skipPatterns) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
for _, changedFile := range changedFiles { | ||
if !matcher.Matches(changedFile) { | ||
return false, nil | ||
} | ||
} | ||
|
||
return true, nil | ||
} |
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.
[imo] It might not be a func, just put it in the skipByPathPattern
?
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.
@ffjlabo thanks, I merged the func and used mock in tests.
// checkSkipStage checks whether the stage should be skipped or not. | ||
func checkSkipStage(ctx context.Context, in executor.Input, opt config.SkipOptions) (skip bool, err error) { | ||
if len(opt.Paths) == 0 && len(opt.CommitMessagePrefixes) == 0 { | ||
// When no condition is specified. | ||
return false, nil | ||
} |
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.
[imo] It might not be a func, just put it in the shouldSkipStage
?
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.
Thanks, I did it here 8a96a8c
Sorry to be late. I agree with it.
|
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
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.
If I push several commits at once, this PR's code seems to process only the last commit.
I think all pushed commits should be handled the same way as the last commit. What do you think?
Thank you, that's important. a. Path Pattern: This PR already checks ALL changes from the running commit to the latest commit as below. changedFiles, err := repo.ChangedFiles(ctx, runningRev, targetRev) b. Commit Message: As you said, only the latest commit is checked. Cases when the latest commit matches the condition but not all commits match it would be:
cf.
@peaceiris What do you think? Should ALL commits match the condition? |
Only the latest commit is good enough for my use case 👍 |
@peaceiris I got it, thank you so much! |
I think the same way, we should only treat the last commit message 👍 |
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.
LGTM, can't wait for this in action 👍
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.
Thank you. There is a consensus to see only the last commit message, so LGTM.
What this PR does / why we need it:
This PR enables skipping stages (Analysis,WaitApproval,Wait,ScriptRun) when the commit matches
configured path patterns or commit message prefixes.
Which issue(s) this PR fixes:
Fixes #4899
Does this PR introduce a user-facing change?: N/A (only append)
How to use
Configuration: add
with.skipOn
section in stages to skip.paths
: When ALL changes of the commit match them, the stage will be skipped.commitMessagePrefixes
: When the prefix of the commit's message matches ANY of them, the stage will be skipped.When all
skipOn
conditions of each stage passed, the deployment will be: