-
Notifications
You must be signed in to change notification settings - Fork 127
Decouple repository root resolver from internal logic #2957
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
base: main
Are you sure you want to change the base?
Conversation
… and update options in rally and stream runners
…factor tests and added readme note
@mrodm i've updated the code with your feedback. i usually mark resolved the comments that have been addressed, please re-open if you find anything pending. thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks great, it seems to solve links resolution and does a good refactor to allow injection of the path to the root repository.
I did some tests and found some issues, commented in the files, though maybe some of them can be solved in follow ups.
Many comments are nitpicking, no need to do anything about them if you prefer current code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried to link a fields file that includes fields with external: ecs
and elastic-package fails to resolve these fields when building the package, with errors like:
Error: building package failed: invalid content found in built zip package: found 7 validation errors:
1. file ".../github.com/elastic/integrations/build/packages/system-2.6.1.zip/data_stream/cpu/fields/agent.yml" is invalid: field cloud.account.id with external key defined ("ecs") but no _dev/build/build.yml found
I guess it is trying to read the build.yml
file from the target directory instead of from the source directory. It only happens with linked files.
Not sure if the issue is introduced with the current PR, so we can handle this in a follow up, as you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you walk me through this test? i am not sure i understood correctly the operation here.
Create a .link file for ecs.yml
of one package ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be reproduced with the following commands, from the integrations repository:
mkdir packages/system/_dev/shared
mv packages/system/data_stream/cpu/fields/agent.yml packages/system/_dev/shared/agent.yml
echo ../../../_dev/shared/agent.yml > packages/system/data_stream/cpu/fields/agent.yml.link
elastic-package links update
elastic-package build -C packages/system
…use value receiver instead of pointer
… handling in tests
…th to PackageRootPath
…and update related tests
💔 Build Failed
Failed CI Steps
History
|
Resolves #2797
This pull request refactors how repository root and links definitions files are discovered and used throughout the codebase, improving consistency, error handling, and test coverage. The main changes include passing the repository root explicitly to functions that need it, updating the logic for finding and reading the links definitions file, and enhancing license file handling during package builds. Comprehensive unit tests have been added for these new behaviors.
Repository root and links file handling:
build
,lint
, and links-related commands incmd/build.go
,cmd/lint.go
,cmd/links.go
) now explicitly locate and pass the repository root usingfiles.FindRepositoryRoot()
, and use this to find the links definitions file viadocs.LinksDefinitionsFilePath(repoRoot)
. This improves reliability and consistency in locating project resources. [1] [2] [3] [4] [5] [6]License file handling during build:
internal/builder/packages.go
now takes the repository root as a parameter and uses it to locate and copy the license file into the package, supporting overrides via environment variable and handling missing files gracefully. The helper functions have been refactored for clarity and improved error handling. [1] [2] [3] [4] [5]Links map logic and API changes:
internal/docs/links_map.go
has been refactored to use pointer receivers, provide clearer error handling, and accept the links file path explicitly. The logic for finding the links definitions file now checks environment variables first and falls back to the default file in the repository root, returning an empty string if not found. [1] [2] [3]Unit tests for new behaviors:
internal/builder/packages_test.go
andinternal/docs/links_map_test.go
cover repository license file discovery, license copying logic, and links file resolution under various scenarios (env var, missing file, default file, YAML parsing). [1] [2]Imports and cleanup: