Skip to content

Commit bffc18f

Browse files
authored
Doc: Update readme with the example to create PipelineRunFinished CDEvent (#40)
* Update readme with example to create PipelineRunFinished CDEvent * adding DEVELOPMENT page
1 parent 7a50d20 commit bffc18f

File tree

2 files changed

+140
-1
lines changed

2 files changed

+140
-1
lines changed

DEVELOPMENT.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Developing
2+
3+
## Setting up a development environment
4+
5+
### Setup a GitHub account accessible via SSH
6+
7+
GitHub is used for project Source Code Management (SCM) using the SSH protocol for authentication.
8+
9+
1. Create [a GitHub account](https://github.com/join) if you do not already have one.
10+
1. Setup
11+
[GitHub access via SSH](https://help.github.com/articles/connecting-to-github-with-ssh/)
12+
13+
### Install tools
14+
15+
You must install these tools:
16+
17+
1. [`git`](https://help.github.com/articles/set-up-git/): For source control
18+
19+
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.
20+
21+
1. [`docker`](https://www.docker.com/): Required If Super-Linter needs to run locally
22+
23+
24+
25+
### Setup a fork
26+
27+
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.
28+
29+
1. [Create a fork](https://help.github.com/articles/fork-a-repo/) of the `cdevents/sdk-java` repository in your GitHub account.
30+
31+
1. Create a clone of your fork on your local machine:
32+
33+
```shell
34+
git clone git@github.com:${YOUR_GITHUB_USERNAME}/sdk-java.git
35+
```
36+
37+
1. Configure `git` remote repositories
38+
39+
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.
40+
41+
1. Change into the project directory
42+
43+
```shell
44+
cd sdk-java
45+
```
46+
47+
1. Configure sdk-java as the `upstream` repository
48+
49+
```shell
50+
git remote add upstream git@github.com:cdevents/sdk-java.git
51+
52+
# Optional: Prevent accidental pushing of commits by changing the upstream URL to `no_push`
53+
git remote set-url --push upstream no_push
54+
```
55+
56+
1. Configure your fork as the `origin` repository
57+
58+
```shell
59+
git remote add origin git@github.com:${YOUR_GITHUB_USERNAME}/sdk-java.git
60+
```
61+
62+
## Developing, building and testing
63+
64+
65+
To [Run Super-Linter locally](https://github.com/github/super-linter/blob/main/docs/run-linter-locally.md):
66+
67+
```shell
68+
$ docker run -e RUN_LOCAL=true -e USE_FIND_ALGORITHM=true -v /path/to/local/codebase:/tmp/lint github/super-linter:v4
69+
```
70+
71+
To run unit tests:
72+
```shell
73+
$ ./mvnw test
74+
```
75+
76+
To run all targets, before creating a commit:
77+
78+
```shell
79+
./mvnw verify
80+
```

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,60 @@
1-
# sdk-java
1+
# CDEvents Java SDK
2+
3+
Java SDK to produce [CDEvents](https://cdevents.dev).
4+
5+
The SDK can be used to create CDEvents and render as CloudEvents to send them to a specific CloudEvents broker
6+
7+
## Add dependency module
8+
9+
```xml
10+
<dependency>
11+
<groupId>dev.cdevents</groupId>
12+
<artifactId>cdevents-sdk-java</artifactId>
13+
<version>${cdevents.version}</version>
14+
</dependency>
15+
```
16+
17+
## Create your first CDEvent
18+
19+
Below is the example of creating a new [PipelineRun-finished](https://cdevents.dev/docs/core/#pipelinerun-finished) event,
20+
21+
```java
22+
public class CDEventsExample {
23+
24+
public static void main(String args[]){
25+
/*when creating new object of any CDEvent type, the event will be initialized with
26+
context.id, context.type, context.version, context.timestamp
27+
and subject.type */
28+
PipelineRunFinishedCDEvent pipelineRunFinishedCDEvent = new PipelineRunFinishedCDEvent();
29+
30+
/* set the required context fields to the pipelineRunFinishedCDEvent */
31+
pipelineRunFinishedCDEvent.setSource(URI.create("http://dev.cdevents"));
32+
33+
/* set the required subject fields to the pipelineRunFinishedCDEvent */
34+
pipelineRunFinishedCDEvent.setSubjectId("/dev/pipeline/run/1");
35+
pipelineRunFinishedCDEvent.setSubjectSource(URI.create("http://dev.pipeline.run/source"));
36+
pipelineRunFinishedCDEvent.setSubjectUrl(URI.create("http://dev.pipeline.run/url"));
37+
pipelineRunFinishedCDEvent.setSubjectOutcome(CDEventConstants.Outcome.SUCCESS);
38+
pipelineRunFinishedCDEvent.setSubjectPipelineName("testPipeline");
39+
pipelineRunFinishedCDEvent.setSubjectErrors("pipelineErrors");
40+
41+
/* Create a CloudEvent from a pipelineRunFinishedCDEvent */
42+
CloudEvent ceEvent = CDEvents.cdEventAsCloudEvent(pipelineRunFinishedCDEvent);
43+
44+
/* This CDEvent can be sent as CloudEvent using HTTP Protocol Binding,
45+
Refer : https://cloudevents.github.io/sdk-java/http-basic.html
46+
*/
47+
48+
}
49+
}
50+
```
51+
Now the CDEvent can be sent as CloudEvent using [Generic HTTP Protocol Binding](https://cloudevents.github.io/sdk-java/http-basic.html)
52+
53+
## Contributing
54+
55+
If you would like to contribute, see our [development](DEVELOPMENT.md) guide.
56+
57+
## References
58+
59+
- [CDEvents](https://cdevents.dev)
60+
- [CDFoundation SIG Events Vocabulary Draft](https://github.com/cdfoundation/sig-events/tree/main/vocabulary-draft)

0 commit comments

Comments
 (0)