Skip to content

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 5 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions DEVELOPMENT.md
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
```
61 changes: 60 additions & 1 deletion README.md
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)
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dev.cdevents.sdk-java</groupId>
<groupId>dev.cdevents</groupId>
<artifactId>cdevents-sdk-java</artifactId>
<version>v0.1.0-draft6</version>

Expand Down