Skip to content

Feature: Protect existing workflow files from accidental overwrites.#3407

Open
twoGiants wants to merge 1 commit intoknative:mainfrom
twoGiants:issue-782-defensive-workflow-file-generation
Open

Feature: Protect existing workflow files from accidental overwrites.#3407
twoGiants wants to merge 1 commit intoknative:mainfrom
twoGiants:issue-782-defensive-workflow-file-generation

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

/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 41.57303% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.56%. Comparing base (c12ec96) to head (ffadf68).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
cmd/ci/config.go 14.28% 42 Missing ⚠️
cmd/ci/workflow.go 30.00% 5 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.56%   -0.04%     
==========================================
  Files         179      179              
  Lines       20228    20282      +54     
==========================================
+ Hits        11045    11067      +22     
- Misses       8011     8044      +33     
+ Partials     1172     1171       -1     
Flag Coverage Δ
e2e 38.45% <0.00%> (-0.12%) ⬇️
e2e go 32.65% <0.00%> (-0.10%) ⬇️
e2e node 28.57% <0.00%> (-0.09%) ⬇️
e2e python 32.17% <0.00%> (-0.10%) ⬇️
e2e quarkus 28.71% <0.00%> (-0.09%) ⬇️
e2e rust 28.13% <0.00%> (-0.05%) ⬇️
e2e springboot 26.59% <0.00%> (-0.08%) ⬇️
e2e typescript 28.68% <0.00%> (-0.11%) ⬇️
integration 17.54% <0.00%> (-0.04%) ⬇️
unit macos-14 42.25% <44.00%> (-0.03%) ⬇️
unit macos-latest 42.26% <44.00%> (-0.02%) ⬇️
unit ubuntu-24.04-arm 42.59% <41.57%> (-0.03%) ⬇️
unit ubuntu-latest 43.15% <44.00%> (-0.03%) ⬇️
unit windows-latest 42.28% <44.00%> (-0.02%) ⬇️

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

@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
cmd/ci/config.go Outdated
Comment on lines 156 to 167
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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good catch! I was also unsure about this one. Thank you. Will correct it 😸 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am setting the default during resolution, the I don't need to pass down cobra.Command. Is that ok too?

Copy link
Contributor Author

@twoGiants twoGiants Feb 5, 2026

Choose a reason for hiding this comment

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

After talking to David I got a small primer about how default values are set and it's probably best to evaluate the cmd.Flags().Changed(WorkflowNameFlag) and do what you proposed Luke 😺

@twoGiants twoGiants force-pushed the issue-782-defensive-workflow-file-generation branch from 6fb5f5e to 09b4258 Compare February 5, 2026 10:08
@twoGiants twoGiants marked this pull request as ready for review February 5, 2026 10:09
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 5, 2026
@twoGiants twoGiants force-pushed the issue-782-defensive-workflow-file-generation branch from 09b4258 to 332f403 Compare February 5, 2026 10:13
@twoGiants twoGiants requested a review from lkingland February 5, 2026 10:14
@twoGiants twoGiants force-pushed the issue-782-defensive-workflow-file-generation branch 2 times, most recently from 9487908 to b055aaa Compare February 5, 2026 15:14
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. When --force
is used and a file exists, a warning is logged.

Remote builds now use a distinct default workflow name ("Remote Func
Deploy") to avoid conflicts, while explicit --workflow-name values
are always preserved regardless of --remote flag.

Issue knative#3256

Signed-off-by: Stanislav Jakuschevskij <sjakusch@redhat.com>
@twoGiants twoGiants force-pushed the issue-782-defensive-workflow-file-generation branch from b055aaa to ffadf68 Compare February 5, 2026 16:52
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. 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