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

Add support for JSON patches in folder spec files #540

Merged
merged 25 commits into from
Jun 20, 2023

Conversation

mrodm
Copy link
Contributor

@mrodm mrodm commented Jun 14, 2023

What does this PR do?

This PR adds support to define JSON patches at folder specs (spec.yml) files too.
It also ensure that JSON patches are defined in versions key keeping the newer versions on top.

It also removes usages of errors.Wrapf in files under code/go/internal/specschema module.

Why is it important?

This is important to allow us to remove/add/replace files or folders depending on the spec version used by the package.

Checklist

  • I have added test packages to test/packages that prove my change is effective.
    • Add tests in specschema and validator modules
  • I have added an entry in spec/changelog.yml.

Related issues

@mrodm mrodm self-assigned this Jun 14, 2023
@elasticmachine
Copy link

elasticmachine commented Jun 14, 2023

💚 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: 2023-06-19T15:34:57.194+0000

  • Duration: 8 min 3 sec

Test stats 🧪

Test Results
Failed 0
Passed 874
Skipped 0
Total 874

🤖 GitHub comments

Expand to view the GitHub comments

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

  • /test : Re-trigger the build.

@elasticmachine
Copy link

elasticmachine commented Jun 14, 2023

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (8/8) 💚
Files 73.333% (22/30) 👍 4.368
Classes 76.19% (32/42) 👍 3.02
Methods 59.091% (78/132) 👍 2.937
Lines 45.201% (730/1615) 👍 2.172
Conditionals 100.0% (0/0) 💚

mrodm added 3 commits June 15, 2023 11:12
JSON patches need to be defined keeping the patches for newer versions
on top.
Comment on lines +63 to 67

newSpec, err := folderSpec.resolve(l.specVersion)
if err != nil {
return err
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is where JSON patches are read and applied.

@mrodm mrodm marked this pull request as ready for review June 15, 2023 10:12
@mrodm mrodm requested a review from a team as a code owner June 15, 2023 10:12
@mrodm
Copy link
Contributor Author

mrodm commented Jun 15, 2023

test integrations

@elasticmachine
Copy link

Created or updated PR in integrations repostiory to test this vesrion. Check elastic/integrations#6587

jsoriano
jsoriano previously approved these changes Jun 15, 2023
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

👍

return &resolved, nil
}

func (f *folderSchemaSpec) patchForVersion(target semver.Version) ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can move some of this common functionality to a shared package. No need to do it in this PR unless you see it would be straightforward.

Suggested change
func (f *folderSchemaSpec) patchForVersion(target semver.Version) ([]byte, error) {
func PatchForVersion(target semver.Version, versions specpatch.Version) ([]byte, error) {

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 did some refactor to extract that logic and create a new module specpatch.

@mrodm
Copy link
Contributor Author

mrodm commented Jun 15, 2023

test integrations

@mrodm
Copy link
Contributor Author

mrodm commented Jun 15, 2023

test integrations

@mrodm mrodm requested a review from jsoriano June 15, 2023 17:47
@elasticmachine
Copy link

Created or updated PR in integrations repostiory to test this vesrion. Check elastic/integrations#6587

@mrodm
Copy link
Contributor Author

mrodm commented Jun 19, 2023

Failures in the integrations PR elastic/integrations#6587 are not related to any issue with package validation.

@mrodm mrodm mentioned this pull request Jun 19, 2023
2 tasks
@mrodm mrodm merged commit 3995319 into elastic:main Jun 20, 2023
@mrodm mrodm deleted the add_jsonpatch_folderspec branch June 20, 2023 07:38
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