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

Java templates and release #47

Merged
merged 9 commits into from
Dec 5, 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
91 changes: 91 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Pre-release updates

on:
workflow_dispatch:
inputs:
sdkTypescriptVersion:
description: 'sdk-typescript version (without prepending v). Leave empty if you do not want to update it.'
required: false
type: string
sdkJavaVersion:
description: 'sdk-java version (without prepending v). Leave empty if you do not want to update it.'
required: false
type: string

jobs:
updates:
# prevent from running on forks
if: github.repository_owner == 'restatedev'
runs-on: ubuntu-latest
timeout-minutes: 20

steps:
- name: Checkout
uses: actions/checkout@v3

# Setup node
- uses: actions/setup-node@v3
if: github.event.inputs.sdkTypescriptVersion != ''
with:
node-version: "19.x"
registry-url: 'https://registry.npmjs.org'

# Bump sdk version in node examples and run checks
- name: Run npm updates
if: github.event.inputs.sdkTypescriptVersion != ''
run: npm --prefix typescript install @restatedev/restate-sdk@^${{ inputs.sdkTypescriptVersion }} --workspaces
- name: Check npm examples compile correctly
if: github.event.inputs.sdkTypescriptVersion != ''
run: npm --prefix typescript run verify --workspaces

# Setup Java
- uses: actions/setup-java@v3
if: github.event.inputs.sdkJavaVersion != ''
with:
distribution: 'temurin'
java-version: '17'

# Bump sdk version in java/kotlin examples and run checks
# When adding a new example make sure it's listed here
- name: Find and replace restateVersion in build.gradle.kts for java templates
if: github.event.inputs.sdkJavaVersion != ''
run: for jvmDir in hello-world-http hello-world-lambda; do sed -i 's/val restateVersion = "[0-9A-Z.-]*"/val restateVersion = "${{ inputs.sdkJavaVersion }}"/' java/$jvmDir/build.gradle.kts; done
- name: Find and replace restateVersion in build.gradle.kts for kotlin templates
if: github.event.inputs.sdkJavaVersion != ''
run: for jvmDir in hello-world-http hello-world-lambda; do sed -i 's/val restateVersion = "[0-9A-Z.-]*"/val restateVersion = "${{ inputs.sdkJavaVersion }}"/' kotlin/$jvmDir/build.gradle.kts; done

# When adding a new example add the check task here
- name: Test java/hello-world-http
if: github.event.inputs.sdkJavaVersion != ''
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: java/hello-world-http
- name: Test java/hello-world-lambda
if: github.event.inputs.sdkJavaVersion != ''
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: java/hello-world-lambda
- name: Test kotlin/hello-world-http
if: github.event.inputs.sdkJavaVersion != ''
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: kotlin/hello-world-http
- name: Test kotlin/hello-world-lambda
if: github.event.inputs.sdkJavaVersion != ''
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: kotlin/hello-world-lambda

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
title: "[GithubActions] Update Restate ${{ inputs.sdkTypescriptVersion != '' && format('SDK-Typescript {0} ', inputs.sdkTypescriptVersion) }}${{ inputs.sdkJavaVersion != '' && format('SDK-Java {0}', inputs.sdkJavaVersion) }}"
commit-message: "[GithubActions] Update Restate ${{ inputs.sdkTypescriptVersion != '' && format('SDK-Typescript {0} ', inputs.sdkTypescriptVersion) }}${{ inputs.sdkJavaVersion != '' && format('SDK-Java {0}', inputs.sdkJavaVersion) }}"
add-paths: |
**/package.json
**/package-lock.json
**/build.gradle.kts
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Create new release

on:
push:
tags:
- v**

jobs:
publish-release:
# prevent from running on forks
if: github.repository_owner == 'restatedev'
name: Publish release
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Prepare zip files
run: ./scripts/prepare_release_zip.sh

- name: Create release
uses: softprops/action-gh-release@v1
with:
# create a draft release which needs manual approval
draft: true
files: |
typescript-lambda-greeter.zip
java-hello-world-http.zip
java-hello-world-lambda.zip
kotlin-hello-world-http.zip
kotlin-hello-world-lambda.zip
42 changes: 41 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,45 @@ on:
branches: [ main ]

jobs:
build:
build-jvm:
# prevent from running on forks
if: github.repository_owner == 'restatedev'
runs-on: ubuntu-latest
strategy:
matrix:
jvm-version: [ 17 ]

steps:
- uses: actions/checkout@v3

- name: Use JVM ${{ matrix.jvm-version }}
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ matrix.jvm-version }}

# When adding a new example make sure it's listed here
- name: Test java/hello-world-http
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: java/hello-world-http
- name: Test java/hello-world-lambda
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: java/hello-world-lambda
- name: Test kotlin/hello-world-http
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: kotlin/hello-world-http
- name: Test kotlin/hello-world-lambda
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: kotlin/hello-world-lambda
build-ts:
# prevent from running on forks
if: github.repository_owner == 'restatedev'
runs-on: ubuntu-latest
Expand All @@ -17,11 +55,13 @@ jobs:

steps:
- uses: actions/checkout@v3

- uses: bufbuild/buf-setup-action@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'

- run: npm ci --prefix typescript
- run: npm run --prefix typescript -ws verify
102 changes: 73 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,75 @@

Browse this repository to see how easy distributed applications development becomes with Restate.

## Typescript examples
## Starters

### Starter examples
![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white)

* [Lambda greeter](typescript/lambda-greeter): A simple example of how you can run a Restate service on AWS Lambda.
* [Payment api](typescript/payment-api/): Example API for payments, inspired by the Stripe API.
* [Food ordering](typescript/food-ordering): See how to integrate Restate with external services using Awakeables and side effects.
[Hello world on AWS Lambda](typescript/hello-world-lambda)
```shell
# Download the example
wget https://github.com/restatedev/examples/releases/latest/download/typescript-hello-world-lambda.zip && unzip typescript-hello-world-lambda.zip -d typescript-hello-world-lambda && rm typescript-hello-world-lambda.zip
```

![Java](https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white)

[Hello World HTTP](java/hello-world-http)
```shell
# Download the example
wget https://github.com/restatedev/examples/releases/latest/download/java-hello-world-http.zip && unzip java-hello-world-http.zip -d java-hello-world-http && rm java-hello-world-http.zip
```

[Hello world on AWS Lambda](java/hello-world-lambda)
```shell
# Download the example
wget https://github.com/restatedev/examples/releases/latest/download/java-hello-world-lambda.zip && unzip java-hello-world-lambda.zip -d java-hello-world-lambda && rm java-hello-world-lambda.zip
```

![Kotlin](https://img.shields.io/badge/kotlin-%237F52FF.svg?style=for-the-badge&logo=kotlin&logoColor=white)

### Intermediate examples
[Hello World HTTP](java/hello-world-kotlin-http)
```shell
# Download the example
wget https://github.com/restatedev/examples/releases/latest/download/kotlin-hello-world-http.zip && unzip kotlin-hello-world-http.zip -d kotlin-hello-world-http && rm kotlin-hello-world-http.zip
```

[Hello world on AWS Lambda](java/hello-world-kotlin-lambda)
```shell
# Download the example
wget https://github.com/restatedev/examples/releases/latest/download/kotlin-hello-world-lambda.zip && unzip kotlin-hello-world-lambda.zip -d kotlin-hello-world-lambda && rm kotlin-hello-world-lambda.zip
```

* [Ticket reservation](typescript/ticket-reservation): An example to illustrate how Restate's keyed-sharding and concurrency guarantees simplify microservice architectures.
## Patterns

### Advanced examples
![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white)

- [Ecommerce store](typescript/ecommerce-store): A sophisticated example on how to build an ecommerce store based on Restate using the grpc-based Typescript SDK.
[Payment api](typescript/payment-api): Example API for payments, inspired by the Stripe API
```shell
# Download the example
wget https://github.com/restatedev/examples/releases/latest/download/typescript-payment-api.zip && unzip typescript-payment-api.zip -d typescript-payment-api && rm typescript-payment-api.zip
```

## Applications

![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white)

[Food ordering](typescript/food-ordering): Integrate Restate with external services
```shell
# Download the example
wget https://github.com/restatedev/examples/releases/latest/download/typescript-food-ordering.zip && unzip typescript-food-ordering.zip -d typescript-food-ordering && rm typescript-food-ordering.zip
```

[Ticket reservation](typescript/ticket-reservation): Example showing Restate's keyed-sharding and concurrency guarantees
```shell
# Download the example
wget https://github.com/restatedev/examples/releases/latest/download/typescript-ticket-reservation.zip && unzip typescript-ticket-reservation.zip -d typescript-ticket-reservation && rm typescript-ticket-reservation.zip
```

[Ecommerce store](typescript/ecommerce-store): An ecommerce store completely built on top of Restate
```shell
# Download the example
wget https://github.com/restatedev/examples/releases/latest/download/typescript-ecommerce-store.zip && unzip typescript-ecommerce-store.zip -d typescript-ecommerce-store && rm typescript-ecommerce-store.zip
```

## Joining the community

Expand Down Expand Up @@ -78,29 +132,19 @@ This should give you the following output in case of the ticket reservation exam
}
```

## Releasing (for Restate developers)

In order to create a new release, push a tag of the form `vX.Y.Z`.
Then [create a release via GitHub](https://github.com/restatedev/example-lambda-ts-greeter/releases).
## Adding examples (for Restate developers)

### Upgrading the SDK dependency (for Restate developers)
When adding a new example:

In order to upgrade/update the SDK dependency you have to run:
* Make sure it has a `.gitignore` file and a README
* Add it to this README
* Check it's tested both in [`test.yaml`](./.github/workflows/test.yml) and [`pre-release.yaml`](./.github/workflows/pre-release.yml)
* Add it to the [zips script](./scripts/prepare_release_zip.sh) and [`release.yaml`](./.github/workflows/release.yml)

**Major version** change:
## Releasing (for Restate developers)

```shell
npm --prefix typescript install @restatedev/restate-sdk@^Z.Y.X --workspaces
```
Before releasing, trigger the "pre-release" workflow to update sdk versions. This automatically creates a pull request, which must be manually merged.

**Minor/patch version** change:
Once the repo is ready for the release, push a tag of the form `vX.Y.Z`.

```shell
npm --prefix typescript update @restatedev/restate-sdk --workspaces
```

Now check whether the examples are still building:

```shell
npm --prefix typescript run verify --workspaces
```
This triggers a workflow that [creates a draft release](https://github.com/restatedev/examples/releases) on Github, which you need to approve to finalize it.
35 changes: 35 additions & 0 deletions java/hello-world-http/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build

.idea
*.iml

# Unignore the gradle wrapper
!gradle/wrapper/gradle-wrapper.jar
35 changes: 35 additions & 0 deletions java/hello-world-http/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Hello world - Java HTTP example

Sample project configuration of a Restate service using the Java interface and HTTP server. It contains:

* [`build.gradle.kts`](build.gradle.kts)
* [Service interface definition `greeter.proto`](src/main/proto/greeter.proto)
* [Service class implementation `Greeter`](src/main/java/dev/restate/sdk/examples/Greeter.java)
* [Test `GreeterTest`](src/test/java/dev/restate/sdk/examples/GreeterTest.java)
* [Logging configuration](src/main/resources/log4j2.properties)

## Download the example

```shell
wget https://github.com/restatedev/examples/releases/latest/download/java-hello-world-http.zip && unzip java-hello-world-http.zip -d java-hello-world-http && rm java-hello-world-http.zip
```

## Running the example

You can run the Java greeter service via:

```shell
./gradlew run
```

Or from your IDE.

## Running the tests

You can run the tests either via:

```shell
./gradlew check
```

Or from your IDE.
Loading
Loading