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

CI check for Standard.Base API changes via snapshotting #10507

Open
Akirathan opened this issue Jul 10, 2024 · 11 comments
Open

CI check for Standard.Base API changes via snapshotting #10507

Akirathan opened this issue Jul 10, 2024 · 11 comments
Assignees
Labels
-compiler -libs Libraries: New libraries to be implemented -syntax -tooling Category: tooling p-high Should be completed in the next sprint x-new-feature Type: new feature request

Comments

@Akirathan
Copy link
Member

Akirathan commented Jul 10, 2024

Stability of Enso APIs, encapsulation of internals, detection of accidental API changes are of great value for Enso customers. Helping Enso runtime developers keeping these values is of high priority.

There have been two recent developments demonstrating how easy API snapshotting is and how it can be used in tests to ensure stability of API of a single module. The goal of this PR is to scale this up and apply such an API snapshotting to the whole Standard.Base and its APIs.

Steps

First of all we need to do few manual steps to prepare the infrastructure:

Generate API Snapshot

Executing following command:

sbt:enso> runEngineDistribution --docs=api --in-project distribution/lib/Standard/Base/0.0.0-dev/

generates distribution/lib/Standard/Base/0.0.0-dev/docs/api/ directory with a lot of API signatures of publicly accessible modules.

Store in Version Control

Let's put the current snapshot under version control:

enso$ git add distribution/lib/Standard/Base/0.0.0-dev/docs/
enso$ git commit -m "Initial snapshot of Standard.Base APIs"
The CI Check

Now we need to modify the CI to perform the check. E.g. to execute:

sbt:enso> runEngineDistribution --docs=api --in-project distribution/lib/Standard/Base/0.0.0-dev/
enso$ git diff --exit-code distribution/lib/Standard/Base/0.0.0-dev/docs/api/

The first command re-generates the Standard.Base API snapshot according to latest state of the .enso code. The second command checks for any differences. It succeeds if there are no differences. It fails with exit code 1 when any differences is found. In such case let us fail the CI build.

CI Failed. What Shall I do Now?

Once the above is implemented, we are likely to see the CI check to fail. Failing is good! Failure of this check means: we have discovered an unintended API change. Unintended API changes are bad. Thus detecting them is good!

Anyway, we need to fix the CI to be green. Here are the tips:

  1. don't do the API change.
  2. add private to the top of the .enso file containing the change
  3. mark the method private
  4. if you really wish to make an API change, turn it into intentional API change
Intentional API Change

When an API change is intended, it is not only changing the .enso code, but it is also updating the API snapshot. The simplest way to update the API snapshot is to regenerate it:

sbt:enso> runEngineDistribution --docs=api --in-project distribution/lib/Standard/Base/0.0.0-dev/

then review the changes via git diff and if they seem OK, integrate them into your PR.

Prior Work

Inspiration from NetBeans:

@Akirathan Akirathan added p-medium Should be completed in the next few sprints x-new-feature Type: new feature request -compiler -syntax -libs Libraries: New libraries to be implemented labels Jul 10, 2024
@JaroslavTulach JaroslavTulach added the -tooling Category: tooling label Jul 10, 2024
@JaroslavTulach
Copy link
Member

Prepare a design for review, Pavel.

@JaroslavTulach JaroslavTulach moved this from ❓New to 📤 Backlog in Issues Board Jul 16, 2024
@Akirathan
Copy link
Member Author

As part of library compilation, we already generate cached Suggestions. They are later sent to the IDE in JSON format. The sigfile can thus be a JSON-formatted .suggestions. Implementation-wise this should be the most straightforward approach. Moreover, for the backward compatibility, suggestions are what we should care about the most.

@JaroslavTulach
Copy link
Member

The sigfile can thus be a JSON-formatted .suggestions.

CCing @4e6 and @hubertp

@JaroslavTulach
Copy link
Member

JaroslavTulach commented Jan 15, 2025

The output format could be a simplified .md file:

- type `File_By_Line`
    - `new` `file:File` `encoding:Encoding=` `offset:Integer=`
    - `Reader` `file:File` `encoding:Encoding` `limit_lines:(Integer|Nothing)` `filter_func` `row_map` `file_end=`
    - ...
- `read_line` `file:File_By_Line line:Integer=` `~default=`

with such an infrastructure we would then:

  • put the files for each library under version control
  • create a CI job to regenerate the files
  • fail the build whenever there is any change in files
  • forcing human to regenerate the files and commit then
  • to avoid unwanted API changes in our libraries

@JaroslavTulach JaroslavTulach changed the title Automatic check of API backward compatibility CI check for API snapsnot changes Jan 21, 2025
@JaroslavTulach JaroslavTulach changed the title CI check for API snapsnot changes CI check for Standard.Base API changes via snapshotting Jan 21, 2025
@JaroslavTulach JaroslavTulach added p-high Should be completed in the next sprint and removed p-medium Should be completed in the next few sprints labels Jan 21, 2025
@Akirathan
Copy link
Member Author

Reordering methods/types in a module is not an API change. That is why the API signature generator should sort the markdown file. That will not only fix this case, but also provide better readability. We just have to stick to a certain ordering convention.

@Akirathan
Copy link
Member Author

Using git diff to check for change of the API is not a good idea. If a new file was added, git diff will not discover it, because it is still untracked. We should rather output the API signatures in a different directory and then use simple diff program.

@enso-bot
Copy link

enso-bot bot commented Jan 28, 2025

Pavel Marek reports a new STANDUP for yesterday (2025-01-27):

Progress: - Started to work on #10507

  • Added tests for the visitation order of IR elements in a module by the Documentation visitor.
  • finally merged Dump compiler IR to IGV #12061 after many Windows job restarts It should be finished by 2025-02-04.

@Akirathan
Copy link
Member Author

Important note to remember for some follow-up PRs: Exports should be part of the API.

@Akirathan
Copy link
Member Author

There should be no API file generated for synthetical and empty modules. In other words, there should be no empty .md files (files with just title and no content).

@enso-bot
Copy link

enso-bot bot commented Jan 29, 2025

Pavel Marek reports a new STANDUP for today (2025-01-29):

Progress: - The preparation PR for the CI job is ready to review: #12175 It should be finished by 2025-02-04.

@enso-bot
Copy link

enso-bot bot commented Jan 31, 2025

Pavel Marek reports a new STANDUP for today (2025-01-31):

Progress: - Generated API signatures in - #12203

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-compiler -libs Libraries: New libraries to be implemented -syntax -tooling Category: tooling p-high Should be completed in the next sprint x-new-feature Type: new feature request
Projects
Status: 📤 Backlog
Development

No branches or pull requests

2 participants