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

feat: first implementation of cdevents-sdk from json-schema #8

Merged
merged 34 commits into from
Feb 1, 2024

Conversation

davidB
Copy link
Collaborator

@davidB davidB commented Jan 10, 2024

This PR is a WIP and a proposal implementation to have cdevents sdk for rust.

The PR contains:

  • typed struct for part of subject than json::Value (nearly any json type) or String without constraint
  • feedback from review
  • test: read and write examples from spec
  • enforce context.type to match the subject's type
  • cloudevents integration
  • CI (can be view in action at https://github.com/davidB/cdevents-sdk-rust/actions)
  • use enums, instead of string for field defined as enum in schema
  • test: generate random events and check against json schema

POSTPONED to another PR

  • documentation: Development, TODO, README (like other sdk)
  • test: setter/getter

I have a few other ideas, but after this PR

I need the rust sdk to continue my wip on davidB/cdviz: View software deployment's events & states

Let me know if I'm on the wrong path or if I should publish this library on my side.

PS: for the review, under the cdevents/src/generated folder, you can overlook just a few files. The generated folder is committed because rust crates are distributed as source, and I don't expect the user to build the generator and generate cdevents from git cloned spec before compiling the lib.

@afrittoli
Copy link
Contributor

Hello @davidB, and thank you for your PR!
I see this is marked as draft - please let us know when this is ready for review.
I'm very new to rust but I'll do my best to review.

@rjtch has been working on the rust SDK a bit, so it would be great if the two of you could collaborate on the rust SDK.

FYI - we have public weekly CDEvents working group meetings (see https://github.com/cdevents/community?tab=readme-ov-file#how-to-get-involved) - if the time is convenient you're very welcome to join the meeting to discuss the rust SDK or any other topic around CDEvents.

@afrittoli
Copy link
Contributor

@mlieberman85 FYI - in case you are interested in reviewing / contributing or even simply watching

@davidB
Copy link
Collaborator Author

davidB commented Jan 14, 2024

@afrittoli Thank you, that motivate me to continue (I guess reviewer will be afraid by the volume of change in the PR, Sorry)

Before I start this PR, I looked at how to contact the community, but the slack channel is restricted to some email host, and I have a conflict on my agenda with the weekly meeting (and my contribution is out of working hours/resources).

@mlieberman85
Copy link

I'm just watching this. I'm interested in replacing my generated structs here: https://github.com/kusaridev/skootrs/blob/main/src/model/cd_events/repo_created.rs that was made using a tool I wrote that calls out to https://github.com/oxidecomputer/typify, with something supported by the broader CD events community.

@rjtch
Copy link
Contributor

rjtch commented Jan 15, 2024

@afrittoli Thank you, that motivate me to continue (I guess reviewer will be afraid by the volume of change in the PR, Sorry)

Before I start this PR, I looked at how to contact the community, but the slack channel is restricted to some email host, and I have a conflict on my agenda with the weekly meeting (and my contribution is out of working hours/resources).

Hey David, I can write you on slack if you want and we could work on this together. The community meeting is also conflicting with my agenda. I will contact you on slack.

@afrittoli
Copy link
Contributor

@afrittoli Thank you, that motivate me to continue (I guess reviewer will be afraid by the volume of change in the PR, Sorry)

Before I start this PR, I looked at how to contact the community, but the slack channel is restricted to some email host, and I have a conflict on my agenda with the weekly meeting (and my contribution is out of working hours/resources).

Thanks David! Async collaboration is perfectly fine.
It would be good for you to join the slack nonetheless, it you don't mind could you try this link and let me know if it works? If not we'll need to have it fixed.

@davidB
Copy link
Collaborator Author

davidB commented Jan 15, 2024

I'm on the slack workspace of the CD Foundation.
Thank you.

@rjtch
Copy link
Contributor

rjtch commented Jan 15, 2024

I'm on the slack workspace of the CD Foundation. Thank you.

you can also join the #cdevents and the #general channels.

@davidB
Copy link
Collaborator Author

davidB commented Jan 18, 2024

@afrittoli , @rjtch,
because there was no ci, lint when I forked the repository, I included it as part of this PR. And it will conflict with the stuff you are pushing.
The PR is in draft because it is not full (from the checklist), but you can look at it. So I can start to integrate your feedback or prepare for the coming discussion.

@davidB davidB marked this pull request as ready for review January 21, 2024 22:07
@davidB
Copy link
Collaborator Author

davidB commented Jan 21, 2024

@afrittoli , @rjtch,

You can start the review; missing parts could added via the next PRs (smaller and more focused). Sorry for this too-big PR.

Maybe the next commits in this PR will be comments and documentation to explain some choices.

PS: I don't have permission to assign you as a reviewer, so I am notifying you via comment.

# (not recommended if you don't pay for GH Actions)
push:

# pull_request:
Copy link
Contributor

Choose a reason for hiding this comment

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

We should actually run on pull requests against main, to avoid new PRs breaking CI

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

with this configuration, it runs against every push (on every branch/pr). I can enable it for pull_request instead of push. But enabling both generates dual (overkill and sometimes conflicting) workflow.

Copy link
Contributor

Choose a reason for hiding this comment

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

The usual workflow is to push to a fork and create a PR from that. I may be wrong but I don't think that push to a fork would trigger the workflow on this repo.

The setup I usually use it pull_request only on main. If we at some point add branches to maintain specific releases we can extend the config from main only to whatever name pattern we have for release branches.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I made the change, but it will be visible into the coming PR with merged CI,...

.github/dependabot.yml Outdated Show resolved Hide resolved
.editorconfig Outdated Show resolved Hide resolved
with:
fetch-depth: 0
submodules: "true"
- uses: jdx/rtx-action@v1
Copy link
Contributor

Choose a reason for hiding this comment

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

The repo is archived, so maybe not a good candidate? https://github.com/jdx/rtx-action

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll check why he archive few days ago, maybe because the action could be replaced by 3 line of shell call.

rtx is simple and very useful tool (at least for me, when I have to switch between multiple project with various version of java, python, rust, node...)

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it's related to the rename rtx -> mise? https://dev.to/jdxcode/beginners-guide-to-rtx-ac4
I can see how rtx is very handy for the development environment on your laptop, but do we need it in CI jobs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In my team, we found it useful to have the ci and local environment in sync.
I'll also a believer of "portable" CI, I mean every dev should be able to do the same as CI (if enough permission on third party system) or CI should just be like a developper that do every steps. So more the CI use same tooling than dev, better it is and less we are coupled to a CI system (trauma from migration between travis, azure pipeline, github-action, and hell of commit to debug/setup CI workflow special command).

And in the case of rtx+justfile/Makefile, it also provide a similar CI flow for various ecosystem.

Copy link
Collaborator Author

@davidB davidB Jan 23, 2024

Choose a reason for hiding this comment

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

Yes you're right it's due to rename ofrtx to mise https://mise.jdx.dev/rtx.html + some nice new feature.

Copy link
Contributor

Choose a reason for hiding this comment

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

@davidB i found mise also it is a good tool! the linter works now fine i think we could integrate mise in a next pr.

justfile Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have a Makefile, so we should probably use that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the Makefile didn't exist when I forked. I'll try to convert the justfile into Makefile.

.gitmodules Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
@davidB
Copy link
Collaborator Author

davidB commented Jan 22, 2024

Thanks for the review, I'll try to do the change ASAP (maybe tomorrow).

Cargo.toml Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@afrittoli afrittoli 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 this, I started reviewing but it will take me a bit of extra time as I'm rather new to rust 🙏
That said, I don't want to slow down progress here, so if you feel confident this is a good way forward I'm happy to approve it (once the CI files part is sorted out).

cdevents-sdk/Cargo.toml Outdated Show resolved Hide resolved
cdevents-sdk/Cargo.toml Outdated Show resolved Hide resolved
cdevents-sdk/Cargo.toml Show resolved Hide resolved
cdevents-sdk/examples/pipelinerun_finished.rs Outdated Show resolved Hide resolved
cdevents-sdk/src/serde.rs Outdated Show resolved Hide resolved
generator/README.md Outdated Show resolved Hide resolved
@afrittoli
Copy link
Contributor

Would you mind updating the PR title and description in the next iteration?

@davidB
Copy link
Collaborator Author

davidB commented Jan 23, 2024

@rjtch I removed the ci + megalinter workflow from this PR (to work on the workflows) on an other PR (as suggested by @afrittoli). I also rebase the branch on master to resolve conflicts, switch to Makefile,... but now the PR is blocked by the new workflow:

  • lint commit message: => I'll rebase all commit to rephrase git message from gitmoji to conventional commit (the default setup of the plugin)
  • lint rust: the issue is more on the setup of the workflow, should I
    • disable them until fixed (into an other PR)?
    • ignore and the PR will be merged?
    • fix them? (but it will defeat the purpose to work on CI into an other PR)

@afrittoli, What do you prefer "merge", "squash & merge", "rebase" when PR is ok?
Because if "squash & merge" I don't need to rephrase each commit message and just made use conventional commit for the squashed commit. It could also "it depends", on my side I mainly prefer "rebase" by default, "squash merge" (when I want to hide some intermediate commit, eg when fixing CI, debugging,...), forbid "merge" to have linear history on main branch.

…generated samples

- generate samples with arbitraries (proptest)

Signed-off-by: David Bernard <[email protected]>
…ontext.type and subject.type

Signed-off-by: David Bernard <[email protected]>
- avoid clippy genarte wrong warning about useless stuff
- apply some clippy recommandation

Signed-off-by: David Bernard <[email protected]>
- clippy & tests need git submodules content

Signed-off-by: David Bernard <[email protected]>
Signed-off-by: David Bernard <[email protected]>
@davidB
Copy link
Collaborator Author

davidB commented Jan 30, 2024

@rjtch you can review the code and the few modifications, I made on Makefile, tools configuration, ci...

Sorry I rewrite the history several times (that will not ease the review as github could not remember what it already reviewed, and where comment should be inserted), but it was to please the new commit message rules (commitlint) and have a clean history when the PR will be rebase & merge.

Copy link
Contributor

@rjtch rjtch Jan 31, 2024

Choose a reason for hiding this comment

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

I used lint here in the matrix because i wanted to differentiate with next coming tests ci. Now that you renamed it to task it is not really clear what it is! If it is the linter_ci or the tests_ci.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why not simply call this workflow ci (and ci.yml for the filename, github workflow often use this name, and the extension .yml, like what is generated by github and other framework).

We can discuss this point into a next PR. So I'll revert my change.

.mise.toml Outdated Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
@afrittoli
Copy link
Contributor

ide I mainly prefer "rebase" by default, "squash merge" (when I want to hide some intermediate commit, eg when fixing CI, debugging,...), forbid "merge" to have linear history on main branc

I also prefer rebase - I'll add "require linear history" to the branch protection rule.
I think it's fine to squash, but only problem I see is that GitHub won't re-run checks on the squashed commit, so the commit CI job won't actually do anything useful.

Alternatives are:

  • ask authors to squash locally and force push after approval
  • remove the commit linter
  • enable the GitHub merge queue, which, if I understand correctly, once something is squashed for merge, it will add it to a queue and retest (like tide or zuul have done for many years)

.mega-linter.yml Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Comment on lines +15 to +18
# The unpublished packages (generator) would be ignored now
# FIXME the generator is excluded explicitly (see Makefile), I don't know why this is not working
[licenses.private]
ignore = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you create an issue in GitHub to track this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

#13 created, I don't found related issue on cargo-deny so maybe I misunderstood the purpose. It's why I didn't open yet an issue on there repository.

generator/src/main.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@afrittoli afrittoli 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 this!

As a follow-up could you please add a CI job that runs the generator from the PR head and checks that there are no diff with the content of the PR?

@davidB
Copy link
Collaborator Author

davidB commented Feb 1, 2024

@afrittoli I'll not push change on CI in this PR to close it faster, but I include the makefile task to do the check that we could include in the next PR related to CI. I think other points are fixed

@davidB davidB requested a review from afrittoli February 1, 2024 17:31
Copy link
Contributor

@afrittoli afrittoli 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 updates!

@davidB davidB merged commit 4b47b8a into cdevents:main Feb 1, 2024
6 checks passed
@davidB davidB deleted the newstart branch February 1, 2024 18:09
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.

4 participants