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

fix: .gitignore .func #1728

Merged
merged 1 commit into from
May 16, 2023
Merged

Conversation

lkingland
Copy link
Member

  • 🐛 .gitignore file path incorrect when creating in a different path that CWD
  • 🐛 .gitignore /.func was causing the build stamp to update
  • 🎁 can now force inclusion of .func in source control by commenting the line
  • 🎁 adds built log journaling via a WithStampJournal option

/kind bug
/kind enhancement

Fixes an issue where .gitignore was not correctly updated when running func with a custom --path
Improves build caching

@knative-prow knative-prow bot added kind/bug Categorizes issue or PR as related to a bug. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/enhancement approved Indicates a PR has been approved by an approver from all required OWNERS files. labels May 9, 2023
@knative-prow knative-prow bot requested review from jrangelramos and nainaz May 9, 2023 06:05
@knative-prow knative-prow bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 9, 2023
@codecov
Copy link

codecov bot commented May 9, 2023

Codecov Report

Patch coverage: 66.42% and project coverage change: +10.10 🎉

Comparison is base (e9385f3) 49.66% compared to head (128fc0e) 59.76%.

❗ Current head 128fc0e differs from pull request most recent head 014ef00. Consider uploading reports for the commit 014ef00 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1728       +/-   ##
===========================================
+ Coverage   49.66%   59.76%   +10.10%     
===========================================
  Files          82       94       +12     
  Lines       11474    12343      +869     
===========================================
+ Hits         5698     7377     +1679     
+ Misses       5281     4285      -996     
- Partials      495      681      +186     
Flag Coverage Δ
e2e-test-oncluster-runtime 29.34% <44.28%> (?)
e2e-test-runtime-go 27.90% <44.28%> (?)
e2e-test-runtime-quarkus 29.17% <44.28%> (?)
e2e-test-runtime-springboot 27.99% <44.28%> (?)
e2e-test-runtime-typescript 29.17% <44.28%> (?)
integration-tests 50.21% <44.28%> (?)
unit-tests-ubuntu-latest 49.75% <66.42%> (+0.09%) ⬆️
unit-tests-windows-latest 48.91% <66.42%> (?)

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

Impacted Files Coverage Δ
pkg/functions/client.go 63.57% <62.93%> (+7.04%) ⬆️
pkg/functions/function.go 84.56% <83.33%> (+5.21%) ⬆️

... and 48 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@lkingland lkingland marked this pull request as ready for review May 9, 2023 09:31
@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 May 9, 2023
@knative-prow knative-prow bot requested a review from rhuss May 9, 2023 09:31
@lance
Copy link
Member

lance commented May 9, 2023

@lkingland the linter fails with

 Error: SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details.  (staticcheck)

// TestClient_BuiltDetects ensures that the client's Built command detects
// filesystem changes as indicating the function is no longer Built (aka stale)
// This includes modifying timestamps, removing or adding files.
func TestClient_BuiltDetects(t *testing.T) {
Copy link
Member Author

@lkingland lkingland May 10, 2023

Choose a reason for hiding this comment

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

This test was just moved in its entirety to be with the other functions tests, since the Built logic is now a method on Function rather than a package static function.

@@ -394,19 +408,46 @@ func (f Function) Write() (err error) {
//
// The runtime data directory .func is created in the function root if
// necessary.
func (f Function) Stamp() (err error) {
func (f Function) Stamp(oo ...stampOption) (err error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Journaling is very much an optional, debugging-focused feature, so I used the option pattern here to retain the default API as the happy-path

@lkingland lkingland force-pushed the fix-gitignore-func branch 3 times, most recently from 8bda323 to ad45e9c Compare May 11, 2023 05:54
@lkingland lkingland requested a review from lance May 11, 2023 12:58
@knative-prow knative-prow bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 11, 2023
@@ -960,6 +966,178 @@ func (c *Client) Push(ctx context.Context, f Function) (Function, error) {
return f, nil
}

// ensureRunDataDir creates a .func directory at the given path, and
// registers it as ignored in a .gitignore file.
func ensureRunDataDir(root string) error {
Copy link
Member Author

@lkingland lkingland May 11, 2023

Choose a reason for hiding this comment

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

These functions (ensureRunDataDir, fingerprint, ...) support the functionality of the Client methods, so they were moved from function.go. Keeping Function as close to a data object as possible, with Client being the actor. The only one appreciably modified was this one, ensureRunDataDir.

@@ -51,6 +52,138 @@ func TestClient_New(t *testing.T) {
}
}

// TestClient_New_RunData ensures that the .func runtime directory is
// correctly created.
func TestClient_New_RunDataDir(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the new test

@lkingland lkingland requested a review from zroubalik May 13, 2023 05:10
- The .gitignore file was always relative to process' current working
  directory.  Now correctly uses the function root
- The .gitignore file was always being updated, causing its modification
  timestamp to be updated multiple times throughout the executaion of
  any client commands.
- Adds the ability to override this behavior by commenting out the line
  in the .gitignore.
- Adds the ability to request that stamping create an ongoing journal
  via a build log file with timestamp prefix (for debugging)
@matejvasek
Copy link
Contributor

matejvasek commented May 16, 2023

Running func run twice in a row do build also on the second run, I think that should not be happening.

@matejvasek
Copy link
Contributor

matejvasek commented May 16, 2023

Running func run twice in a row do build also on the second run, I think that should not be happening.

Although this might not be caused by this PR.
EDIT: it is not caused by this PR, it was probably broken some time ago.
Deploy does the same unnecessary rebuild, I would swear this worked at some point.

@lkingland
Copy link
Member Author

lkingland commented May 16, 2023

Running func run twice in a row do build also on the second run, I think that should not be happening.

Although this might not be caused by this PR. EDIT: it is not caused by this PR, it was probably broken some time ago. Deploy does the same unnecessary rebuild, I would swear this worked at some point.

Thanks for taking a look. Yes caching is something that is still not happening with complete reliability. This PR gets it working in a few more scenarios and makes it more auditable so we can debug the others more easily. In particular it helps enable the changes to run in #1733. I would expect caching to be working as part of that PR

@matejvasek
Copy link
Contributor

/approve
/lgtm

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label May 16, 2023
@knative-prow
Copy link

knative-prow bot commented May 16, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lkingland, matejvasek

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

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [lkingland,matejvasek]

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

@knative-prow knative-prow bot merged commit 94c81d4 into knative:main May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. kind/enhancement lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants