Skip to content

Conversation

@twoGiants
Copy link
Contributor

@twoGiants twoGiants commented Jan 30, 2026

Changes

  • 🎁 Add workflow file existence check to prevent accidental overwrites
  • 🎁 Add --force flag to explicitly allow overwriting existing workflow files
  • 🎁 Add warning message when --force is used to overwrite existing workflows
  • 🎁 Add distinct default workflow name for remote builds ("Remote Func Deploy") to avoid conflicts
  • 🧹 Introduce Logger interface to cmd/common for structured logging 👉 continue reading below 📖

Logger Clarifications

Here is some ground work for the upcoming --verbose flag implementation. I introduce logging using an interface and maybe we can slowly start switching to such an approach.

For now the interface has only one method but more are to follow. I am keeping it simple on purpose. The logger is also testable with a spy test double.

When implementing the --verbose logging I will introduce VerboseInfo(...) and SetLevel() methods and a new VerboseInfoLevel log level for verbose logging and set it when the --verbose flag is used.

It's a first draft/proposal for the introduction of logging to our project. I chose this path because we will be able to replace the logging implementation easily and also allow the user to provide his own logger if he uses func as library.

[UPDATED]
This is how the logging is currently configured to look:

FUNC_ENABLE_CI_CONFIG=true /home/sjakusch/Dev/active/knative/forks/knative-func/func config ci --branch=main --force
msg="WARNING: --force flag is set, overwriting existing GitHub Workflow file"

Now I am a bit unsure about it. It seems that what I am looking for here is not really logging in the traditional sense but information shown to the user. In a GUI that would be some notification message or an info text and not actual logs.

/kind enhancement

Relates to #3256

Release Note

The `func config ci` command now protects existing workflow files from accidental overwrites. Use the `--force` flag to explicitly overwrite existing files.

Docs


@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 30, 2026
@knative-prow knative-prow bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 30, 2026
@twoGiants twoGiants force-pushed the issue-782-defensive-workflow-file-generation branch 4 times, most recently from c7ebe59 to ab5ed8f Compare February 2, 2026 16:17
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 2, 2026
@twoGiants twoGiants force-pushed the issue-782-defensive-workflow-file-generation branch from ab5ed8f to 8162643 Compare February 2, 2026 18:12
@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 33.98058% with 68 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.49%. Comparing base (c12ec96) to head (6fb5f5e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/ci/config.go 14.00% 43 Missing ⚠️
cmd/common/common.go 30.43% 15 Missing and 1 partial ⚠️
cmd/ci/workflow.go 33.33% 4 Missing and 2 partials ⚠️
cmd/ci/writer.go 66.66% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3407      +/-   ##
==========================================
- Coverage   54.60%   54.49%   -0.11%     
==========================================
  Files         179      179              
  Lines       20228    20295      +67     
==========================================
+ Hits        11045    11060      +15     
- Misses       8011     8061      +50     
- Partials     1172     1174       +2     
Flag Coverage Δ
e2e 38.47% <8.98%> (-0.10%) ⬇️
e2e go 32.68% <8.98%> (-0.07%) ⬇️
e2e node 28.60% <8.98%> (-0.06%) ⬇️
e2e python 32.19% <8.98%> (-0.07%) ⬇️
e2e quarkus 28.72% <8.98%> (-0.08%) ⬇️
e2e rust 28.16% <8.98%> (-0.02%) ⬇️
e2e springboot 26.60% <8.98%> (-0.07%) ⬇️
e2e typescript 28.71% <8.98%> (-0.08%) ⬇️
integration 17.49% <0.00%> (-0.09%) ⬇️
unit macos-14 42.17% <29.21%> (-0.11%) ⬇️
unit macos-latest 42.17% <29.21%> (-0.11%) ⬇️
unit ubuntu-24.04-arm 42.51% <27.18%> (-0.11%) ⬇️
unit ubuntu-latest 43.06% <29.21%> (-0.11%) ⬇️
unit windows-latest 42.19% <29.21%> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@twoGiants twoGiants force-pushed the issue-782-defensive-workflow-file-generation branch from 8162643 to 8109c29 Compare February 3, 2026 08:20
@twoGiants
Copy link
Contributor Author

/cc @gauron99 @matejvasek @lkingland

The PR is ready for review. Please read the description about the logging.

@gauron99
Copy link
Contributor

gauron99 commented Feb 3, 2026

/lgtm
/hold for potential other reviews or the ci jobs to complete 😁 . Unhold when you please

@knative-prow knative-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 3, 2026
@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Feb 3, 2026
@twoGiants
Copy link
Contributor Author

twoGiants commented Feb 3, 2026

Codecov Report

❌ Patch coverage is 37.25490% with 64 lines in your changes missing coverage. Please review. ✅ Project coverage is 54.52%. Comparing base (c12ec96) to head (8109c29). ⚠️ Report is 1 commits behind head on main.
Files with missing lines
...
☔ View full report in Codecov by Sentry. 📢 Have feedback on the report? Share it here.
🚀 New features to boost your workflow:

The codecov tool is poorly configured or am I missing something? It's flagging the resolveBranch function as uncovered and much more but I have explicit tests for this paths TestNewConfigCICmd_BranchFlagResolution, TestNewConfigCICmd_BranchFlagResolutionError etc.

@gauron99

The `func config ci` command previously overwrote existing workflow
files silently, risking loss of user customizations.

Now the command checks if a workflow file exists before writing and
returns an error unless the `--force` flag is specified. This gives
users explicit control over when to replace their existing workflows.
When --force is used and a workflow file exists, a warning
message is logged to inform the user that the existing file is being
overwritten.

The implementation introduces a Logger interface to cmd/common
with slog-based production implementation and a buffer-based test
double for verification.

Additionally, remote builds now use a distinct default workflow name
("Remote Func Deploy") to avoid conflicts.

Issue knative#3256

Signed-off-by: Stanislav Jakuschevskij <sjakusch@redhat.com>
@twoGiants twoGiants force-pushed the issue-782-defensive-workflow-file-generation branch from 8109c29 to 6fb5f5e Compare February 3, 2026 11:00
@knative-prow knative-prow bot removed the lgtm Indicates that a PR is ready to be merged. label Feb 3, 2026
@knative-prow
Copy link

knative-prow bot commented Feb 3, 2026

New changes are detected. LGTM label has been removed.

@knative-prow
Copy link

knative-prow bot commented Feb 3, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: twoGiants
Once this PR has been reviewed and has the lgtm label, please ask for approval from gauron99. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@twoGiants twoGiants marked this pull request as draft February 3, 2026 12:30
@knative-prow knative-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 3, 2026
Comment on lines +156 to +168
func resolveWorkflowName() string {
workflowName := viper.GetString(WorkflowNameFlag)
if workflowName != DefaultWorkflowName && workflowName != "" {
return workflowName
}

useRemoteBuild := viper.GetBool(UseRemoteBuildFlag)
if useRemoteBuild {
return DefaultRemoteBuildWorkflowName
}

return DefaultWorkflowName
}
Copy link
Member

@lkingland lkingland Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I understand this right, if a user explicitly sets workflow-name="Func Deploy" (the default value), the function treats it as if no custom name was provided because of the workflowName != DefaultWorkflowName check. This means with --remote --workflow-name="Func Deploy", we'd get "Remote Func Deploy" instead of their explicitly requested "Func Deploy"?

Something like this might help:

workflowNameChanged := cmd.Flags().Changed(WorkflowNameFlag)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/enhancement size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants