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

Added .tool-versions file support #606

Merged

Conversation

mahabaleshwars
Copy link
Contributor

@mahabaleshwars mahabaleshwars commented Mar 4, 2024

Description:
Add support for getting version from tool-versions file

Related issue:
#579

Check list:

  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.

@mahabaleshwars mahabaleshwars requested a review from a team as a code owner March 4, 2024 08:46
@mahabaleshwars mahabaleshwars changed the title Added tool version file support Added .tool-versions file support Mar 4, 2024
@mahabaleshwars mahabaleshwars self-assigned this Mar 12, 2024
@HarithaVattikuti HarithaVattikuti merged commit 5896cec into actions:main Mar 12, 2024
301 checks passed
@mahabaleshwars mahabaleshwars mentioned this pull request Mar 14, 2024
2 tasks
github-merge-queue bot pushed a commit to AmadeusITGroup/otter that referenced this pull request Mar 14, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change | Age | Adoption | Passing |
Confidence |
|---|---|---|---|---|---|---|---|
| [actions/setup-java](https://togithub.com/actions/setup-java) | action
| minor | `v4.1.0` -> `v4.2.0` |
[![age](https://developer.mend.io/api/mc/badges/age/github-tags/actions%2fsetup-java/v4.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/github-tags/actions%2fsetup-java/v4.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/github-tags/actions%2fsetup-java/v4.1.0/v4.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/github-tags/actions%2fsetup-java/v4.1.0/v4.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [sass](https://togithub.com/sass/dart-sass) | peerDependencies | minor
| [`~1.71.0` ->
`~1.72.0`](https://renovatebot.com/diffs/npm/sass/1.71.1/1.72.0) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/sass/1.72.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/sass/1.72.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/sass/1.71.1/1.72.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/sass/1.71.1/1.72.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [sass](https://togithub.com/sass/dart-sass) | devDependencies | minor
| [`~1.71.0` ->
`~1.72.0`](https://renovatebot.com/diffs/npm/sass/1.71.1/1.72.0) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/sass/1.72.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/sass/1.72.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/sass/1.71.1/1.72.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/sass/1.71.1/1.72.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>actions/setup-java (actions/setup-java)</summary>

###
[`v4.2.0`](https://togithub.com/actions/setup-java/releases/tag/v4.2.0)

[Compare
Source](https://togithub.com/actions/setup-java/compare/v4.1.0...v4.2.0)

#### What's Changed

- Updated actions/httpclient version to 2.2.1 and other dependencies by
[@&#8203;HarithaVattikuti](https://togithub.com/HarithaVattikuti) in
[actions/setup-java#607
- Added .tool-versions file support along with .java-version file by
[@&#8203;mahabaleshwars](https://togithub.com/mahabaleshwars) in
[actions/setup-java#606

#### New Contributors

- [@&#8203;HarithaVattikuti](https://togithub.com/HarithaVattikuti) made
their first contribution in
[actions/setup-java#607
**Full Changelog**:
actions/setup-java@v4...v4.2.0

</details>

<details>
<summary>sass/dart-sass (sass)</summary>

###
[`v1.72.0`](https://togithub.com/sass/dart-sass/blob/HEAD/CHANGELOG.md#1720)

[Compare
Source](https://togithub.com/sass/dart-sass/compare/1.71.1...1.72.0)

- Support adjacent `/`s without whitespace in between when parsing plain
CSS
    expressions.

- Allow the Node.js `pkg:` importer to load Sass stylesheets for
`package.json`
    `exports` field entries without extensions.

- When printing suggestions for variables, use underscores in variable
names
    when the original usage used underscores.

##### JavaScript API

- Properly resolve `pkg:` imports with the Node.js package importer when
    arguments are passed to the JavaScript process.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 10pm every weekday,before 5am
every weekday,every weekend" in timezone Europe/Paris, Automerge - At
any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/AmadeusITGroup/otter).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMzguMSIsInVwZGF0ZWRJblZlciI6IjM3LjIzOC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
rtyley added a commit to guardian/etag-caching that referenced this pull request Mar 14, 2024
This is motivated by guardian/gha-scala-library-release-workflow#31 -
initially I was just thinking about updating to Java 21, but now I think
that making projects declare which Java version they use to build is
probably a good thing!

Note that we're using asdf's .tool-versions file here, which has recently gained
support in actions/setup-java#606 - this means that
we can also get _all_ our GitHub Actions files to respect the Java version
definied in that file - eg, we can reference it in ci.yml, and we don't need
to update Java version in there anymore.
let javaVersionRegExp;
if (versionFile == '.tool-versions') {
javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
Copy link

@rtyley rtyley Mar 14, 2024

Choose a reason for hiding this comment

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

Note that this regex will not accept full java versions commonly generated in asdf using latest - eg:

asdf local java latest:corretto-21

...will generate a file with this line:

java corretto-21.0.2.13.1

The regex doesn't recognise this, so setup-java will fail with this message:

Error: No supported version was found in file .tool-versions

If we play around with the regex, we can see that we have to edit the string down to java corretto-21.0.2 in order to get it to work:

image

Shegox pushed a commit to Shegox/setup-java that referenced this pull request Mar 26, 2024
* added support for tool version file

* testing with one regex

* working regex

* Checked for the file extension

* added e2e checks for tool version

* removed error warning

* updated regex to support early version

* updated regex for early version support

* updated regex for early version

* updated regex to accept early versions

* added coreinfo to analyze

* updated the regex

* updated regex

* new regex for early version

* updated regex to match the new version file format

* new regex

* changed the regex

* redex updated

* used java version regex

* regex updated

* regex modified

* regex updated

* regex updated

* regex updated

* updated regex to support early versions

* Regex updated to support all java versions

* Documentation updated to add tool version description

* Documentation updated for the tool version file

* update the advanced doc and readme file to specify tool version changes
Valid entry options:
```
major versions: 8, 11, 16, 17, 21
more specific versions: 1.8.0.2, 17.0, 11.0, 11.0.4, 8.0.232, 8.0.282+8
early access (EA) versions: 15-ea, 15.0.0-ea, 15.0.0-ea.2, 15.0.0+2-ea

Choose a reason for hiding this comment

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

15.0.2-sa.2, 15.2.0+2-sa

rtyley added a commit to guardian/gha-scala-library-release-workflow that referenced this pull request Apr 30, 2024
This allows projects to specify, with an `asdf` (https://asdf-vm.com/)-formatted
`.tool-versions` file, the Java version to be used by the workflow for building
the project- `gha-scala-library-release-workflow` has always used a recent LTS
version Java for the build (eg Java 17), and this has sometimes been _too recent_
(guardian/atom-maker#94) for some projects at the Guardian.

We _want_ projects to update to Java 21 (see guardian/support-frontend#5792,
guardian/scala-steward-public-repos#67 etc), but tying
dozens of projects tightly to what `gha-scala-library-release-workflow` is using
will make updating that version pretty hard. If, at some later point, _some_ projects
want to experiment with Java 25, we shouldn't have to force all other projects to
be compatible with that first.

## How to express the version of Java required...

### Configuration proliferation is a problem...

One option would have been to simply add a new input parameter to the workflow,
specifying the required Java version, but that has a downside: it proliferates the
number of places in a project where the desired Java version is declared - and there
are many in use at the Guardian, with no well-agreed canonical source-of-truth:

* GHA `ci.yml`, in the [`java-version`](https://github.com/guardian/etag-caching/blob/7ecc04981f5a42a0f2ecb10631f28da571a49836/.github/workflows/ci.yml#L22) field of `actions/setup-java` - this has been my favourite in the past, as whatever CI runs with is usually pretty close to the truth
* In sbt, the `scalacOptions` of `-target`, `-release`, `-java-output-version` (currently `-release` preferred, tho' once [support](scala/scala#10654) is pervasive, `-java-output-version` is probably best) and the `javacOptions` of `-target` & `-source` - these all effectively set lower-bounds on the version of Java supported, rather than guaranteeing a minimum upper bound of Java version the way CI does.
* In apps running on Amigo AMI images; the Java version baked into the AMI, usually [referenced](https://github.com/guardian/mobile-apps-api/blob/3231e6bf064163c6d0e72c8dc862678c68eb0b62/mobile-fronts/conf/riff-raff.yaml#L10) by `riff-raff.yaml`
* In AWS Lambdas; the cloudformation [`Runtime`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-runtime) parameter, often set [by CDK](https://github.com/guardian/mobile-save-for-later/blob/1ac12e4c0100edb976ebae9e2a9975ad2321e26e/cdk/lib/mobile-save-for-later.ts#L44)

### ...`asdf`'s `.tool-versions` flle offers some consolidation

Benefits of using `.tool-versions`:

* Developers will automatically get the right Java version if they have `asdf` installed
* actions/setup-java#606 has added early support for reading the version of Java used in CI by `setup-java` from the `.tool-versions` flle - unfortunately, it's of limited use to us at the moment because of actions/setup-java#615, but it's a promising start _(`setup-java` also has support for `jEnv` files, but they are not commonly used at the Guardian)_
* Format of the file is simple enough that it can be easily understood and used, even if `asdf` is not in use - **including the file doesn't _force_ developers to use `asdf`** (I know some devs have been having some problems with it, and maybe there are/will be better alternatives out there), but it clearly documents the Java version to be used.

This does mean that **all library repos need to add a `.tool-versions` file** before this PR is merged. Helpful error messaging has been added with this PR to handle cases where the file is missing or invalid:

#### Only Java _major_ version is guaranteed

Note that although `asdf` requires a fully-specified Java version (eg `21.0.3.9.1`) in the `.tool-versions` file, currently the workflow will only match the *major* version of Java specified in the file (eg `21`), and will _always_ use the AWS Corretto distribution of Java. This is due to [limitations](actions/setup-java#615) in [`actions/setup-java`](https://github.com/actions/setup-java).
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.

None yet

7 participants