Skip to content

Commit

Permalink
Merge branch 'main' into dotnet-after-1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cretz authored Sep 12, 2024
2 parents 689e232 + fb6ed5d commit 2a1167f
Show file tree
Hide file tree
Showing 12 changed files with 645 additions and 513 deletions.
107 changes: 78 additions & 29 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,42 @@ on: # rebuild any PRs and main branch changes
push:
branches:
- main
workflow_dispatch:
inputs:
go_sdk_version:
default: ''
type: string
typescript_sdk_version:
default: ''
type: string
java_sdk_version:
default: ''
type: string
python_sdk_version:
default: ''
type: string
dotnet_sdk_version:
default: ''
type: string

concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
latest-sdk-versions:
runs-on: 'ubuntu-latest'
outputs:
go_latest: '1.28.1'
typescript_latest: '1.10.3'
java_latest: '1.25.0'
python_latest: '1.7.0'
csharp_latest: '1.2.0'
steps:
- run: 'echo noop'

# Build cli and harnesses
# Build cli and harnesses and get the latest SDK versions
build-go:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest] # windows-latest - like 8x slower. Excluded for now since we're just building.
runs-on: ${{ matrix.os }}
outputs:
go_latest: ${{ steps.latest_version.outputs.go_latest }}
typescript_latest: ${{ steps.latest_version.outputs.typescript_latest }}
java_latest: ${{ steps.latest_version.outputs.java_latest }}
python_latest: ${{ steps.latest_version.outputs.python_latest }}
csharp_latest: ${{ steps.latest_version.outputs.csharp_latest }}
steps:
- name: Print build information
run: 'echo head_ref: "$GITHUB_HEAD_REF", ref: "$GITHUB_REF", os: ${{ matrix.os }}'
Expand All @@ -39,6 +51,44 @@ jobs:

- run: go build -o temporal-features

- name: Get the latest release version
id: latest_version
run: |
go_latest="${{ github.event.inputs.go_sdk_version }}"
if [ -z "$go_latest" ]; then
go_latest=$(./temporal-features latest-sdk-version --lang go)
echo "Derived latest Go SDK release version: $go_latest"
fi
echo "go_latest=$go_latest" >> $GITHUB_OUTPUT
typescript_latest="${{ github.event.inputs.typescript_sdk_version }}"
if [ -z "$typescript_latest" ]; then
typescript_latest=$(./temporal-features latest-sdk-version --lang ts)
echo "Derived latest Typescript SDK release version: $typescript_latest"
fi
echo "typescript_latest=$typescript_latest" >> $GITHUB_OUTPUT
java_latest="${{ github.event.inputs.java_sdk_version }}"
if [ -z "$java_latest" ]; then
java_latest=$(./temporal-features latest-sdk-version --lang java)
echo "Derived latest Java SDK release version: $java_latest"
fi
echo "java_latest=$java_latest" >> $GITHUB_OUTPUT
python_latest="${{ github.event.inputs.python_sdk_version }}"
if [ -z "$python_latest" ]; then
python_latest=$(./temporal-features latest-sdk-version --lang py)
echo "Derived latest Python SDK release version: $python_latest"
fi
echo "python_latest=$python_latest" >> $GITHUB_OUTPUT
csharp_latest="${{ github.event.inputs.dotnet_sdk_version }}"
if [ -z "$csharp_latest" ]; then
csharp_latest=$(./temporal-features latest-sdk-version --lang cs)
echo "Derived latest Dotnet SDK release version: $csharp_latest"
fi
echo "csharp_latest=$csharp_latest" >> $GITHUB_OUTPUT
build-ts:
strategy:
fail-fast: true
Expand Down Expand Up @@ -106,59 +156,58 @@ jobs:
- run: dotnet test

feature-tests-ts:
needs: latest-sdk-versions
needs: build-go
uses: ./.github/workflows/typescript.yaml
with:
version: ${{ needs.latest-sdk-versions.outputs.typescript_latest }}
version: ${{ needs.build-go.outputs.typescript_latest }}
version-is-repo-ref: false
features-repo-ref: ${{ github.head_ref }}
features-repo-path: ${{ github.event.pull_request.head.repo.full_name }}

feature-tests-go:
needs: latest-sdk-versions
needs: build-go
uses: ./.github/workflows/go.yaml
with:
version: ${{ needs.latest-sdk-versions.outputs.go_latest }}
version: ${{ needs.build-go.outputs.go_latest }}
version-is-repo-ref: false
features-repo-ref: ${{ github.head_ref }}
features-repo-path: ${{ github.event.pull_request.head.repo.full_name }}

feature-tests-python:
needs: latest-sdk-versions
needs: build-go
uses: ./.github/workflows/python.yaml
with:
version: ${{ needs.latest-sdk-versions.outputs.python_latest }}
version: ${{ needs.build-go.outputs.python_latest }}
version-is-repo-ref: false
features-repo-ref: ${{ github.head_ref }}
features-repo-path: ${{ github.event.pull_request.head.repo.full_name }}

feature-tests-java:
needs: latest-sdk-versions
needs: build-go
uses: ./.github/workflows/java.yaml
with:
version: 'v${{ needs.latest-sdk-versions.outputs.java_latest }}'
version: 'v${{ needs.build-go.outputs.java_latest }}'
version-is-repo-ref: false
features-repo-ref: ${{ github.head_ref }}
features-repo-path: ${{ github.event.pull_request.head.repo.full_name }}

feature-tests-dotnet:
needs: latest-sdk-versions
needs: build-go
uses: ./.github/workflows/dotnet.yaml
with:
version: ${{ needs.latest-sdk-versions.outputs.csharp_latest }}
version: ${{ needs.build-go.outputs.csharp_latest }}
version-is-repo-ref: false
features-repo-ref: ${{ github.head_ref }}
features-repo-path: ${{ github.event.pull_request.head.repo.full_name }}

build-docker-images:
needs: latest-sdk-versions
needs: build-go
uses: ./.github/workflows/all-docker-images.yaml
secrets: inherit
# TODO: Find some way to automatically upgrade to "latest"
with:
do-push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
go-ver: 'v${{ needs.latest-sdk-versions.outputs.go_latest }}'
ts-ver: 'v${{ needs.latest-sdk-versions.outputs.typescript_latest }}'
java-ver: 'v${{ needs.latest-sdk-versions.outputs.java_latest }}'
py-ver: 'v${{ needs.latest-sdk-versions.outputs.python_latest }}'
cs-ver: 'v${{ needs.latest-sdk-versions.outputs.csharp_latest }}'
go-ver: 'v${{ needs.build-go.outputs.go_latest }}'
ts-ver: 'v${{ needs.build-go.outputs.typescript_latest }}'
java-ver: 'v${{ needs.build-go.outputs.java_latest }}'
py-ver: 'v${{ needs.build-go.outputs.python_latest }}'
cs-ver: 'v${{ needs.build-go.outputs.csharp_latest }}'
2 changes: 1 addition & 1 deletion cmd/build_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func buildImageCmd() *cli.Command {
var config ImageBuildConfig
return &cli.Command{
Name: "build-image",
Usage: "build a 'prepared' single language docker image",
Usage: "Build a 'prepared' single language docker image",
Flags: config.flags(),
Action: func(ctx *cli.Context) error {
return NewImageBuilder(config).BuildImage(ctx.Context)
Expand Down
1 change: 1 addition & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewApp() *cli.App {
runCmd(),
buildImageCmd(),
publishImageCmd(),
latestSdkVersionCmd(),
},
}
}
65 changes: 65 additions & 0 deletions cmd/latest_sdk_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package cmd

import (
"encoding/json"
"fmt"
"io"
"net/http"
"strings"

"github.com/urfave/cli/v2"
)

func latestSdkVersionCmd() *cli.Command {
var config LatestSdkVersionConfig
return &cli.Command{
Name: "latest-sdk-version",
Usage: "get the latest SDK version",
Flags: config.flags(),
Action: func(ctx *cli.Context) error {
return getLatestSdkVersion(config)
},
}
}

type LatestSdkVersionConfig struct {
Lang string
}

func (p *LatestSdkVersionConfig) flags() []cli.Flag {
return []cli.Flag{
langFlag(&p.Lang),
}
}

func getLatestSdkVersion(config LatestSdkVersionConfig) error {
var sdk string
sdk, err := expandLangName(config.Lang)
if err != nil {
return err
}

url := fmt.Sprintf("https://api.github.com/repos/temporalio/sdk-%s/releases/latest", sdk)
resp, err := http.Get(url)
if err != nil {
return fmt.Errorf("failed to query the GH API for SDK version: %w", err)
}

defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read body of GitHub Get request: %w", err)
}

var version struct {
TagName string `json:"tag_name"`
}
err = json.Unmarshal(body, &version)
if err != nil {
return fmt.Errorf("failed to decode json response: %w", err)
}

fmt.Println(strings.TrimPrefix(version.TagName, "v"))

return nil
}
2 changes: 1 addition & 1 deletion cmd/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func prepareCmd() *cli.Command {
var config PrepareConfig
return &cli.Command{
Name: "prepare",
Usage: "prepare an SDK for execution",
Usage: "Prepare an SDK for execution",
Flags: config.flags(),
Action: func(ctx *cli.Context) error {
return NewPreparer(config).Prepare(ctx.Context)
Expand Down
2 changes: 1 addition & 1 deletion cmd/push_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func publishImageCmd() *cli.Command {
var config PublishImageConfig
return &cli.Command{
Name: "push-images",
Usage: "Push docker image(s) to our test repository. Used by CI.",
Usage: "Push docker image(s) to our test repository. Used by CI",
Flags: config.flags(),
Action: func(ctx *cli.Context) error {
return publishImages(config)
Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func runCmd() *cli.Command {
var config RunConfig
return &cli.Command{
Name: "run",
Usage: "run a test or set of tests",
Usage: "Run a test or set of tests",
Flags: config.flags(),
Action: func(ctx *cli.Context) error {
return NewRunner(config).Run(ctx.Context, ctx.Args().Slice())
Expand Down
31 changes: 19 additions & 12 deletions features/update/async_accepted/feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,28 @@ public Run execute(Runner runner) throws Exception {
Assertions.assertEquals(UPDATE_RESULT, handle.getResultAsync().get());
// issue an async update that should throw
updateId = UUID.randomUUID().toString();
UpdateHandle<Integer> errorHandle =
untypedStub.startUpdate(
UpdateOptions.newBuilder(Integer.class)
.setUpdateName("update")
.setUpdateId(updateId)
.setFirstExecutionRunId(run.execution.getRunId())
.setWaitForStage(WorkflowUpdateStage.ACCEPTED)
.build(),
false);
try {
// If the worker accepts the update, but fails it in the same workflow task
// the update will be marked as failed and the exception may be thrown
// from startUpdate. This is not consistent with the behavior of the
// other SDKs.
UpdateHandle<Integer> errorHandle =
untypedStub.startUpdate(
UpdateOptions.newBuilder(Integer.class)
.setUpdateName("update")
.setUpdateId(updateId)
.setFirstExecutionRunId(run.execution.getRunId())
.setWaitForStage(WorkflowUpdateStage.ACCEPTED)
.build(),
false);
errorHandle.getResultAsync().get();
Assertions.fail("unreachable");
} catch (ExecutionException e) {
Assertions.assertTrue(e.getCause() instanceof WorkflowUpdateException);
WorkflowUpdateException wue = (WorkflowUpdateException) e.getCause();
} catch (Throwable e) {
if (e instanceof ExecutionException) {
e = e.getCause();
}
Assertions.assertTrue(e instanceof WorkflowUpdateException);
WorkflowUpdateException wue = (WorkflowUpdateException) e;
Assertions.assertTrue(wue.getCause() instanceof ApplicationFailure);
Assertions.assertEquals("Failure", ((ApplicationFailure) wue.getCause()).getType());
Assertions.assertEquals(
Expand Down
5 changes: 4 additions & 1 deletion features/update/async_accepted/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { Feature } from '@temporalio/harness';
import * as assert from 'assert';
import ms from 'ms';
import { Duration, StringValue } from '@temporalio/common';
import { WorkflowUpdateStage } from '@temporalio/client';

const myUpdate = wf.defineUpdate<void, [Duration, boolean]>('myUpdate');
const requestedSleep = '2s';

export const feature = new Feature({
workflow,
checkResult: async (_, handle) => {
const timeToAccept = await time(handle.startUpdate(myUpdate, { args: [requestedSleep, false] }));
const timeToAccept = await time(
handle.startUpdate(myUpdate, { args: [requestedSleep, false], waitForStage: WorkflowUpdateStage.ACCEPTED })
);
const timeToComplete = await time(handle.executeUpdate(myUpdate, { args: [requestedSleep, false] }));
assert.equal(
ms(timeToAccept) < ms(requestedSleep),
Expand Down
12 changes: 9 additions & 3 deletions features/update/basic_async/feature.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WorkflowUpdateFailedError } from '@temporalio/client';
import { WorkflowUpdateFailedError, WorkflowUpdateStage } from '@temporalio/client';
import { Feature } from '@temporalio/harness';
import * as wf from '@temporalio/workflow';
import * as assert from 'assert';
Expand Down Expand Up @@ -29,7 +29,10 @@ export async function workflow(): Promise<string> {
export const feature = new Feature({
workflow,
checkResult: async (runner, handle) => {
const badUpdateHandle = await handle.startUpdate(myUpdate, { args: ['invalid-arg'] });
const badUpdateHandle = await handle.startUpdate(myUpdate, {
args: ['invalid-arg'],
waitForStage: WorkflowUpdateStage.ACCEPTED,
});
try {
await badUpdateHandle.result();
throw 'Expected update to fail';
Expand All @@ -39,7 +42,10 @@ export const feature = new Feature({
}
}

const updateHandle = await handle.startUpdate(myUpdate, { args: ['update-arg'] });
const updateHandle = await handle.startUpdate(myUpdate, {
args: ['update-arg'],
waitForStage: WorkflowUpdateStage.ACCEPTED,
});
const updateResult = await updateHandle.result();
assert.equal(updateResult, 'update-result');
const workflowResult = await runner.waitForRunResult(handle);
Expand Down
Loading

0 comments on commit 2a1167f

Please sign in to comment.