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

chore: try to run swift test like we do for android #648

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 11 additions & 2 deletions .github/workflows/package-ffi-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ jobs:
notify:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
platform:
- name: Android
workflow: test-android-sdk.yml

- name: iOS
workflow: test-swift-sdk.yml

if: github.repository == 'flipt-io/flipt-client-sdks'
steps:
- name: Generate token
Expand All @@ -173,9 +182,9 @@ jobs:
private_key: ${{ secrets.FLIPT_RELEASE_BOT_APP_PEM }}
installation_id: ${{ secrets.FLIPT_RELEASE_BOT_INSTALLATION_ID }}

- name: Trigger Test Android SDK
- name: "Trigger Test ${{ matrix.platform.name }} SDK"
run: |
curl -X POST -H "Authorization: Bearer ${{ steps.generate_token.outputs.token }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/flipt-io/flipt-client-sdks/actions/workflows/test-android-sdk.yml/dispatches \
https://api.github.com/repos/flipt-io/flipt-client-sdks/actions/workflows/${{ matrix.platform.workflow }}/dispatches \
-d '{"ref":"${{ github.head_ref }}", "inputs":{"caller_run_id":"${{ github.run_id }}"}}'
86 changes: 68 additions & 18 deletions .github/workflows/test-swift-sdk.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
name: Test Swift SDK
on:
push:
branches:
- main
pull_request:
branches-ignore:
- release/*
workflow_dispatch:
inputs:
caller_run_id:
type: string
required: true

permissions:
contents: write
Expand All @@ -16,7 +14,13 @@ jobs:
test:
name: Integration Tests
runs-on: macos-latest
timeout-minutes: 10
steps:
- name: Install Swift
uses: swift-actions/setup-swift@v2
with:
swift-version: "5.9"

- name: Checkout Sources
uses: actions/checkout@v4

Expand All @@ -25,28 +29,74 @@ jobs:
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install Rust
uses: actions-rs/toolchain@v1
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
with:
toolchain: 1.75.0
override: true
app_id: ${{ secrets.FLIPT_RELEASE_BOT_APP_ID }}
private_key: ${{ secrets.FLIPT_RELEASE_BOT_APP_PEM }}
installation_id: ${{ secrets.FLIPT_RELEASE_BOT_INSTALLATION_ID }}

- name: Install Swift
uses: swift-actions/setup-swift@v2
- name: Download Artifact (iOS arm64)
uses: actions/download-artifact@v4
with:
swift-version: "5.9"
github-token: ${{ steps.generate_token.outputs.token }}
name: flipt-engine-ffi-iOS-arm64.tar.gz
path: /tmp
run-id: ${{ inputs.caller_run_id }}

- name: Download Artifact (iOS arm64 sim)
uses: actions/download-artifact@v4
with:
github-token: ${{ steps.generate_token.outputs.token }}
name: flipt-engine-ffi-iOS-arm64-sim.tar.gz
path: /tmp
run-id: ${{ inputs.caller_run_id }}

- name: Download Artifact (Darwin arm64)
uses: actions/download-artifact@v4
with:
github-token: ${{ steps.generate_token.outputs.token }}
name: flipt-engine-ffi-Darwin-arm64.tar.gz
path: /tmp
run-id: ${{ inputs.caller_run_id }}

- name: Extract Artifacts
run: |
mkdir -p /tmp/flipt-engine-ffi-iOS-arm64
mkdir -p /tmp/flipt-engine-ffi-iOS-arm64-sim
mkdir -p /tmp/flipt-engine-ffi-Darwin-arm64
tar -xzvf /tmp/flipt-engine-ffi-iOS-arm64.tar.gz -C /tmp/flipt-engine-ffi-iOS-arm64
tar -xzvf /tmp/flipt-engine-ffi-iOS-arm64-sim.tar.gz -C /tmp/flipt-engine-ffi-iOS-arm64-sim
tar -xzvf /tmp/flipt-engine-ffi-Darwin-arm64.tar.gz -C /tmp/flipt-engine-ffi-Darwin-arm64

- name: Run tree
run: |
brew install tree
tree flipt-engine-ffi/include

- name: XCode Build
run: |
xcodebuild -create-xcframework \
-library /tmp/flipt-engine-ffi-iOS-arm64/target/aarch64-apple-ios/release/libfliptengine.a -headers ../flipt-engine-ffi/include/ \
-library /tmp/flipt-engine-ffi-iOS-arm64-sim/target/aarch64-apple-ios-sim/release/libfliptengine.a -headers ../flipt-engine-ffi/include/ \
-library /tmp/flipt-engine-ffi-Darwin-arm64/target/aarch64-apple-darwin/release/libfliptengine.a -headers ../flipt-engine-ffi/include/ \
-output ../flipt-client-swift/Sources/FliptEngineFFI.xcframework

- name: Run flipt
- name: Run Flipt
env:
FLIPT_STORAGE_TYPE: "local"
FLIPT_STORAGE_LOCAL_PATH: "./test/fixtures/testdata"
FLIPT_AUTHENTICATION_REQUIRED: true
FLIPT_AUTHENTICATION_METHODS_TOKEN_ENABLED: true
FLIPT_AUTHENTICATION_METHODS_TOKEN_BOOTSTRAP_TOKEN: "secret"
run: flipt&

- name: Build Engine
- name: Wait for Flipt to be ready
run: |
pushd ./flipt-engine-ffi
./build.sh swift
popd
while ! curl -s http://0.0.0.0:8080/health | grep -q "SERVING"; do
sleep 1
done

- name: Run Integration Tests
env:
Expand Down
68 changes: 36 additions & 32 deletions test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func main() {
}
}

func args(args string, a ...any) []string {
return strings.Split(fmt.Sprintf(args, a...), " ")
}

func run() error {
tests := make(map[string]integrationTestFn, len(sdkToFn))

Expand Down Expand Up @@ -83,9 +87,9 @@ func run() error {

flipt := client.Container().From("flipt/flipt:latest").
WithUser("root").
WithExec([]string{"mkdir", "-p", "/var/data/flipt"}).
WithExec(args("mkdir -p /var/data/flipt")).
WithDirectory("/var/data/flipt", dir.Directory("test/fixtures/testdata")).
WithExec([]string{"chown", "-R", "flipt:flipt", "/var/data/flipt"}).
WithExec(args("chown -R flipt:flipt /var/data/flipt")).
WithUser("flipt").
WithEnvVariable("FLIPT_STORAGE_TYPE", "local").
WithEnvVariable("FLIPT_STORAGE_LOCAL_PATH", "/var/data/flipt").
Expand Down Expand Up @@ -165,7 +169,7 @@ func getFFITestContainer(_ context.Context, client *dagger.Client, hostDirectory
}).
WithDirectory("/src/flipt-evaluation", hostDirectory.Directory("flipt-evaluation")).
WithFile("/src/Cargo.toml", hostDirectory.File("Cargo.toml")).
WithExec([]string{"cargo", "build", "-p", "flipt-engine-ffi", "--release"}) // Build the dynamic library
WithExec(args("cargo build -p flipt-engine-ffi --release")) // Build the dynamic library
}

// getWasmTestContainer builds the wasm module for the Rust core, and the Flipt container for the client libraries to run
Expand All @@ -179,16 +183,16 @@ func getWasmTestContainer(_ context.Context, client *dagger.Client, hostDirector
}).
WithDirectory("/src/flipt-evaluation", hostDirectory.Directory("flipt-evaluation")).
WithFile("/src/Cargo.toml", hostDirectory.File("Cargo.toml")).
WithExec([]string{"cargo", "build", "-p", "flipt-engine-wasm", "--release"}) // Build the wasm module
WithExec(args("cargo build -p flipt-engine-wasm --release")) // Build the wasm module

if architecture == "arm64" {
container = container.WithExec([]string{"apt-get", "update"}).
WithExec([]string{"apt-get", "-y", "install", "binaryen"})
container = container.WithExec(args("apt-get update")).
WithExec(args("apt-get -y install binaryen"))
}

return container.WithExec([]string{"cargo", "install", "wasm-pack"}). // Install wasm-pack
WithWorkdir("/src/flipt-engine-wasm").
WithExec([]string{"wasm-pack", "build", "--target", target}) // Build the wasm package
return container.WithExec(args("cargo install wasm-pack")). // Install wasm-pack
WithWorkdir("/src/flipt-engine-wasm").
WithExec(args("wasm-pack build --target %s", target)) // Build the wasm package
}

// pythonTests runs the python integration test suite against a container running Flipt.
Expand All @@ -201,8 +205,8 @@ func pythonTests(ctx context.Context, root *dagger.Container, t *testCase) error
WithServiceBinding("flipt", t.flipt.WithExec(nil).AsService()).
WithEnvVariable("FLIPT_URL", "http://flipt:8080").
WithEnvVariable("FLIPT_AUTH_TOKEN", "secret").
WithExec([]string{"poetry", "install", "--without=dev"}).
WithExec([]string{"poetry", "run", "test"}).
WithExec(args("poetry install --without=dev")).
WithExec(args("poetry run test")).
Sync(ctx)

return err
Expand All @@ -211,8 +215,8 @@ func pythonTests(ctx context.Context, root *dagger.Container, t *testCase) error
// goTests runs the golang integration test suite against a container running Flipt.
func goTests(ctx context.Context, root *dagger.Container, t *testCase) error {
_, err := root.From("golang:1.21.3-bookworm").
WithExec([]string{"apt-get", "update"}).
WithExec([]string{"apt-get", "-y", "install", "build-essential"}).
WithExec(args("apt-get update")).
WithExec(args("apt-get -y install build-essential")).
WithWorkdir("/src").
WithDirectory("/src", t.dir.Directory("flipt-client-go")).
WithFile(fmt.Sprintf("/src/ext/linux_%s/libfliptengine.so", architecture), t.test.File(libFile)).
Expand All @@ -224,8 +228,8 @@ func goTests(ctx context.Context, root *dagger.Container, t *testCase) error {
// modify the LD_LIBRARY_PATH variable to inform the linker different locations for
// dynamic libraries.
WithEnvVariable("LD_LIBRARY_PATH", fmt.Sprintf("/src/ext/linux_%s:$LD_LIBRARY_PATH", architecture)).
WithExec([]string{"go", "mod", "download"}).
WithExec([]string{"go", "test", "./..."}).
WithExec(args("go mod download")).
WithExec(args("go test ./...")).
Sync(ctx)

return err
Expand All @@ -244,9 +248,9 @@ func nodeTests(ctx context.Context, root *dagger.Container, t *testCase) error {
WithServiceBinding("flipt", t.flipt.WithExec(nil).AsService()).
WithEnvVariable("FLIPT_URL", "http://flipt:8080").
WithEnvVariable("FLIPT_AUTH_TOKEN", "secret").
WithExec([]string{"npm", "install"}).
WithExec([]string{"npm", "run", "build"}).
WithExec([]string{"npm", "test"}).
WithExec(args("npm install")).
WithExec(args("npm run build")).
WithExec(args("npm test")).
Sync(ctx)

return err
Expand All @@ -261,8 +265,8 @@ func rubyTests(ctx context.Context, root *dagger.Container, t *testCase) error {
WithServiceBinding("flipt", t.flipt.WithExec(nil).AsService()).
WithEnvVariable("FLIPT_URL", "http://flipt:8080").
WithEnvVariable("FLIPT_AUTH_TOKEN", "secret").
WithExec([]string{"bundle", "install"}).
WithExec([]string{"bundle", "exec", "rspec"}).
WithExec(args("bundle install")).
WithExec(args("bundle exec rspec")).
Sync(ctx)

return err
Expand All @@ -285,7 +289,7 @@ func javaTests(ctx context.Context, root *dagger.Container, t *testCase) error {
WithServiceBinding("flipt", t.flipt.WithExec(nil).AsService()).
WithEnvVariable("FLIPT_URL", "http://flipt:8080").
WithEnvVariable("FLIPT_AUTH_TOKEN", "secret").
WithExec([]string{"gradle", "test"}).
WithExec(args("gradle test")).
Sync(ctx)

return err
Expand All @@ -304,9 +308,9 @@ func browserTests(ctx context.Context, root *dagger.Container, t *testCase) erro
WithServiceBinding("flipt", t.flipt.WithExec(nil).AsService()).
WithEnvVariable("FLIPT_URL", "http://flipt:8080").
WithEnvVariable("FLIPT_AUTH_TOKEN", "secret").
WithExec([]string{"npm", "install"}).
WithExec([]string{"npm", "run", "build"}).
WithExec([]string{"npm", "test"}).
WithExec(args("npm install")).
WithExec(args("npm run build")).
WithExec(args("npm test")).
Sync(ctx)

return err
Expand All @@ -320,9 +324,9 @@ func reactTests(ctx context.Context, root *dagger.Container, t *testCase) error
WithDirectory("/src", t.dir.Directory("flipt-client-react"), dagger.ContainerWithDirectoryOpts{
Exclude: []string{".node_modules/", ".gitignore", "dist/"},
}).
WithExec([]string{"npm", "install"}).
WithExec([]string{"npm", "run", "build"}).
WithExec([]string{"npm", "test"}).
WithExec(args("npm install")).
WithExec(args("npm run build")).
WithExec(args("npm test")).
Sync(ctx)

return err
Expand All @@ -339,8 +343,8 @@ func dartTests(ctx context.Context, root *dagger.Container, t *testCase) error {
WithServiceBinding("flipt", t.flipt.WithExec(nil).AsService()).
WithEnvVariable("FLIPT_URL", "http://flipt:8080").
WithEnvVariable("FLIPT_AUTH_TOKEN", "secret").
WithExec([]string{"dart", "pub", "get"}).
WithExec([]string{"dart", "test"}).
WithExec(args("dart pub get")).
WithExec(args("dart test")).
Sync(ctx)

return err
Expand All @@ -357,9 +361,9 @@ func csharpTests(ctx context.Context, root *dagger.Container, t *testCase) error
WithServiceBinding("flipt", t.flipt.WithExec(nil).AsService()).
WithEnvVariable("FLIPT_URL", "http://flipt:8080").
WithEnvVariable("FLIPT_AUTH_TOKEN", "secret").
WithExec([]string{"dotnet", "restore"}).
WithExec([]string{"dotnet", "build"}).
WithExec([]string{"dotnet", "test"}).
WithExec(args("dotnet restore")).
WithExec(args("dotnet build")).
WithExec(args("dotnet test")).
Sync(ctx)

return err
Expand Down
Loading