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

Include repository license in package when available #920

Merged
merged 2 commits into from
Aug 2, 2022

Conversation

jsoriano
Copy link
Member

@jsoriano jsoriano commented Aug 2, 2022

If the package doesn't include a LICENSE.txt file, look for one in the repository, and include it if found.

Implements elastic/package-spec#298 (comment).

@jsoriano jsoriano requested a review from a team August 2, 2022 13:07
@jsoriano jsoriano self-assigned this Aug 2, 2022
Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

I know that some packages are using NOTICE.txt to carry license and Kibana shows that file. I don't know what's the difference between NOTICE.txt and LICENSE.txt, but maybe this is something we need to sort out too.

return errors.Wrap(err, "failure while looking for license in repository")
}

logger.Debugf("License text found in %q will be included in package", sourceLicensePath)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe info?

Copy link
Member Author

@jsoriano jsoriano Aug 2, 2022

Choose a reason for hiding this comment

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

Ok.

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 only thing logged now for packages in the integrations repo. Is this so relevant that requires higher logging level than other things? 🙂

$ elastic-package build --zip
Build the package
README.md file rendered: /home/jaime/gocode/src/github.com/elastic/integrations/packages/apache/docs/README.md
2022/08/02 16:00:17  INFO License text found in "/home/jaime/gocode/src/github.com/elastic/integrations/LICENSE.txt" will be included in package
Package built: /home/jaime/gocode/src/github.com/elastic/integrations/build/packages/apache-1.5.0.zip
Done

Comment on lines +269 to +272
dir, err := findRepositoryRootDirectory()
if errors.Is(err, os.ErrNotExist) {
return "", errors.New("package can be only built inside of a Git repository (.git folder is used as reference point)")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it change the implementation logic or is it just refactoring?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just refactoring, this is basically a copy of what there was in the loop looking for .git.

@@ -157,6 +159,11 @@ func BuildPackage(options BuildOptions) (string, error) {
return "", errors.Wrap(err, "copying package contents failed")
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Please leave logger.Debugf here for consistency with other steps (clear target, encode dashboards, resolve fields).

Copy link
Member Author

Choose a reason for hiding this comment

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

Here it does different things depending on the situation, so it will log two messages for the same thing, do we still want the log message here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, message added, now it looks like this:

When copied from the repo:

2022/08/02 15:59:57 DEBUG Copy license file if needed
2022/08/02 15:59:57  INFO License text found in "/home/jaime/gocode/src/github.com/elastic/integrations/LICENSE.txt" will be included in package

When already available in the package:

2022/08/02 16:01:32 DEBUG Copy license file if needed
2022/08/02 16:01:32 DEBUG License file in the package will be used

func copyLicenseTextFile(licensePath string) error {
_, err := os.Stat(licensePath)
if err == nil {
// License is already there, nothing to do.
Copy link
Contributor

Choose a reason for hiding this comment

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

Debug message?

Copy link
Member Author

Choose a reason for hiding this comment

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

Even if it does nothing? 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

Added.

@@ -233,7 +240,53 @@ func signZippedPackage(options BuildOptions, zippedPackagePath string) error {
return nil
}

func copyLicenseTextFile(licensePath string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess that you don't check if the license content has changed?

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean? The file is copied as is (as any other file in the package).

Copy link
Contributor

Choose a reason for hiding this comment

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

For example, the check command fails if README.md is outdated due to changed fields.

Copy link
Member Author

Choose a reason for hiding this comment

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

But this content in the README is generated and has to be kept on sync with the fields definitions. Nothing is generated in the license files, they are copied as they are, as other files in packages.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok 👍

@elasticmachine
Copy link
Collaborator

elasticmachine commented Aug 2, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-08-02T14:01:09.885+0000

  • Duration: 28 min 37 sec

Test stats 🧪

Test Results
Failed 0
Passed 771
Skipped 0
Total 771

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@elasticmachine
Copy link
Collaborator

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (32/32) 💚
Files 66.667% (78/117) 👍
Classes 62.195% (102/164) 👍
Methods 49.697% (328/660) 👍
Lines 33.198% (2940/8856) 👍
Conditionals 100.0% (0/0) 💚

@jsoriano
Copy link
Member Author

jsoriano commented Aug 2, 2022

I know that some packages are using NOTICE.txt to carry license and Kibana shows that file. I don't know what's the difference between NOTICE.txt and LICENSE.txt, but maybe this is something we need to sort out too.

There was a discussion about this here: elastic/package-spec#298 (comment)

@mtojek mtojek self-requested a review August 2, 2022 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants