Skip to content

Commit aa10558

Browse files
authored
Merge pull request #119 from mikeee/validation-workflow
Implement example validation
2 parents a9bdb9e + 80c77ac commit aa10558

23 files changed

+558
-19
lines changed
+212
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
name: validate-examples
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- release-*
8+
tags:
9+
- v*
10+
pull_request:
11+
branches:
12+
- main
13+
- release-*
14+
workflow_dispatch:
15+
inputs:
16+
daprdapr_commit:
17+
description: "Dapr/Dapr commit to build custom daprd from"
18+
required: false
19+
default: ""
20+
daprcli_commit:
21+
description: "Dapr/CLI commit to build custom dapr CLI from"
22+
required: false
23+
default: ""
24+
repository_dispatch:
25+
types: [validate-examples]
26+
merge_group:
27+
jobs:
28+
setup:
29+
runs-on: ubuntu-latest
30+
env:
31+
GOOS: linux
32+
GOARCH: amd64
33+
GOPROXY: https://proxy.golang.org
34+
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/master/install/install.sh
35+
DAPR_CLI_REF: ${{ github.event.inputs.daprcli_commit }}
36+
DAPR_REF: ${{ github.event.inputs.daprdapr_commit }}
37+
CHECKOUT_REPO: ${{ github.repository }}
38+
CHECKOUT_REF: ${{ github.ref }}
39+
outputs:
40+
DAPR_INSTALL_URL: ${{ env.DAPR_INSTALL_URL }}
41+
DAPR_CLI_VER: ${{ steps.outputs.outputs.DAPR_CLI_VER }}
42+
DAPR_RUNTIME_VER: ${{ steps.outputs.outputs.DAPR_RUNTIME_VER }}
43+
CHECKOUT_REPO: ${{ steps.outputs.outputs.CHECKOUT_REPO }}
44+
CHECKOUT_REF: ${{ steps.outputs.outputs.CHECKOUT_REF }}
45+
DAPR_REF: ${{ steps.outputs.outputs.DAPR_REF }}
46+
steps:
47+
- name: Parse repository_dispatch payload
48+
if: github.event_name == 'repository_dispatch'
49+
run: |
50+
if [ ${{ github.event.client_payload.command }} = "ok-to-test" ]; then
51+
echo "CHECKOUT_REPO=${{ github.event.client_payload.pull_head_repo }}" >> $GITHUB_ENV
52+
echo "CHECKOUT_REF=${{ github.event.client_payload.pull_head_ref }}" >> $GITHUB_ENV
53+
echo "DAPR_REF=master" >> $GITHUB_ENV
54+
fi
55+
56+
- name: Set up Go
57+
uses: actions/setup-go@v5
58+
with:
59+
go-version: "stable"
60+
61+
- name: Determine latest Dapr Runtime version
62+
run: |
63+
RUNTIME_VERSION=$(curl -s "https://api.github.com/repos/dapr/dapr/releases/latest" | grep '"tag_name"' | cut -d ':' -f2 | tr -d '",v')
64+
echo "DAPR_RUNTIME_VER=$RUNTIME_VERSION" >> $GITHUB_ENV
65+
echo "Found $RUNTIME_VERSION"
66+
67+
- name: Determine latest Dapr Cli version
68+
run: |
69+
CLI_VERSION=$(curl -s "https://api.github.com/repos/dapr/cli/releases/latest" | grep '"tag_name"' | cut -d ':' -f2 | tr -d '",v')
70+
echo "DAPR_CLI_VER=$CLI_VERSION" >> $GITHUB_ENV
71+
echo "Found $CLI_VERSION"
72+
73+
- name: Set up Dapr CLI
74+
run: wget -q ${{ env.DAPR_INSTALL_URL }} -O - | /bin/bash -s ${{ env.DAPR_CLI_VER }}
75+
76+
- name: Checkout Dapr CLI repo to override dapr command.
77+
uses: actions/checkout@v4
78+
if: env.DAPR_CLI_REF != ''
79+
with:
80+
repository: dapr/cli
81+
ref: ${{ env.DAPR_CLI_REF }}
82+
path: cli
83+
84+
- name: Checkout Dapr repo to override daprd.
85+
uses: actions/checkout@v4
86+
if: env.DAPR_REF != ''
87+
with:
88+
repository: dapr/dapr
89+
ref: ${{ env.DAPR_REF }}
90+
path: dapr_runtime
91+
92+
- name: Build dapr cli with referenced commit.
93+
if: env.DAPR_CLI_REF != ''
94+
run: |
95+
cd cli
96+
make
97+
mkdir -p $HOME/artifacts/$GITHUB_SHA/
98+
sudo cp dist/linux_amd64/release/dapr $HOME/artifacts/$GITHUB_SHA/dapr
99+
100+
- name: Build daprd and placement with referenced commit.
101+
if: env.DAPR_REF != ''
102+
run: |
103+
cd dapr_runtime
104+
make
105+
mkdir -p $HOME/artifacts/$GITHUB_SHA/
106+
cp dist/linux_amd64/release/daprd $HOME/artifacts/$GITHUB_SHA/daprd
107+
cp dist/linux_amd64/release/placement $HOME/artifacts/$GITHUB_SHA/placement
108+
109+
- name: Upload dapr-artifacts
110+
uses: actions/upload-artifact@v4
111+
if: env.DAPR_REF != '' || env.DAPR_CLI_REF != ''
112+
with:
113+
name: dapr-artifacts
114+
path: $HOME/artifacts/$GITHUB_SHA/
115+
if-no-files-found: error
116+
retention-days: 1
117+
compression-level: 0
118+
119+
- name: Outputs
120+
id: outputs
121+
run: |
122+
echo "DAPR_INSTALL_URL=$DAPR_INSTALL_URL"
123+
echo "DAPR_CLI_VER=$DAPR_CLI_VER" >> "$GITHUB_OUTPUT"
124+
echo "DAPR_RUNTIME_VER=$DAPR_RUNTIME_VER" >> "$GITHUB_OUTPUT"
125+
echo "CHECKOUT_REPO=$CHECKOUT_REPO" >> "$GITHUB_OUTPUT"
126+
echo "CHECKOUT_REF=$CHECKOUT_REF" >> "$GITHUB_OUTPUT"
127+
echo "DAPR_REF=$DAPR_REF" >> "$GITHUB_OUTPUT"
128+
129+
validate-example:
130+
needs: setup
131+
runs-on: ubuntu-latest
132+
env:
133+
PYTHON_VER: 3.12
134+
DAPR_INSTALL_URL: ${{ needs.setup.outputs.DAPR_INSTALL_URL }}
135+
DAPR_CLI_VER: ${{ needs.setup.outputs.DAPR_CLI_VER }}
136+
DAPR_RUNTIME_VER: ${{ needs.setup.outputs.DAPR_RUNTIME_VER }}
137+
DAPR_CLI_REF: ${{ github.event.inputs.daprcli_commit }}
138+
DAPR_REF: ${{ github.event.inputs.daprdapr_commit }}
139+
CHECKOUT_REPO: ${{ needs.setup.outputs.CHECKOUT_REPO }}
140+
CHECKOUT_REF: ${{ needs.setup.outputs.CHECKOUT_REF }}
141+
RUST_BACKTRACE: full
142+
143+
strategy:
144+
fail-fast: false
145+
matrix:
146+
examples:
147+
["actors", "client", "configuration", "invoke/grpc", "invoke/grpc-proxying", "pubsub"]
148+
steps:
149+
- name: Check out code
150+
uses: actions/checkout@v4
151+
with:
152+
repository: ${{ env.CHECKOUT_REPO }}
153+
ref: ${{ env.CHECKOUT_REF }}
154+
155+
- name: Make Artifacts destination folder
156+
if: env.DAPR_CLI_REF != '' || env.DAPR_REF != ''
157+
run: |
158+
mkdir -p $HOME/artifacts/$GITHUB_SHA/
159+
160+
- name: Retrieve dapr-artifacts
161+
if: env.DAPR_CLI_REF != '' || env.DAPR_REF != ''
162+
uses: actions/download-artifact@v4
163+
with:
164+
name: dapr-artifacts
165+
path: $HOME/artifacts/$GITHUB_SHA/
166+
167+
- name: Rust setup
168+
run: rustup toolchain install stable --profile minimal
169+
170+
- name: Install Protoc
171+
uses: arduino/setup-protoc@v3
172+
with:
173+
version: "25.2"
174+
175+
- name: Set up Dapr CLI
176+
run: wget -q ${{ env.DAPR_INSTALL_URL }} -O - | /bin/bash -s ${{ env.DAPR_CLI_VER }}
177+
178+
- name: Override dapr cli with referenced commit.
179+
if: env.DAPR_CLI_REF != ''
180+
run: |
181+
sudo cp $HOME/artifacts/$GITHUB_SHA/dapr /usr/local/bin/dapr
182+
183+
- name: Initialize Dapr runtime ${{ env.DAPR_RUNTIME_VER }}
184+
run: |
185+
dapr uninstall --all
186+
dapr init --runtime-version ${{ env.DAPR_RUNTIME_VER }}
187+
188+
- name: Override daprd and placement service with referenced commit.
189+
if: env.DAPR_REF != ''
190+
run: |
191+
mkdir -p $HOME/.dapr/bin/
192+
cp $HOME/artifacts/$GITHUB_SHA/daprd $HOME/.dapr/bin/daprd
193+
docker stop dapr_placement
194+
$HOME/artifacts/$GITHUB_SHA/placement --healthz-port 9091 &
195+
196+
- name: Set up Python ${{ env.PYTHON_VER }}
197+
uses: actions/setup-python@v5
198+
with:
199+
python-version: ${{ env.PYTHON_VER }}
200+
201+
- name: Install Mechanical Markdown
202+
run: |
203+
python -m pip install --upgrade pip
204+
pip install mechanical-markdown
205+
206+
- name: Cargo Build Examples
207+
run: cargo build --examples
208+
209+
- name: Check Example
210+
run: |
211+
cd examples
212+
./validate.sh ${{ matrix.examples }}

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ Cargo.lock
99
# These are backup files generated by rustfmt
1010
**/*.rs.bk
1111
.vscode/settings.json
12+
13+
# Ignore logs from dapr runs
14+
.dapr/
15+
16+
17+
# OSX cruft
18+
.DS_Store

examples/actors/README.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,35 @@ Use the `DaprJson` extractor to deserialize the request from Json coming from a
8888
> docker ps
8989
> ```
9090

91-
To run this example:
91+
To run this example (using the multi-app run):
92+
93+
94+
<!-- STEP
95+
name: Run Multi-App
96+
output_match_mode: substring
97+
expected_stdout_lines:
98+
- 'dapr::server::actor::runtime] registered actor MyActor'
99+
- 'Request for actor_type: MyActor, actor_id: a1'
100+
- '== APP - actor-server == on_activate a1'
101+
- '== APP - actor-server == doing stuff with test'
102+
- '== APP - actor-server == get_actor_state GetActorStateResponse { data: []'
103+
- '== APP - actor-client == Response: Ok('
104+
- '== APP - actor-client == MyResponse {'
105+
- '== APP - actor-client == available: true,'
106+
- '== APP - actor-client == },'
107+
- '== APP - actor-client == )'
108+
background: true
109+
sleep: 30
110+
timeout_seconds: 30
111+
-->
112+
113+
```bash
114+
dapr run -f .
115+
```
116+
117+
<!-- END_STEP -->
118+
119+
### What the multi-run app will achieve:
92120
93121
1. Start actor host (expose Http server receiver on port 50051):
94122
```bash
@@ -98,4 +126,5 @@ dapr run --app-id actor-host --app-protocol http --app-port 50051 cargo run -- -
98126
2. Start actor client:
99127
```bash
100128
dapr run --app-id actor-client --dapr-grpc-port 3502 cargo run -- --example actor-client
129+
101130
```

examples/actors/dapr.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 1
2+
common:
3+
daprdLogDestination: console
4+
apps:
5+
- appID: actor-server
6+
appDirPath: ./
7+
appProtocol: http
8+
appPort: 50051
9+
logLevel: debug
10+
command: ["cargo", "run", "--example", "actor-server"]
11+
- appID: actor-client
12+
appDirPath: ./
13+
daprGRPCPort: 3502
14+
logLevel: debug
15+
command: ["cargo", "run", "--example", "actor-client"]

examples/client/README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,24 @@ cargo build --examples
1111

1212
2. Run the example with dapr using the following command:
1313

14-
```
14+
<!-- STEP
15+
name: Run client example
16+
output_match_mode: substring
17+
expected_stdout_lines:
18+
- '== APP == Successfully saved!'
19+
- '== APP == Value is "world"'
20+
- '== APP == Deleted value: []'
21+
background: true
22+
sleep: 15
23+
timeout_seconds: 30
24+
-->
25+
26+
```bash
1527
dapr run --app-id=rustapp --dapr-grpc-port 3500 cargo run -- --example client
1628
```
1729

30+
<!-- END_STEP -->
31+
1832
If everything went well you should see the following output along with dapr logs:
1933
```
2034
Successfully saved!

examples/configuration/README.md

+51-5
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,70 @@ docker ps
99
cargo build --examples
1010
```
1111

12-
2. Run the example with dapr using the following command:
12+
2. Insert a key with the value `hello` to redis using the following command:
13+
14+
15+
<!-- STEP
16+
name: Insert test configuration item
17+
output_match_mode: substring
18+
expected_stdout_lines:
19+
- 'OK'
20+
background: false
21+
sleep: 5
22+
timeout_seconds: 5
23+
-->
1324

1425
```bash
15-
dapr run --app-id=rustapp --resources-path ./examples/components --dapr-grpc-port 3500 -- cargo run --example configuration
26+
docker exec dapr_redis redis-cli MSET hello "world"
1627
```
1728

18-
3. Change the value of the key `hello` in redis using the following command:
29+
<!-- END_STEP -->
30+
31+
3. Run the example with dapr using the following command:
32+
33+
<!-- STEP
34+
name: Run configuration app
35+
output_match_mode: substring
36+
expected_stdout_lines:
37+
- '== APP == Configuration value: ConfigurationItem { value: "world"'
38+
- '== APP == App subscribed to config changes with subscription id:'
39+
- '== APP == Configuration value: {"hello": ConfigurationItem { value: "world2"'
40+
- '== APP == App unsubscribed from config changes'
41+
background: true
42+
sleep: 15
43+
timeout_seconds: 30
44+
-->
1945

2046
```bash
21-
docker exec dapr_redis redis-cli MSET hello "world"
47+
dapr run --app-id=rustapp --resources-path ../components --dapr-grpc-port 3500 -- cargo run --example configuration
2248
```
2349

50+
<!-- END_STEP -->
51+
52+
4. Change the value of the key `hello` in redis using the following command:
53+
54+
<!-- STEP
55+
name: Update test configuration item
56+
output_match_mode: substring
57+
expected_stdout_lines:
58+
- 'OK'
59+
background: true
60+
sleep: 5
61+
timeout_seconds: 5
62+
-->
63+
64+
```bash
65+
docker exec dapr_redis redis-cli MSET hello "world2"
66+
```
67+
68+
<!-- END_STEP -->
69+
2470

2571
If everything went well you should see the following output along with dapr logs:
2672
```
2773
Configuration value: ConfigurationItem { value: "world", version: "", metadata: {} }
2874
App subscribed to config changes with subscription id: "d383169a-0893-4c64-adde-fc3145b56d07"
29-
Configuration value: {"hello": ConfigurationItem { value: "world", version: "", metadata: {} }}
75+
Configuration value: {"hello": ConfigurationItem { value: "world2", version: "", metadata: {} }}
3076
App unsubscribed from config changes
3177
```
3278

0 commit comments

Comments
 (0)