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

Create Scaladex badge that supplies info on supported Scala versions #660

Merged
merged 4 commits into from
May 11, 2021

Conversation

rtyley
Copy link
Contributor

@rtyley rtyley commented May 3, 2021

Fixes #659 - adding support for a badge that summarises, for a given artifact, which versions of Scala it supports (and what the latest artifact version is for each of those Scala versions).

$ curl --silent -I http://localhost:8080/typelevel/cats/cats-core/latest-by-scala-version.svg | grep Location
Location: https://img.shields.io/badge/cats--core-0.9.0_(Scala_2.12,_2.11,_2.10)-green.svg?

...on my local box (with a minimal Scaladex elasticsearch index) this renders like this Badge

Scala JS & Scala Native

By default, the badge summarises just Scala JVM artifacts, but it's easy to create platform-specific badges by adding targetType=js or targetType=native as a query-string parameter to the url:

$ curl --silent -I http://localhost:8080/typelevel/cats/cats-core/latest-by-scala-version.svg?targetType=js | grep Location
Location: https://img.shields.io/badge/cats--core-0.9.0_(Scala_2.12,_2.11,_2.10_--_Js_0.6)-green.svg?

Refactor & Implementation

This PR is split into 2 commits:

  1. A refactor of ScalaTargetType & ScalaTarget to make grouping by 'platform edition' (eg 'Scala JS 1.x') easier (see commit message for more detail on that), which had the side benefit of reducing existing code duplication. The ScalaTarget classes are still successfully deserialised from Elasticsearch- I haven't modified them to the point of breaking that!
  2. Implementation of the badge, introducing ArtifactScalaVersionSupport to do all the grouping operations to give a concise summary of Scala version support for a given artifact. The accompanying tests in ArtifactScalaVersionSupportTest detail & test some of the desired behaviour of the badge summary text.

cc @adpi2

rtyley added 2 commits May 3, 2021 11:54
The refactor in this commit is driven by the work in the subsequent
commit for issue scalacenter#659 (creating a Scaladex badge that supplies
concise info on supported Scala versions). The key word there is
'concise' - given the many Scala artifacts that can be published for
a single artifact version (the matrix of Scala language version, the
platform - Scala JS/Native/SBT - and the platform version), achieving
a concise summary requires a lot of grouping by those properties.

Grouping by Scala `LanguageVersion` was easy enough, but grouping by
platform & platform version was harder, as there wasn't any existing
class to represent that. Consequently, I introduced the concept of a
'platform edition' (eg 'Scala JS 0.6', or 'Scala Native 0.4'), which
is composed of two values:

* targetType (Scala JS, Scala Native, or SBT)
* platform version (eg the version '0.6' or '1.0' of Scala JS)

...this is like a `ScalaTarget`, but without the Scala Language
version that `ScalaTarget` includes (eg a `ScalaTarget` is
specifically compiled for, eg, _Scala 2.11_ on Scala JS 0.6).

Having introduced the concept of `PlatformEdition`, it made sense to
redefine relevant `ScalaTarget`s in terms of that - to do this meant
moving several ad-hoc methods from the companion objects of
`ScalaTarget` implementations (ie `ScalaJs`, `ScalaNative`,
`SbtPlugin`) to the corresponding `ScalaTargetType` implementations
and making them more widely available, by declaring them in the new
`PlatformVersionedTargetType` trait, removing duplication for this
existing code:

* producing a String `render` value for platform names
* checking validity of platform versions.

As result most of the `ScalaTarget` companion objects were now empty
and could be deleted.

Another smaller change was prompted by the upcoming need to identify
a `ScalaTargetType` by name (when the user specifies it as a query
string parameter). To do that, you need a full list of
`ScalaTargetType`s, and then you can also use that list to create an
`Ordering[ScalaTargetType]`

Also tidied up various tests that were creating their own platform
version constants (as I was already moving equivalent constants from
`ScalaTarget` companion objects to `ScalaTargetType` objects)
Fixes scalacenter#659 - adding
support for a badge that summarises, for a given artifact, which versions
of Scala it supports (and what the latest artifact version is for each
of those Scala versions).


```
$ curl --silent -I http://localhost:8080/typelevel/cats/cats-core/latest-by-scala-version.svg | grep Location
Location: https://img.shields.io/badge/cats--core-0.9.0_(Scala_2.12,_2.11,_2.10)-green.svg?

$ curl --silent -I http://localhost:8080/typelevel/cats/cats-core/latest-by-scala-version.svg?targetType=Js | grep Location
Location: https://img.shields.io/badge/cats--core-0.9.0_(Scala_2.12,_2.11,_2.10_--_Js_0.6)-green.svg?
```
@rtyley
Copy link
Contributor Author

rtyley commented May 10, 2021

Hi there! Is there anything I can do to help with getting this PR merged? If the size of the PR is a blocker I can try removing the refactor in the first commit?

@adpi2
Copy link
Member

adpi2 commented May 10, 2021

Thanks for the reminder @rtyley! I'll do the review today and the refactoring should not be a problem.

Prompted by scalacenter#660 (comment),
this is a testcase for when Scala platform editions are not available for
all cited Scala versions. In this situation, there are a few options for
what the badge text could be:

* Over promise: `7.1.0 (Scala 3.0.0-M3, 2.13 - Native 0.4+0.3)`, which
  incorrectly implies that there's a `3.0.0-M3` version for `Native 0.4`.
* Provide full detail:
  `7.1.0 (Scala 3.0.0-M3 - Native 0.4, Scala 2.13 - Native 0.3)`.
* Omit platform versions that don't have full support for the listed
  Scala language versions: `7.1.0 (Scala 3.0.0-M3, 2.13)`.

The endpoint `latest-by-scala-version.svg`, is intended to list all
supported Scala versions, with the latest artifact version against them,
and giving that information concisely takes priority over providing
completely comprehensive information about the differing versions of the
Scala platforms. It's also best not to over-promise, so of the three
options I think the last is the best.
@adpi2
Copy link
Member

adpi2 commented May 10, 2021

Copy link
Member

@adpi2 adpi2 left a comment

Choose a reason for hiding this comment

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

I think the general idea and the trade-off between conciseness and accuracy of the badges are good. Also the tests are very clear.

I left some comments about the organization of the code.

* Switch from case class to function that encloses intermediate states
* Rename `ArtifactScalaVersionSupport` to `BadgesSupport` as it's only
  used by the `Badges` class

scalacenter#660 (comment)
scalacenter#660 (comment)

I've overloaded the `summaryOfLatestVersions()` method so the tests can
have a version of the method that accepts a
`Map[SemanticVersion, Seq[ScalaTarget]]` - it makes the tests more
concise.
@rtyley
Copy link
Contributor Author

rtyley commented May 10, 2021

Many thanks for the feedback! As suggested, I've removed the ArtifactScalaVersionSupport case class, putting the code into BadgesSupport.summaryOfLatestVersions() with 35c8957.

Copy link
Member

@adpi2 adpi2 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

@adpi2 adpi2 merged commit dc1444e into scalacenter:main May 11, 2021
adpi2 pushed a commit that referenced this pull request May 11, 2021
Prompted by #660 (comment),
this is a testcase for when Scala platform editions are not available for
all cited Scala versions. In this situation, there are a few options for
what the badge text could be:

* Over promise: `7.1.0 (Scala 3.0.0-M3, 2.13 - Native 0.4+0.3)`, which
  incorrectly implies that there's a `3.0.0-M3` version for `Native 0.4`.
* Provide full detail:
  `7.1.0 (Scala 3.0.0-M3 - Native 0.4, Scala 2.13 - Native 0.3)`.
* Omit platform versions that don't have full support for the listed
  Scala language versions: `7.1.0 (Scala 3.0.0-M3, 2.13)`.

The endpoint `latest-by-scala-version.svg`, is intended to list all
supported Scala versions, with the latest artifact version against them,
and giving that information concisely takes priority over providing
completely comprehensive information about the differing versions of the
Scala platforms. It's also best not to over-promise, so of the three
options I think the last is the best.
@adpi2
Copy link
Member

adpi2 commented May 11, 2021

@rtyley
Copy link
Contributor Author

rtyley commented May 11, 2021

Many thanks! I'm post-vaccine today, and so recovering from the common side-effects, but I'm look forward to applying this badge to all my projects! 🎉

@rtyley rtyley deleted the scala-support-badge branch May 11, 2021 09:20
rtyley added a commit to rtyley/scala-git that referenced this pull request May 12, 2021
rtyley added a commit to rtyley/rate-limit-status that referenced this pull request May 12, 2021
rtyley added a commit to rtyley/line-break-preserving-line-splitting that referenced this pull request May 12, 2021
rtyley added a commit to rtyley/scala-collection-plus that referenced this pull request May 12, 2021
rtyley added a commit to rtyley/scala-textmatching that referenced this pull request May 12, 2021
rtyley added a commit to rtyley/scala-io that referenced this pull request May 12, 2021
rtyley added a commit to rtyley/play-git-hub that referenced this pull request May 12, 2021
rtyley added a commit to guardian/play-secret-rotation that referenced this pull request May 18, 2021
rtyley added a commit to guardian/play-secret-rotation that referenced this pull request May 18, 2021
Badge introduced with scalacenter/scaladex#660

A few other documentation tweaks have crept in.
rtyley added a commit to guardian/play-googleauth that referenced this pull request May 19, 2021
rtyley added a commit to rtyley/scaladex that referenced this pull request May 28, 2021
I contributed slightly broken versions of these in
scalacenter#660
rtyley added a commit to rtyley/twitter4s that referenced this pull request Jan 31, 2022
This Scaladex badge summarises which versions of Scala are supported by `twitter4s` (and what the latest `twitter4s` version is for each of those Scala versions), so it provides a bit more information than a Maven badge:

[![twitter4s Scala version support](https://index.scala-lang.org/danielasfregola/twitter4s/twitter4s/latest-by-scala-version.svg)](https://index.scala-lang.org/danielasfregola/twitter4s/twitter4s)

More details on the badge format: scalacenter/scaladex#660
rtyley added a commit to rtyley/sbt-updates that referenced this pull request Feb 11, 2022
The Scaladex badge is a bit more helpful than the Maven Central badge - it summarises which versions of sbt are supported by sbt-updates (and what the latest sbt-updates version is for each of those sbt versions:

[![sbt-updates Scala version support](https://index.scala-lang.org/rtimush/sbt-updates/sbt-updates/latest-by-scala-version.svg?targetType=Sbt)](https://index.scala-lang.org/rtimush/sbt-updates/sbt-updates)

Interestingly, at the moment, there is a new 0.6.2 release of `sbt-updates` for sbt 0.13, but not for 1.0, which wouldn't have been indicated by the old badge!

More details on the badge format here: scalacenter/scaladex#660 (with some extra changes to better support sbt in scalacenter/scaladex#674).
littleRoundaer added a commit to littleRoundaer/sbt-native-packager that referenced this pull request Jul 19, 2022
Unfortunately the Bintray badge on the readme is broken, I guess due to Bintray being [sunset](https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/)? However, this new Scaladex badge can replace the old Bintray badge - it summarises which versions of sbt are supported by sbt-native-packager (and what the latest sbt-native-packager version is for each of those sbt versions):

[![sbt-native-packager Scala version support](https://index.scala-lang.org/sbt/sbt-native-packager/sbt-native-packager/latest-by-scala-version.svg?targetType=Sbt)](https://index.scala-lang.org/sbt/sbt-native-packager/sbt-native-packager)

More details on the badge format here: scalacenter/scaladex#660 (with some extra changes to better support sbt in scalacenter/scaladex#674).
rtyley added a commit to rtyley/scalatra that referenced this pull request Dec 3, 2022
This Scaladex badge summarises which versions of Scala are supported by `scalatra` (and what the latest `scalatra` version is for each of those Scala versions), so it provides a bit more information than a Maven badge:

[![scalatra Scala version support](https://index.scala-lang.org/scalatra/scalatra/scalatra/latest-by-scala-version.svg?platform=jvm)](https://index.scala-lang.org/scalatra/scalatra/scalatra)

More details on the badge format: scalacenter/scaladex#660
magnolia-k pushed a commit to scalatra/scalatra that referenced this pull request Dec 3, 2022
This Scaladex badge summarises which versions of Scala are supported by `scalatra` (and what the latest `scalatra` version is for each of those Scala versions), so it provides a bit more information than a Maven badge:

[![scalatra Scala version support](https://index.scala-lang.org/scalatra/scalatra/scalatra/latest-by-scala-version.svg?platform=jvm)](https://index.scala-lang.org/scalatra/scalatra/scalatra)

More details on the badge format: scalacenter/scaladex#660
rtyley added a commit to guardian/atom-maker that referenced this pull request Dec 8, 2022
This Scaladex badge summarises which versions of Scala are supported by `atom-publisher-lib` (and what the latest `atom-publisher-lib` version is for each of those Scala versions), so it provides a bit more information than a Maven badge:

[![atom-publisher-lib Scala version support](https://index.scala-lang.org/guardian/atom-maker/atom-publisher-lib/latest-by-scala-version.svg?platform=jvm)](https://index.scala-lang.org/guardian/atom-maker/atom-publisher-lib)

More details on the badge format: scalacenter/scaladex#660
magnolia-k pushed a commit to magnolia-k/scalatra that referenced this pull request Dec 22, 2022
…1458)

This Scaladex badge summarises which versions of Scala are supported by `scalatra` (and what the latest `scalatra` version is for each of those Scala versions), so it provides a bit more information than a Maven badge:

[![scalatra Scala version support](https://index.scala-lang.org/scalatra/scalatra/scalatra/latest-by-scala-version.svg?platform=jvm)](https://index.scala-lang.org/scalatra/scalatra/scalatra)

More details on the badge format: scalacenter/scaladex#660
rtyley added a commit to rtyley/ScalaPB that referenced this pull request Apr 11, 2023
This Scaladex badge summarises which versions of Scala are supported by `ScalaPB` (and what the latest `ScalaPB` version is for each of those Scala versions):

[![compilerplugin Scala version support](https://index.scala-lang.org/scalapb/scalapb/compilerplugin/latest-by-scala-version.svg?platform=jvm)](https://index.scala-lang.org/scalapb/scalapb/compilerplugin)

More details on the badge format: scalacenter/scaladex#660
thesamet added a commit to scalapb/ScalaPB that referenced this pull request Apr 11, 2023
Use Scaladex badge on ReadMe to show Scala version support

This Scaladex badge summarises which versions of Scala are supported by `ScalaPB` (and what the latest `ScalaPB` version is for each of those Scala versions):

More details on the badge format: scalacenter/scaladex#660

---------

Co-authored-by: Nadav Samet <thesamet@gmail.com>
rtyley added a commit to rtyley/scaffeine that referenced this pull request May 20, 2023
This Scaladex badge summarises which versions of Scala are supported by `scaffeine` (and what the latest `scaffeine` version is for each of those Scala versions):

[![scaffeine Scala version support](https://index.scala-lang.org/blemale/scaffeine/scaffeine/latest-by-scala-version.svg?platform=jvm)](https://index.scala-lang.org/blemale/scaffeine/scaffeine)

More details on the badge format: scalacenter/scaladex#660
rtyley added a commit to guardian/mobile-apps-api-models that referenced this pull request Jun 29, 2023
This Scaladex badge summarises which versions of Scala are supported by `mobile-apps-api-models` (and what the latest `mobile-apps-api-models` version is for each of those Scala versions):

[![mobile-apps-api-models Scala version support](https://index.scala-lang.org/guardian/mobile-apps-api-models/mobile-apps-api-models/latest-by-scala-version.svg?platform=jvm)](https://index.scala-lang.org/guardian/mobile-apps-api-models/mobile-apps-api-models)

At the moment, `mobile-apps-api-models` only supports Scala 2.12, but when you come to add Scala 2.13 support, the badge will update automatically.

More details on the badge format: scalacenter/scaladex#660
rtyley added a commit to guardian/mobile-apps-api-models that referenced this pull request Jun 29, 2023
This Scaladex badge summarises which versions of Scala are supported by `mobile-apps-api-models` (and what the latest `mobile-apps-api-models` version is for each of those Scala versions):

[![mobile-apps-api-models Scala version support](https://index.scala-lang.org/guardian/mobile-apps-api-models/mobile-apps-api-models/latest-by-scala-version.svg?platform=jvm)](https://index.scala-lang.org/guardian/mobile-apps-api-models/mobile-apps-api-models)

At the moment, `mobile-apps-api-models` only supports Scala 2.12, but when you come to add Scala 2.13 support, the badge will update automatically.

More details on the badge format: scalacenter/scaladex#660
rtyley added a commit to guardian/etag-caching that referenced this pull request Aug 1, 2023
rtyley added a commit to rtyley/scala-collection-compat that referenced this pull request Oct 12, 2023
This Scaladex badge summarises which versions of Scala are supported by `scala-collection-compat` (and what the latest `scala-collection-compat` version is for each of those Scala versions):

[![scala-collection-compat Scala version support](https://index.scala-lang.org/scala/scala-collection-compat/scala-collection-compat/latest-by-scala-version.svg?platform=jvm)](https://index.scala-lang.org/scala/scala-collection-compat/scala-collection-compat)

More details on the badge format: scalacenter/scaladex#660
rtimush pushed a commit to rtyley/sbt-updates that referenced this pull request Nov 14, 2023
The Scaladex badge is a bit more helpful than the Maven Central badge - it summarises which versions of sbt are supported by sbt-updates (and what the latest sbt-updates version is for each of those sbt versions:

[![sbt-updates Scala version support](https://index.scala-lang.org/rtimush/sbt-updates/sbt-updates/latest-by-scala-version.svg?targetType=Sbt)](https://index.scala-lang.org/rtimush/sbt-updates/sbt-updates)

Interestingly, at the moment, there is a new 0.6.2 release of `sbt-updates` for sbt 0.13, but not for 1.0, which wouldn't have been indicated by the old badge!

More details on the badge format here: scalacenter/scaladex#660 (with some extra changes to better support sbt in scalacenter/scaladex#674).
rtyley added a commit to rtyley/scaladex that referenced this pull request Jan 11, 2024
Currently, for the `content-api-firehose-client`, the Scaladex badges page
is showing some contrasting values:

https://index.scala-lang.org/guardian/content-api-firehose-client/badges

* The 'Latest version' badge is showing a good version:
  1.0.12
* The 'JVM badge' (which shows a summary of latest versions by supported
  Scala version, introduced with scalacenter#660)
  is showing an undesireable pre-release version:
  1.0.13-PREVIEW.rt-dbremove-travis-file.2024-01-10T1738.6e259255

You can see both values on the versions page, but only if you tick the
'Show pre-release versions' button:

* https://index.scala-lang.org/guardian/content-api-firehose-client/artifacts/content-api-firehose-client
* https://index.scala-lang.org/guardian/content-api-firehose-client/artifacts/content-api-firehose-client?pre-releases=true#
rtyley added a commit to rtyley/scaladex that referenced this pull request Jan 13, 2024
Currently, for the `content-api-firehose-client`, the Scaladex badges page
is showing some contrasting values:

https://index.scala-lang.org/guardian/content-api-firehose-client/badges

* The 'Latest version' badge is showing a good version:
  1.0.12
* The 'JVM badge' (which shows a summary of latest versions by supported
  Scala version, introduced with scalacenter#660)
  is showing an undesireable pre-release version:
  1.0.13-PREVIEW.rt-dbremove-travis-file.2024-01-10T1738.6e259255

You can see both values on the versions page, but only if you tick the
'Show pre-release versions' button:

* https://index.scala-lang.org/guardian/content-api-firehose-client/artifacts/content-api-firehose-client
* https://index.scala-lang.org/guardian/content-api-firehose-client/artifacts/content-api-firehose-client?pre-releases=true#
rtyley added a commit to rtyley/scaladex that referenced this pull request Jan 13, 2024
Currently, for the `content-api-firehose-client`, the Scaladex badges page
is showing some contrasting values:

https://index.scala-lang.org/guardian/content-api-firehose-client/badges

* The 'Latest version' badge is showing a good version:
  1.0.12
* The 'JVM badge' (which shows a summary of latest versions by supported
  Scala version, introduced with scalacenter#660)
  is showing an undesireable pre-release version:
  1.0.13-PREVIEW.rt-dbremove-travis-file.2024-01-10T1738.6e259255

You can see both values on the versions page, but only if you tick the
'Show pre-release versions' button:

* https://index.scala-lang.org/guardian/content-api-firehose-client/artifacts/content-api-firehose-client
* https://index.scala-lang.org/guardian/content-api-firehose-client/artifacts/content-api-firehose-client?pre-releases=true#

This PR fixes the behaviour on the latest-by-scala-version badge to match the behaviour
of the other badge - it does this with a new PreferReleases ordering for SemanticVersions.
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.

Scaladex badge that supplies info on supported Scala versions
3 participants