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

Add support for structured output from publish goal. #13292

Merged
merged 4 commits into from Oct 22, 2021

Conversation

kaos
Copy link
Member

@kaos kaos commented Oct 19, 2021

This allows publisher plugins to provide additional meta data about what has been published, along with some common default data from the core publish goal rule.

Example output:

$ ./pants publish --output=publish-result.json testprojects/src/python/docker:: 
14:41:46.65 [INFO] Initializing scheduler...
14:41:46.88 [INFO] Scheduler initialized.
14:41:51.98 [INFO] Built docker image: docker.registry.example.net:8181/test-example:1.2.5
The push refers to repository [docker.registry.example.net:8181/test-example]
7c521f914a2d: Layer already exists 
cd61869a0a0d: Layer already exists 
da8ee6936a47: Layer already exists 
6ae392c466cc: Layer already exists 
7fcd2600f5ad: Layer already exists 
8f56c3340629: Layer already exists 
ba6e5ff31f23: Layer already exists 
9f9f651e9303: Layer already exists 
0b3c02b5d746: Layer already exists 
62a747bf1719: Layer already exists 
1.2.5: digest: sha256:961beb6126320d277ad4236f9f12694ad4e077a16f73b896b3292023007a002c size: 2428

✓ docker.registry.example.net:8181/test-example:1.2.5 published.
$ cat publish-result.json 
[
  {
    "exit_code": 0,
    "names": [
      "docker.registry.example.net:8181/test-example:1.2.5"
    ],
    "published": true,
    "publisher": "docker",
    "registries": [
      "docker.registry.example.net:8181"
    ],
    "status": "published",
    "target": "testprojects/src/python/docker:test-example"
  }
]

[ci skip-rust]

[ci skip-build-wheels]
@kaos kaos requested a review from stuhood October 19, 2021 13:29
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Copy link
Sponsor Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Thanks!

# Print structured output to file in requested format, if any.
if publish.output:
with open(publish.output, mode="w") as fd:
json.dump(outputs, fp=fd, cls=_PublishJsonEncoder, indent=2, sort_keys=True)
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Since this is only executed when publish.output is set, and since backends can include arbitrary data, I'm a bit worried that this will bitrot. Is it possible to make the encoded data typesafe? If not, should we unconditionally render the JSON, but only write it if there is a target file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good point. How about always render it, and log it to the pants log (how's that done?) so you can inspect it for debugging purposes..

Copy link
Member Author

Choose a reason for hiding this comment

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

Resorted to simply debug log it for now..

@kaos kaos enabled auto-merge (squash) October 22, 2021 09:33
@kaos kaos merged commit 354a203 into pantsbuild:main Oct 22, 2021
@kaos kaos deleted the publish_output_json branch October 22, 2021 12:37
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

2 participants