-
Notifications
You must be signed in to change notification settings - Fork 532
feat: auto-fetch node versions in module extension #3919
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| """Implementation of node SHASUM fetching for facts.""" | ||
|
|
||
| _REPOSITORY_TYPES = { | ||
| "darwin-arm64.tar.gz": "darwin_arm64", | ||
| "darwin-x64.tar.gz": "darwin_amd64", | ||
| "linux-x64.tar.xz": "linux_amd64", | ||
| "linux-arm64.tar.xz": "linux_arm64", | ||
| "linux-s390x.tar.xz": "linux_s390x", | ||
| "win-x64.zip": "windows_amd64", | ||
| "win-arm64.zip": "windows_arm64", | ||
| "linux-ppc64le.tar.xz": "linux_ppc64le", | ||
| } | ||
|
|
||
| def fetch_node_repositories(module_ctx, version): | ||
| """Fetches node repositories for the given node version. | ||
|
|
||
| Port of scripts/update-nodejs-versions.js | ||
|
|
||
| Args: | ||
| module_ctx: Module context | ||
| version: The node version to fetch repositories for. | ||
|
|
||
| Returns: | ||
| A dictionary in the shape of node_repositories. | ||
| """ | ||
|
|
||
| shasums_filename = "{version}-SHASUMS256.txt".format(version = version) | ||
| url = "https://nodejs.org/dist/v{version}/SHASUMS256.txt".format(version = version) | ||
|
|
||
| result = module_ctx.download(url = url, output = shasums_filename) | ||
| if not result.success: | ||
| fail("Failed to fetch node shasums:", url, result, sep = "\n") | ||
|
|
||
| shasums = module_ctx.read(shasums_filename) | ||
|
|
||
| result = {} | ||
|
|
||
| for line in shasums.splitlines(): | ||
| line = line.strip() | ||
| if not line: | ||
| continue | ||
|
|
||
| parts = line.split(" ") | ||
| if len(parts) != 2: | ||
| fail("{url} contains unexpected line:\n{line}".format( | ||
| url = url, | ||
| line = line, | ||
| )) | ||
|
|
||
| sha, filename = parts | ||
| type = _REPOSITORY_TYPES.get(filename.removeprefix("node-v%s-" % version)) | ||
| if not type: | ||
| continue | ||
|
|
||
| strip_prefix = filename.removesuffix(".tar.gz").removesuffix(".tar.xz").removesuffix(".zip") | ||
| result[version + "-" + type] = (filename, strip_prefix, sha) | ||
|
|
||
| return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| """Helper to get node version from user config.""" | ||
|
|
||
| def _verify_version_is_valid(version): | ||
| major, minor, patch = (version.split(".") + [None, None, None])[:3] | ||
| if not major.isdigit() or not minor.isdigit() or not patch.isdigit(): | ||
| fail("Invalid node version: %s" % version) | ||
|
|
||
| def version_from_attr(ctx, attr): | ||
| """Extract the node version from attr. | ||
|
|
||
| Verifies if the extracted version is valid. | ||
|
|
||
| Args: | ||
| ctx: repository or module context | ||
| attr: A struct with fields node_version and node_version_from_nvmrc | ||
|
|
||
| Returns: | ||
| The node version. | ||
| """ | ||
|
|
||
| node_version = attr.node_version | ||
|
|
||
| if attr.node_version_from_nvmrc: | ||
| node_version = str(ctx.read(attr.node_version_from_nvmrc)).strip() | ||
|
|
||
| _verify_version_is_valid(node_version) | ||
|
|
||
| return node_version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.