Skip to content

Commit 0740213

Browse files
Java templates and release (#47)
* Java/Kotlin Hello world examples * Automation * This package-lock.json seems wrong * Add .gitignore to typescript examples that don't have it. this is used by gitzip in the release script * Rename lambda-greeter to hello-world-greeter * READMEs
1 parent 6afc5f7 commit 0740213

File tree

67 files changed

+2747
-37
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2747
-37
lines changed

.github/workflows/pre-release.yml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Pre-release updates
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
sdkTypescriptVersion:
7+
description: 'sdk-typescript version (without prepending v). Leave empty if you do not want to update it.'
8+
required: false
9+
type: string
10+
sdkJavaVersion:
11+
description: 'sdk-java version (without prepending v). Leave empty if you do not want to update it.'
12+
required: false
13+
type: string
14+
15+
jobs:
16+
updates:
17+
# prevent from running on forks
18+
if: github.repository_owner == 'restatedev'
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 20
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
26+
# Setup node
27+
- uses: actions/setup-node@v3
28+
if: github.event.inputs.sdkTypescriptVersion != ''
29+
with:
30+
node-version: "19.x"
31+
registry-url: 'https://registry.npmjs.org'
32+
33+
# Bump sdk version in node examples and run checks
34+
- name: Run npm updates
35+
if: github.event.inputs.sdkTypescriptVersion != ''
36+
run: npm --prefix typescript install @restatedev/restate-sdk@^${{ inputs.sdkTypescriptVersion }} --workspaces
37+
- name: Check npm examples compile correctly
38+
if: github.event.inputs.sdkTypescriptVersion != ''
39+
run: npm --prefix typescript run verify --workspaces
40+
41+
# Setup Java
42+
- uses: actions/setup-java@v3
43+
if: github.event.inputs.sdkJavaVersion != ''
44+
with:
45+
distribution: 'temurin'
46+
java-version: '17'
47+
48+
# Bump sdk version in java/kotlin examples and run checks
49+
# When adding a new example make sure it's listed here
50+
- name: Find and replace restateVersion in build.gradle.kts for java templates
51+
if: github.event.inputs.sdkJavaVersion != ''
52+
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
53+
- name: Find and replace restateVersion in build.gradle.kts for kotlin templates
54+
if: github.event.inputs.sdkJavaVersion != ''
55+
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
56+
57+
# When adding a new example add the check task here
58+
- name: Test java/hello-world-http
59+
if: github.event.inputs.sdkJavaVersion != ''
60+
uses: gradle/gradle-build-action@v2
61+
with:
62+
arguments: check
63+
build-root-directory: java/hello-world-http
64+
- name: Test java/hello-world-lambda
65+
if: github.event.inputs.sdkJavaVersion != ''
66+
uses: gradle/gradle-build-action@v2
67+
with:
68+
arguments: check
69+
build-root-directory: java/hello-world-lambda
70+
- name: Test kotlin/hello-world-http
71+
if: github.event.inputs.sdkJavaVersion != ''
72+
uses: gradle/gradle-build-action@v2
73+
with:
74+
arguments: check
75+
build-root-directory: kotlin/hello-world-http
76+
- name: Test kotlin/hello-world-lambda
77+
if: github.event.inputs.sdkJavaVersion != ''
78+
uses: gradle/gradle-build-action@v2
79+
with:
80+
arguments: check
81+
build-root-directory: kotlin/hello-world-lambda
82+
83+
- name: Create Pull Request
84+
uses: peter-evans/create-pull-request@v5
85+
with:
86+
title: "[GithubActions] Update Restate ${{ inputs.sdkTypescriptVersion != '' && format('SDK-Typescript {0} ', inputs.sdkTypescriptVersion) }}${{ inputs.sdkJavaVersion != '' && format('SDK-Java {0}', inputs.sdkJavaVersion) }}"
87+
commit-message: "[GithubActions] Update Restate ${{ inputs.sdkTypescriptVersion != '' && format('SDK-Typescript {0} ', inputs.sdkTypescriptVersion) }}${{ inputs.sdkJavaVersion != '' && format('SDK-Java {0}', inputs.sdkJavaVersion) }}"
88+
add-paths: |
89+
**/package.json
90+
**/package-lock.json
91+
**/build.gradle.kts

.github/workflows/release.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Create new release
2+
3+
on:
4+
push:
5+
tags:
6+
- v**
7+
8+
jobs:
9+
publish-release:
10+
# prevent from running on forks
11+
if: github.repository_owner == 'restatedev'
12+
name: Publish release
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Prepare zip files
19+
run: ./scripts/prepare_release_zip.sh
20+
21+
- name: Create release
22+
uses: softprops/action-gh-release@v1
23+
with:
24+
# create a draft release which needs manual approval
25+
draft: true
26+
files: |
27+
typescript-lambda-greeter.zip
28+
java-hello-world-http.zip
29+
java-hello-world-lambda.zip
30+
kotlin-hello-world-http.zip
31+
kotlin-hello-world-lambda.zip

.github/workflows/test.yml

+41-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,45 @@ on:
77
branches: [ main ]
88

99
jobs:
10-
build:
10+
build-jvm:
11+
# prevent from running on forks
12+
if: github.repository_owner == 'restatedev'
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
jvm-version: [ 17 ]
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- name: Use JVM ${{ matrix.jvm-version }}
22+
uses: actions/setup-java@v3
23+
with:
24+
distribution: 'temurin'
25+
java-version: ${{ matrix.jvm-version }}
26+
27+
# When adding a new example make sure it's listed here
28+
- name: Test java/hello-world-http
29+
uses: gradle/gradle-build-action@v2
30+
with:
31+
arguments: check
32+
build-root-directory: java/hello-world-http
33+
- name: Test java/hello-world-lambda
34+
uses: gradle/gradle-build-action@v2
35+
with:
36+
arguments: check
37+
build-root-directory: java/hello-world-lambda
38+
- name: Test kotlin/hello-world-http
39+
uses: gradle/gradle-build-action@v2
40+
with:
41+
arguments: check
42+
build-root-directory: kotlin/hello-world-http
43+
- name: Test kotlin/hello-world-lambda
44+
uses: gradle/gradle-build-action@v2
45+
with:
46+
arguments: check
47+
build-root-directory: kotlin/hello-world-lambda
48+
build-ts:
1149
# prevent from running on forks
1250
if: github.repository_owner == 'restatedev'
1351
runs-on: ubuntu-latest
@@ -17,11 +55,13 @@ jobs:
1755

1856
steps:
1957
- uses: actions/checkout@v3
58+
2059
- uses: bufbuild/buf-setup-action@v1
2160
- name: Use Node.js ${{ matrix.node-version }}
2261
uses: actions/setup-node@v3
2362
with:
2463
node-version: ${{ matrix.node-version }}
2564
registry-url: 'https://registry.npmjs.org'
65+
2666
- run: npm ci --prefix typescript
2767
- run: npm run --prefix typescript -ws verify

README.md

+73-29
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,75 @@
66

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

9-
## Typescript examples
9+
## Starters
1010

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

13-
* [Lambda greeter](typescript/lambda-greeter): A simple example of how you can run a Restate service on AWS Lambda.
14-
* [Payment api](typescript/payment-api/): Example API for payments, inspired by the Stripe API.
15-
* [Food ordering](typescript/food-ordering): See how to integrate Restate with external services using Awakeables and side effects.
13+
[Hello world on AWS Lambda](typescript/hello-world-lambda)
14+
```shell
15+
# Download the example
16+
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
17+
```
18+
19+
![Java](https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white)
20+
21+
[Hello World HTTP](java/hello-world-http)
22+
```shell
23+
# Download the example
24+
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
25+
```
26+
27+
[Hello world on AWS Lambda](java/hello-world-lambda)
28+
```shell
29+
# Download the example
30+
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
31+
```
32+
33+
![Kotlin](https://img.shields.io/badge/kotlin-%237F52FF.svg?style=for-the-badge&logo=kotlin&logoColor=white)
1634

17-
### Intermediate examples
35+
[Hello World HTTP](java/hello-world-kotlin-http)
36+
```shell
37+
# Download the example
38+
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
39+
```
40+
41+
[Hello world on AWS Lambda](java/hello-world-kotlin-lambda)
42+
```shell
43+
# Download the example
44+
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
45+
```
1846

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

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

23-
- [Ecommerce store](typescript/ecommerce-store): A sophisticated example on how to build an ecommerce store based on Restate using the grpc-based Typescript SDK.
51+
[Payment api](typescript/payment-api): Example API for payments, inspired by the Stripe API
52+
```shell
53+
# Download the example
54+
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
55+
```
56+
57+
## Applications
58+
59+
![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white)
60+
61+
[Food ordering](typescript/food-ordering): Integrate Restate with external services
62+
```shell
63+
# Download the example
64+
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
65+
```
66+
67+
[Ticket reservation](typescript/ticket-reservation): Example showing Restate's keyed-sharding and concurrency guarantees
68+
```shell
69+
# Download the example
70+
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
71+
```
72+
73+
[Ecommerce store](typescript/ecommerce-store): An ecommerce store completely built on top of Restate
74+
```shell
75+
# Download the example
76+
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
77+
```
2478

2579
## Joining the community
2680

@@ -78,29 +132,19 @@ This should give you the following output in case of the ticket reservation exam
78132
}
79133
```
80134

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

86-
### Upgrading the SDK dependency (for Restate developers)
137+
When adding a new example:
87138

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

90-
**Major version** change:
144+
## Releasing (for Restate developers)
91145

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

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

98-
```shell
99-
npm --prefix typescript update @restatedev/restate-sdk --workspaces
100-
```
101-
102-
Now check whether the examples are still building:
103-
104-
```shell
105-
npm --prefix typescript run verify --workspaces
106-
```
150+
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.

java/hello-world-http/.gitignore

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.jar
15+
*.war
16+
*.nar
17+
*.ear
18+
*.zip
19+
*.tar.gz
20+
*.rar
21+
22+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23+
hs_err_pid*
24+
25+
# Ignore Gradle project-specific cache directory
26+
.gradle
27+
28+
# Ignore Gradle build output directory
29+
build
30+
31+
.idea
32+
*.iml
33+
34+
# Unignore the gradle wrapper
35+
!gradle/wrapper/gradle-wrapper.jar

java/hello-world-http/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Hello world - Java HTTP example
2+
3+
Sample project configuration of a Restate service using the Java interface and HTTP server. It contains:
4+
5+
* [`build.gradle.kts`](build.gradle.kts)
6+
* [Service interface definition `greeter.proto`](src/main/proto/greeter.proto)
7+
* [Service class implementation `Greeter`](src/main/java/dev/restate/sdk/examples/Greeter.java)
8+
* [Test `GreeterTest`](src/test/java/dev/restate/sdk/examples/GreeterTest.java)
9+
* [Logging configuration](src/main/resources/log4j2.properties)
10+
11+
## Download the example
12+
13+
```shell
14+
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
15+
```
16+
17+
## Running the example
18+
19+
You can run the Java greeter service via:
20+
21+
```shell
22+
./gradlew run
23+
```
24+
25+
Or from your IDE.
26+
27+
## Running the tests
28+
29+
You can run the tests either via:
30+
31+
```shell
32+
./gradlew check
33+
```
34+
35+
Or from your IDE.

0 commit comments

Comments
 (0)