-
Notifications
You must be signed in to change notification settings - Fork 6
Doc: Update readme with the example to create PipelineRunFinished CDEvent #40
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Developing | ||
|
||
## Setting up a development environment | ||
|
||
### Setup a GitHub account accessible via SSH | ||
|
||
GitHub is used for project Source Code Management (SCM) using the SSH protocol for authentication. | ||
|
||
1. Create [a GitHub account](https://github.com/join) if you do not already have one. | ||
1. Setup | ||
[GitHub access via SSH](https://help.github.com/articles/connecting-to-github-with-ssh/) | ||
|
||
### Install tools | ||
|
||
You must install these tools: | ||
|
||
1. [`git`](https://help.github.com/articles/set-up-git/): For source control | ||
|
||
1. [`java`](https://www.oracle.com/java/technologies/downloads/): The language this SDK is built in. Java 9 is a minimum requirement to build the project. | ||
|
||
1. [`docker`](https://www.docker.com/): Required If Super-Linter needs to run locally | ||
|
||
|
||
|
||
### Setup a fork | ||
|
||
The sdk-java project requires that you develop (commit) code changes to branches that belong to a fork of the `cdevents/sdk-java` repository in your GitHub account before submitting them as Pull Requests (PRs) to the actual project repository. | ||
|
||
1. [Create a fork](https://help.github.com/articles/fork-a-repo/) of the `cdevents/sdk-java` repository in your GitHub account. | ||
|
||
1. Create a clone of your fork on your local machine: | ||
|
||
```shell | ||
git clone git@github.com:${YOUR_GITHUB_USERNAME}/sdk-java.git | ||
``` | ||
|
||
1. Configure `git` remote repositories | ||
|
||
Adding `cdevents/sdk-java` as the `upstream` and your fork as the `origin` remote repositories to your `.git/config` sets you up nicely for regularly [syncing your fork](https://help.github.com/articles/syncing-a-fork/) and submitting pull requests. | ||
|
||
1. Change into the project directory | ||
|
||
```shell | ||
cd sdk-java | ||
``` | ||
|
||
1. Configure sdk-java as the `upstream` repository | ||
|
||
```shell | ||
git remote add upstream git@github.com:cdevents/sdk-java.git | ||
|
||
# Optional: Prevent accidental pushing of commits by changing the upstream URL to `no_push` | ||
git remote set-url --push upstream no_push | ||
``` | ||
|
||
1. Configure your fork as the `origin` repository | ||
|
||
```shell | ||
git remote add origin git@github.com:${YOUR_GITHUB_USERNAME}/sdk-java.git | ||
``` | ||
|
||
## Developing, building and testing | ||
|
||
|
||
To [Run Super-Linter locally](https://github.com/github/super-linter/blob/main/docs/run-linter-locally.md): | ||
|
||
```shell | ||
$ docker run -e RUN_LOCAL=true -e USE_FIND_ALGORITHM=true -v /path/to/local/codebase:/tmp/lint github/super-linter:v4 | ||
``` | ||
|
||
To run unit tests: | ||
```shell | ||
$ ./mvnw test | ||
``` | ||
|
||
To run all targets, before creating a commit: | ||
|
||
```shell | ||
./mvnw verify | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,60 @@ | ||
# sdk-java | ||
# CDEvents Java SDK | ||
|
||
Java SDK to produce [CDEvents](https://cdevents.dev). | ||
|
||
The SDK can be used to create CDEvents and render as CloudEvents to send them to a specific CloudEvents broker | ||
|
||
## Add dependency module | ||
|
||
```xml | ||
<dependency> | ||
<groupId>dev.cdevents</groupId> | ||
<artifactId>cdevents-sdk-java</artifactId> | ||
<version>${cdevents.version}</version> | ||
</dependency> | ||
``` | ||
|
||
## Create your first CDEvent | ||
|
||
Below is the example of creating a new [PipelineRun-finished](https://cdevents.dev/docs/core/#pipelinerun-finished) event, | ||
|
||
```java | ||
public class CDEventsExample { | ||
|
||
public static void main(String args[]){ | ||
/*when creating new object of any CDEvent type, the event will be initialized with | ||
context.id, context.type, context.version, context.timestamp | ||
and subject.type */ | ||
PipelineRunFinishedCDEvent pipelineRunFinishedCDEvent = new PipelineRunFinishedCDEvent(); | ||
|
||
/* set the required context fields to the pipelineRunFinishedCDEvent */ | ||
pipelineRunFinishedCDEvent.setSource(URI.create("http://dev.cdevents")); | ||
|
||
/* set the required subject fields to the pipelineRunFinishedCDEvent */ | ||
pipelineRunFinishedCDEvent.setSubjectId("/dev/pipeline/run/1"); | ||
pipelineRunFinishedCDEvent.setSubjectSource(URI.create("http://dev.pipeline.run/source")); | ||
pipelineRunFinishedCDEvent.setSubjectUrl(URI.create("http://dev.pipeline.run/url")); | ||
pipelineRunFinishedCDEvent.setSubjectOutcome(CDEventConstants.Outcome.SUCCESS); | ||
pipelineRunFinishedCDEvent.setSubjectPipelineName("testPipeline"); | ||
pipelineRunFinishedCDEvent.setSubjectErrors("pipelineErrors"); | ||
|
||
/* Create a CloudEvent from a pipelineRunFinishedCDEvent */ | ||
CloudEvent ceEvent = CDEvents.cdEventAsCloudEvent(pipelineRunFinishedCDEvent); | ||
|
||
/* This CDEvent can be sent as CloudEvent using HTTP Protocol Binding, | ||
Refer : https://cloudevents.github.io/sdk-java/http-basic.html | ||
*/ | ||
|
||
} | ||
} | ||
``` | ||
Now the CDEvent can be sent as CloudEvent using [Generic HTTP Protocol Binding](https://cloudevents.github.io/sdk-java/http-basic.html) | ||
|
||
## Contributing | ||
|
||
If you would like to contribute, see our [development](DEVELOPMENT.md) guide. | ||
|
||
## References | ||
|
||
- [CDEvents](https://cdevents.dev) | ||
- [CDFoundation SIG Events Vocabulary Draft](https://github.com/cdfoundation/sig-events/tree/main/vocabulary-draft) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.