mirror of https://github.com/dapr/quickstarts.git
Addressing review comments
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
This commit is contained in:
parent
f2c6352dd0
commit
9bb624efbe
|
@ -0,0 +1,103 @@
|
||||||
|
#
|
||||||
|
# Copyright 2022 The Dapr Authors
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
name: Validate Workflows
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- feature/new_quickstarts
|
||||||
|
- release-*
|
||||||
|
tags:
|
||||||
|
- v*
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- feature/new_quickstarts
|
||||||
|
- release-*
|
||||||
|
jobs:
|
||||||
|
validate:
|
||||||
|
name: Validate quickstart for `${{ matrix.quickstart_language }}` with `${{ matrix.quickstart_variant }}` on ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
env:
|
||||||
|
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/master/install
|
||||||
|
GOVER: 1.17
|
||||||
|
KUBERNETES_VERSION: v1.21.1
|
||||||
|
KIND_VERSION: v0.11.0
|
||||||
|
KIND_IMAGE_SHA: sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-10.15]
|
||||||
|
quickstart_language: [csharp]
|
||||||
|
quickstart_variant: [sdk]
|
||||||
|
steps:
|
||||||
|
- name: Install docker - MacOS
|
||||||
|
if: matrix.os == 'macos-10.15'
|
||||||
|
uses: docker-practice/actions-setup-docker@v1
|
||||||
|
with:
|
||||||
|
docker_buildx: false
|
||||||
|
docker_version: 20.10
|
||||||
|
- name: Set up Go ${{ env.GOVER }}
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: ${{ env.GOVER }}
|
||||||
|
- name: Set up OpenJDK 11
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
distribution: 'adopt'
|
||||||
|
java-version: 11
|
||||||
|
- name: Install .NET Core
|
||||||
|
uses: actions/setup-dotnet@v1.9.0
|
||||||
|
with:
|
||||||
|
dotnet-version: |
|
||||||
|
6.0.x
|
||||||
|
- name: Determine latest Dapr Runtime version including Pre-releases
|
||||||
|
run: |
|
||||||
|
helm repo add dapr https://dapr.github.io/helm-charts/ && helm repo update && export RUNTIME_VERSION=$(helm search repo dapr/dapr --devel --versions | awk '/dapr\/dapr/ {print $3; exit}' )
|
||||||
|
echo "DAPR_RUNTIME_VERSION=$RUNTIME_VERSION" >> $GITHUB_ENV
|
||||||
|
echo "Found $RUNTIME_VERSION"
|
||||||
|
shell: bash
|
||||||
|
- name: Determine latest Dapr Cli version including Pre-releases
|
||||||
|
run: |
|
||||||
|
export CLI_VERSION=$(curl "https://api.github.com/repos/dapr/cli/releases?per_page=1&page=1" --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | jq '.[0].tag_name'| tr -d '",v')
|
||||||
|
echo "DAPR_CLI_VERSION=$CLI_VERSION" >> $GITHUB_ENV
|
||||||
|
echo "Found $CLI_VERSION"
|
||||||
|
shell: bash
|
||||||
|
- name: Set up Dapr CLI - Mac/Linux
|
||||||
|
if: matrix.os != 'windows-latest'
|
||||||
|
run: wget -q ${{ env.DAPR_INSTALL_URL }}/install.sh -O - | /bin/bash -s ${{ env.DAPR_CLI_VERSION }}
|
||||||
|
- name: Set up Dapr CLI - Windows
|
||||||
|
if: matrix.os == 'windows-latest'
|
||||||
|
run: powershell -Command "\$$script=iwr -useb ${{ env.DAPR_INSTALL_URL }}/install.ps1; \$$block=[ScriptBlock]::Create(\$$script); invoke-command -ScriptBlock \$$block -ArgumentList ${{ env.DAPR_CLI_VERSION }}"
|
||||||
|
- name: Install Dapr
|
||||||
|
run: |
|
||||||
|
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
|
||||||
|
dapr init --runtime-version=${{ env.DAPR_RUNTIME_VERSION }}
|
||||||
|
dapr --version
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Install utilities dependencies
|
||||||
|
run: |
|
||||||
|
echo "PATH=$PATH:$HOME/.local/bin" >> $GITHUB_ENV
|
||||||
|
pip3 install setuptools wheel
|
||||||
|
pip3 install mechanical-markdown
|
||||||
|
- name: Validate ${{ matrix.quickstart_language }} ${{ matrix.quickstart_variant }} workflows
|
||||||
|
run: |
|
||||||
|
pushd workflows/${{ matrix.quickstart_language }}/${{ matrix.quickstart_variant }}
|
||||||
|
make validate
|
||||||
|
popd
|
||||||
|
- name: Linkcheck README.md
|
||||||
|
run: |
|
||||||
|
make validate
|
|
@ -38,7 +38,7 @@ sleep: 15
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd ./order-processor
|
cd ./order-processor
|
||||||
dapr run --dapr-grpc-port 4001 dotnet run
|
dapr run dotnet run
|
||||||
```
|
```
|
||||||
|
|
||||||
<!-- END_STEP -->
|
<!-- END_STEP -->
|
||||||
|
|
|
@ -43,51 +43,44 @@ if (string.IsNullOrEmpty(daprPortStr))
|
||||||
using var daprClient = new DaprClientBuilder().Build();
|
using var daprClient = new DaprClientBuilder().Build();
|
||||||
|
|
||||||
// Start the console app
|
// Start the console app
|
||||||
while (true)
|
var health = await daprClient.CheckHealthAsync();
|
||||||
|
Console.WriteLine("Welcome to the workflows example!");
|
||||||
|
Console.WriteLine("In this example, you will be starting a workflow and obtaining the status.");
|
||||||
|
|
||||||
|
// Populate the store with items
|
||||||
|
RestockInventory();
|
||||||
|
|
||||||
|
// Main Loop
|
||||||
|
// Generate a unique ID for the workflow
|
||||||
|
string orderId = Guid.NewGuid().ToString()[..8];
|
||||||
|
string itemToPurchase = "Cars";
|
||||||
|
int ammountToPurchase = 10;
|
||||||
|
Console.WriteLine("In this quickstart, you will be purhasing {0} {1}.", ammountToPurchase, itemToPurchase);
|
||||||
|
|
||||||
|
// Construct the order
|
||||||
|
OrderPayload orderInfo = new OrderPayload(itemToPurchase, 15000, ammountToPurchase);
|
||||||
|
|
||||||
|
OrderPayload orderResponse;
|
||||||
|
string key;
|
||||||
|
// Ensure that the store has items
|
||||||
|
(orderResponse, key) = await daprClient.GetStateAndETagAsync<OrderPayload>(storeName, itemToPurchase);
|
||||||
|
|
||||||
|
// Start the workflow
|
||||||
|
Console.WriteLine("Starting workflow {0} purchasing {1} {2}", orderId, ammountToPurchase, itemToPurchase);
|
||||||
|
var response = await daprClient.StartWorkflowAsync(orderId, workflowComponent, workflowName, orderInfo, null, CancellationToken.None);
|
||||||
|
|
||||||
|
// Wait a second to allow workflow to start
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||||
|
|
||||||
|
var state = await daprClient.GetWorkflowAsync(orderId, workflowComponent, workflowName);
|
||||||
|
Console.WriteLine("Your workflow has started. Here is the status of the workflow: {0}", state);
|
||||||
|
while (state.metadata["dapr.workflow.runtime_status"].ToString() == "RUNNING")
|
||||||
{
|
{
|
||||||
var health = await daprClient.CheckHealthAsync();
|
await Task.Delay(TimeSpan.FromSeconds(5));
|
||||||
Console.WriteLine("Welcome to the workflows example!");
|
state = await daprClient.GetWorkflowAsync(orderId, workflowComponent, workflowName);
|
||||||
Console.WriteLine("In this example, you will be starting a workflow and obtaining the status.");
|
|
||||||
|
|
||||||
// Populate the store with items
|
|
||||||
RestockInventory();
|
|
||||||
|
|
||||||
// Can we remove the logging info?
|
|
||||||
|
|
||||||
// Main Loop
|
|
||||||
// Generate a unique ID for the workflow
|
|
||||||
string orderId = Guid.NewGuid().ToString()[..8];
|
|
||||||
string itemToPurchase = "Cars";
|
|
||||||
int ammountToPurchase = 10;
|
|
||||||
Console.WriteLine("In this quickstart, you will be purhasing {0} {1}.", ammountToPurchase, itemToPurchase);
|
|
||||||
|
|
||||||
// Construct the order
|
|
||||||
OrderPayload orderInfo = new OrderPayload(itemToPurchase, 15000, ammountToPurchase);
|
|
||||||
|
|
||||||
OrderPayload orderResponse;
|
|
||||||
string key;
|
|
||||||
// Ensure that the store has items
|
|
||||||
(orderResponse, key) = await daprClient.GetStateAndETagAsync<OrderPayload>(storeName, itemToPurchase);
|
|
||||||
|
|
||||||
// Start the workflow
|
|
||||||
Console.WriteLine("Starting workflow {0} purchasing {1} {2}", orderId, ammountToPurchase, itemToPurchase);
|
|
||||||
var response = await daprClient.StartWorkflowAsync(orderId, workflowComponent, workflowName, orderInfo, null, CancellationToken.None);
|
|
||||||
|
|
||||||
// Wait a second to allow workflow to start
|
|
||||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
|
||||||
|
|
||||||
var state = await daprClient.GetWorkflowAsync(orderId, workflowComponent, workflowName);
|
|
||||||
Console.WriteLine("Your workflow has started. Here is the status of the workflow: {0}", state);
|
|
||||||
while (state.metadata["dapr.workflow.runtime_status"].ToString() == "RUNNING")
|
|
||||||
{
|
|
||||||
await Task.Delay(TimeSpan.FromSeconds(5));
|
|
||||||
state = await daprClient.GetWorkflowAsync(orderId, workflowComponent, workflowName);
|
|
||||||
}
|
|
||||||
Console.WriteLine("Your workflow has completed: {0}", JsonSerializer.Serialize(state));
|
|
||||||
Console.WriteLine("Workflow Status: {0}", state.metadata["dapr.workflow.runtime_status"]);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
Console.WriteLine("Your workflow has completed: {0}", JsonSerializer.Serialize(state));
|
||||||
|
Console.WriteLine("Workflow Status: {0}", state.metadata["dapr.workflow.runtime_status"]);
|
||||||
|
|
||||||
void RestockInventory()
|
void RestockInventory()
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Dapr.AspNetCore" Version="1.10.0-rc01" />
|
<PackageReference Include="Dapr.AspNetCore" Version="1.10.0-rc02" />
|
||||||
<PackageReference Include="Dapr.Workflow" Version="1.10.0-rc01" />
|
<PackageReference Include="Dapr.Workflow" Version="1.10.0-rc02" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Reference in New Issue