Skip to content

Conversation

@aparnajyothi-y
Copy link
Contributor

Description:
This Pull request improves the regex pattern used in the tool-versions file to ensure compatibility with all ASDF versions across the supported distributions. The goal is to provide better flexibility and robustness when parsing tool version entries, handling variations in version formats more effectively.

Related issue:
#719

Check list:

  • [ ✔️] Mark if documentation changes are required.

@aparnajyothi-y aparnajyothi-y requested a review from a team as a code owner March 18, 2025 08:40
@rnorth
Copy link

rnorth commented Jun 11, 2025

@aparnajyothi-y we'd be very excited to see this get released - is there anything we can do to help? (testing?)

It looks like there's currently a check failing but it's apparently hitting a GitHub API rate limit. Presumably unrelated to the actual changes though:

Fetching version info for GraalVM EA builds from 'https://api.github.com/repos/graalvm/oracle-graalvm-ea-builds/contents/versions/24-ea.json?ref=main' failed with the error: API rate limit exceeded for 13.105.117.124. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

@aparnajyothi-y
Copy link
Contributor Author

Hello @rnorth, thank you again for your continued interest and support!

We’ve completed the regex and documentation updates, aiming for broad coverage of the formats in your test suite while clearly documenting known limitations such as jetbrains-21b212.1. As discussed earlier, we’ve prioritized maintainability and clarity over overfitting the regex to rare edge cases.

The recent failures appear to be caused by unauthenticated GitHub API rate limits and are unrelated to the core changes in this PR. That said, we’d greatly appreciate your feedback on whether the updated pattern works well against your test cases.

Please let us know if the current implementation meets your expectations so we can proceed with the review and merging process.

@rnorth
Copy link

rnorth commented Jun 23, 2025

Thanks @aparnajyothi-y

It looks like you've changed the regex a few times over the past few weeks, so I thought I should test it out.

I've tried the updated regex (source link):

/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+){0,2}(?:[+_]\d+)?)(?=(?:[-_](?!\d))|$)(?:[-_.](?:ea|LTS|beta|snapshot|internal|b\d+|\d+[a-z]*))*$/im;

I've tried this with @annettejanewilson's helpful jq command and by hand - unfortunately it seems like it's failing to match things like java temurin-21.0.0+35.0.LTS (or any other Temurin 21 releases).

Temurin is one of the most mainstream distributions, and 21 the most recent LTS version of it - so I'd say this is not just an edge case, but possibly one of the most important distribution versions to be able to match.

There are some other distribution/versions that fail to match that seem highly likely to catch people out:

  • LTS versions of adoptopenjdk
  • Any version of corretto

So I think it's unfortunate but the regex's changes since @annettejanewilson's comments seem to have reduced its coverage. 😬 I don't know the reasons for the changes, but they feel like a regression.

I'm wondering separately: looking at all the src/distributions/*/installer.ts files, it looks like after all this regex work is done there's corresponding code that has to convert the versions back into what seems like the original string from the .tool-versions file. I haven't got time to try it right now but maybe there's an obvious alternative way to approach this: parse the .tool-versions file just enough to get the distribution name, and then give the whole raw version part to the relevant installer.ts *Distribution to find and install. Maybe this should be considered if there are conflicting constraints stopping regex from working...

@aparnajyothi-y
Copy link
Contributor Author

Hello @rnorth, Thanks for the thoughtful suggestion! We agree that splitting regex logic by distribution would improve readability and long-term maintainability. For now, we’ve updated the existing regex to support all known version formats across distributions, which addresses the immediate issue with minimal impact.

We acknowledge that the proposed refactor—maintaining a distribution-specific regex map and cleaner handling is a valuable direction. However, it would require broader testing and prioritization. We’ll consider it for a future iteration as we continue to refine the version resolution logic.
please feel free to reach us in case of any concerns/clarifications needed :)

@aparnajyothi-y
Copy link
Contributor Author

Hello @rnorth, Please validate the above and let us know if you have any issues/clarifications needed.

@rnorth
Copy link

rnorth commented Jul 14, 2025

Thanks @aparnajyothi-y and I'm sorry for being slow to reply.

Yes, I've tried the new regex again with @annettejanewilson's jq command and it looks good to me - very broad coverage of the ASDF versions list. Thanks for your work on this!

Copilot AI review requested due to automatic review settings July 28, 2025 13:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the regex pattern for parsing Java versions from .tool-versions files to improve compatibility with all ASDF versions and handle a wider variety of version formats. The change aims to better support different distribution naming schemes and version patterns.

Key changes:

  • Replaces the existing regex pattern with a more flexible one that can handle complex version strings
  • Adds documentation explaining the limitations and recommendations for version formatting
  • Includes case-insensitive matching for improved parsing

Reviewed Changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/util.ts Updates the regex pattern for parsing Java versions from .tool-versions files to support more ASDF version formats
docs/advanced-usage.md Adds documentation about supported version formats and notes limitations with complex version strings

Comment on lines 135 to +136
javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
Copy link

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

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

The regex pattern is extremely complex and hard to read/maintain. Consider breaking it down into smaller, named components or using multiple regex patterns with clear comments explaining each part's purpose.

Copilot uses AI. Check for mistakes.
@rnorth
Copy link

rnorth commented Sep 15, 2025

I'm itching to see this in a released version - is there an ETA?
Thank you 🙇

@HarithaVattikuti HarithaVattikuti merged commit ead9eaa into actions:main Sep 16, 2025
366 of 367 checks passed
aeharding added a commit to aeharding/voyager that referenced this pull request Nov 9, 2025
mergify bot added a commit to ArcadeData/arcadedb that referenced this pull request Dec 8, 2025
[//]: # (dependabot-start)
⚠️ \*\*Dependabot is rebasing this PR\*\* ⚠️
Rebasing might not happen immediately, so don't worry if this takes some time.
Note: if you make any changes to this PR yourself, they will take precedence over the rebase.
---
[//]: # (dependabot-end)
Bumps [actions/setup-java](https://github.com/actions/setup-java) from 5.0.0 to 5.1.0.
Release notes

*Sourced from [actions/setup-java's releases](https://github.com/actions/setup-java/releases).*

> v5.1.0
> ------
>
> What's Changed
> --------------
>
> ### New Features
>
> * Add support for `.sdkmanrc` file in `java-version-file` parameter by [`@​guicamest`](https://github.com/guicamest) in [actions/setup-java#736](https://redirect.github.com/actions/setup-java/pull/736)
> * Add support for Microsoft OpenJDK 25 builds by [`@​the-mod`](https://github.com/the-mod) in [actions/setup-java#927](https://redirect.github.com/actions/setup-java/pull/927)
>
> ### Bug Fixes & Improvements
>
> * Update Regex to Support All ASDF Versions for the supported distributions in tool-versions File by [`@​aparnajyothi-y`](https://github.com/aparnajyothi-y) in [actions/setup-java#767](https://redirect.github.com/actions/setup-java/pull/767)
> * Enhance error logging for network failures to include endpoint/IP details, add retry mechanism and update workflows to use macos-15-intel by [`@​priya-kinthali`](https://github.com/priya-kinthali) in [actions/setup-java#946](https://redirect.github.com/actions/setup-java/pull/946)
> * Update SapMachine URLs by [`@​RealCLanger`](https://github.com/RealCLanger) in [actions/setup-java#955](https://redirect.github.com/actions/setup-java/pull/955)
> * Add GitHub Token Support for GraalVM and Refactor Code by [`@​mahabaleshwars`](https://github.com/mahabaleshwars) in [actions/setup-java#849](https://redirect.github.com/actions/setup-java/pull/849)
>
> ### Documentation changes
>
> * Update documentation to use checkout and Java v5 by [`@​lmvysakh`](https://github.com/lmvysakh) in [actions/setup-java#903](https://redirect.github.com/actions/setup-java/pull/903)
> * Clarify JAVA\_HOME and PATH setup in README by [`@​chiranjib-swain`](https://github.com/chiranjib-swain) in [actions/setup-java#841](https://redirect.github.com/actions/setup-java/pull/841)
>
> ### Dependency updates
>
> * Upgrade prettier from 2.8.8 to 3.6.2 and document breaking changes in v5 by [`@​dependabot`](https://github.com/dependabot) in [actions/setup-java#873](https://redirect.github.com/actions/setup-java/pull/873)
> * Upgrade actions/publish-action from 0.3.0 to 0.4.0 by [`@​dependabot`](https://github.com/dependabot) in [actions/setup-java#912](https://redirect.github.com/actions/setup-java/pull/912)
>
> New Contributors
> ----------------
>
> * [`@​lmvysakh`](https://github.com/lmvysakh) made their first contribution in [actions/setup-java#903](https://redirect.github.com/actions/setup-java/pull/903)
> * [`@​chiranjib-swain`](https://github.com/chiranjib-swain) made their first contribution in [actions/setup-java#841](https://redirect.github.com/actions/setup-java/pull/841)
> * [`@​the-mod`](https://github.com/the-mod) made their first contribution in [actions/setup-java#927](https://redirect.github.com/actions/setup-java/pull/927)
> * [`@​priya-kinthali`](https://github.com/priya-kinthali) made their first contribution in [actions/setup-java#946](https://redirect.github.com/actions/setup-java/pull/946)
> * [`@​guicamest`](https://github.com/guicamest) made their first contribution in [actions/setup-java#736](https://redirect.github.com/actions/setup-java/pull/736)
>
> **Full Changelog**: <actions/setup-java@v5...v5.1.0>


Commits

* [`f2beeb2`](actions/setup-java@f2beeb2) Bump actions/publish-action from 0.3.0 to 0.4.0 ([#912](https://redirect.github.com/actions/setup-java/issues/912))
* [`4e7e684`](actions/setup-java@4e7e684) feat: Add support for `.sdkmanrc` file in `java-version-file` parameter ([#736](https://redirect.github.com/actions/setup-java/issues/736))
* [`46c56d6`](actions/setup-java@46c56d6) Add GitHub Token Support for GraalVM and Refactor Code ([#849](https://redirect.github.com/actions/setup-java/issues/849))
* [`66b9457`](actions/setup-java@66b9457) Update SapMachine URLs ([#955](https://redirect.github.com/actions/setup-java/issues/955))
* [`6ba5449`](actions/setup-java@6ba5449) Enhance error logging for network failures to include endpoint/IP details, ad...
* [`de5a937`](actions/setup-java@de5a937) adds microsoft openjdk25 builds ([#927](https://redirect.github.com/actions/setup-java/issues/927))
* [`ead9eaa`](actions/setup-java@ead9eaa) Update Regex to Support All ASDF Versions for the supported distributions in ...
* [`8c57fa3`](actions/setup-java@8c57fa3) Clarify JAVA\_HOME and PATH setup in README ([#841](https://redirect.github.com/actions/setup-java/issues/841))
* [`a7ab372`](actions/setup-java@a7ab372) Bump prettier from 2.8.8 to 3.6.2 ([#873](https://redirect.github.com/actions/setup-java/issues/873))
* [`d0351b4`](actions/setup-java@d0351b4) Update documentation to use checkout and Java v5 ([#903](https://redirect.github.com/actions/setup-java/issues/903))
* See full diff in [compare view](actions/setup-java@dded088...f2beeb2)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=actions/setup-java&package-manager=github\_actions&previous-version=5.0.0&new-version=5.1.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
Dependabot commands and options
  
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show  ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
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.

6 participants