apple / swift-docc

Documentation compiler that produces rich API reference documentation and interactive tutorials for your Swift framework or package.
https://swift.org/documentation/docc
Apache License 2.0
1.14k stars 118 forks source link

[external-links] Display frameworks as beta only if all platforms are beta #938

Closed anferbui closed 2 weeks ago

anferbui commented 4 weeks ago

Bug/issue #, if applicable: rdar://128997995

Summary

Symbols can have an availability per platform (iOS, macOS, etc), each of which can be marked as "beta" by providing some metadata when invoking docc:

swift run docc preview preview TestPackage.docc --platform name=macOS,version=40.0.0,beta=true --platform name=iOS,version=50.0.0,beta=true --platform name=watchOS,version=60.0.0,beta=true
Screenshot 2024-06-04 at 16 02 34

A top-level badge is sometimes rendered for a symbol, depending on its platform availability.

Currently there is a mismatch in behaviour where:

This behaviour is inconsistent and can be confusing for documentation writers. This PR proposes unifying the behaviour so that a symbol is shown as beta if all of its available platforms are in beta.

Implementation

Changes the behaviour of external link resolution in OutOfProcessReferenceResolver to only display a framework to be in beta if all the platforms its supported in are in beta.

This makes it match the behaviour for internal link resolution, so that the behaviour is consistent whether you're linking to a symbol internally within a framework or externally from another framework.

Also modifies LinkDestinationSummary to keep both of the external symbol resolution code paths in sync with each other. Hopefully in the future we can unify and have the same code path for both, but right now the logic is duplicated (and equal).

Dependencies

N/A.

Testing

You can set up a link resolver locally which has beta platform information in order to verify this fix: link-resolver.zip

Excerpt:

"platforms": [
    {
      "name": "macOS",
      "introducedAt": "40.0.0",
      "beta": true
    },
    {
      "introducedAt": "50.0.0",
      "beta": true,
      "name": "iOS"
    },
    {
      "introducedAt": "60.0.0",
      "beta": false,
      "name": "watchOS"
    }
  ]

TestPackage.zip

Steps:

  1. Download link-resolver and TestPackage.
  2. Render documentation locally:
    DOCC_LINK_RESOLVER_EXECUTABLE=link-resolver swift run docc preview TestPackage.docc --platform name=macOS,version=40.0.0,beta=true --platform name=iOS,version=50.0.0,beta=true
  3. Verify that in http://localhost:8080/documentation/testpackage/betaclass, neither of the symbols mentioned have a top level badge that says the symbol is a beta symbol.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

Verification

Unit tests

Added unit tests for OutOfProcessReferenceResolver and ExternalPathHierarchyResolver since these changes affect both types of external link resolution.

Ran ./bin/test:

❯ ./bin/test
Building for debugging...
[122/122] Linking SwiftDocCPackageTests
Build complete! (7.75s)
[1685/1685] Testing SwiftDocCUtilitiesTests.DirectoryMonitorTests/testMonitorDoesNotTriggerUpdates
=> Checking for unacceptable language… okay.
=> Checking license headers… okay.
=> Validating scripts in bin subdirectory… okay.

Site rendering

Before After
Screenshot 2024-06-04 at 16 31 53 Screenshot 2024-06-04 at 16 31 13

Documentation

As far as I can tell, no changes to the documentation are needed.

anferbui commented 3 weeks ago

@swift-ci please test

anferbui commented 2 weeks ago

@swift-ci please test