Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

cmd/cue: add diff support #8

Closed
mpvl opened this issue Jan 30, 2019 · 8 comments
Closed

cmd/cue: add diff support #8

mpvl opened this issue Jan 30, 2019 · 8 comments
Labels
FeatureRequest New feature or request roadmap/cli Specific tag for roadmap issue #337
Milestone

Comments

@mpvl
Copy link
Contributor

mpvl commented Jan 30, 2019

Allow diffing between (snapshots of) previous version and current version.

@mpvl mpvl added the FeatureRequest New feature or request label Apr 8, 2019
@mpvl mpvl added this to the v0.0.1 milestone Apr 27, 2019
@mpvl mpvl modified the milestones: v0.0.1, v0.2.0 Jun 22, 2019
@jugaadi
Copy link

jugaadi commented Sep 4, 2019

Any updates on this feature?

@mpvl mpvl added the roadmap/cli Specific tag for roadmap issue #337 label Dec 1, 2019
@mpvl mpvl modified the milestones: v0.3.0-evaluator-rewrite, v0.3.1 Dec 31, 2020
@mpvl
Copy link
Contributor Author

mpvl commented Feb 17, 2021

It would be good for people to give examples of how they would like to use this functionality in a CLI.
There is an internal package for diffing CUE, which could potentially also be exposed as a Go API.

@myitcv
Copy link
Contributor

myitcv commented Mar 15, 2021

Commenting simply to add the word semantic into the mix 😄

I've taken (perhaps incorrectly) to referring to cue diff as a semantic diff, distinct from cmp and friends ("plain diff") used in unity.

@eonpatapon
Copy link
Contributor

Would be nice to have a diff API in cue lib. Currently I'm using Value.Decode and https://github.com/r3labs/diff to diff two cue instances in order to detect which part of the configuration has changed (based on this CI jobs are run).

However this works if the instances have only concrete values. So a similar API that can diff cue values directly would be nice (and required in my case to be able to use the flow API)

@myitcv
Copy link
Contributor

myitcv commented Mar 20, 2021

@eonpatapon take a look at https://pkg.go.dev/cuelang.org/go@v0.3.0-beta.6.0.20210312201910-7c5d28e6721a/internal/diff. That is internal for now, but as we shape up the API it should be made non-internal.

@vikstrous2
Copy link

A semantic diff would be really interesting. I think with diffing kubernetes files, the most awkward part is the way that the kubernetes API wants to be given a list of yaml objects but the identity of those objects is usually best defined by their name rather than their position in a list. My current idea for diffing them is to write them out into a directory tree where the name of the file is based on the name and type of the object and then using git diff. Then as long as the yaml and all of its fields and lists of named objects are sorted in some stable way, this is good enough for most kubernetes things.

@myitcv
Copy link
Contributor

myitcv commented May 3, 2021

Adding something of an experience report here from the world of unity.

unity tests (of cmd/cue) generally follow this rough pattern:

  1. Ensure that evaluation of a given configuration semantically matches expectations. This is, in effect, a CUE semantic diff
  2. Verify that output in a specific format (JSON, Yaml, etc) matches expectations. This is, in effect, a semantic diff in the output format

In the case of point one this will look like:

# CUE semantic diff
cue eval -o out.cue X
cue diff out.cue ref.cue

# JSON diff
cue eval -o out.json X
cue diff out.json ref.json

Some questions:

  • Is cue eval the right command here? cue eval will become cue - but does that give the intended result, as far as concreteness etc are concerned?
  • file.ref will need to be a complete, self-contained configuration. This might well require it to be a txtar archive?

Stepping back a bit further, we should also be able to write a semantic diff for point 2, on the basis that CUE knows about the semantics of these different formats (even to some extent the different versions of, say, Yaml, JSON).

@cueckoo
Copy link

cueckoo commented Jul 3, 2021

This issue has been migrated to cue-lang/cue#8.

For more details about CUE's migration to a new home, please see cue-lang/cue#1078.

@cueckoo cueckoo closed this as completed Jul 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest New feature or request roadmap/cli Specific tag for roadmap issue #337
Projects
None yet
Development

No branches or pull requests

6 participants