Skip to content
Draft
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
29 changes: 29 additions & 0 deletions cmd/lk/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,34 @@
})
}

// ciFromEnv reports the pipeline that started this run, so the dashboard can
// link a run back to it. GitHub Actions is the only provider recognized; nil
// means the run did not come from one.
func ciFromEnv() *livekit.SimulationRun_CI {

Check failure on line 567 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with python agent on ubuntu-latest

undefined: livekit.SimulationRun_CI

Check failure on line 567 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with node agent on ubuntu-latest

undefined: livekit.SimulationRun_CI

Check failure on line 567 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with python agent on ubuntu-latest

undefined: livekit.SimulationRun_CI

Check failure on line 567 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / Cross-build Windows artifacts (zig)

undefined: livekit.SimulationRun_CI

Check failure on line 567 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with python agent on macos-latest

undefined: livekit.SimulationRun_CI

Check failure on line 567 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with node agent on macos-latest

undefined: livekit.SimulationRun_CI

Check failure on line 567 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

undefined: livekit.SimulationRun_CI

Check failure on line 567 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / Cross-build Windows artifacts (zig)

undefined: livekit.SimulationRun_CI

Check failure on line 567 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / Build darwin (native)

undefined: livekit.SimulationRun_CI
if os.Getenv("GITHUB_ACTIONS") == "" {
return nil
}
// On a pull_request event GITHUB_REF_NAME is "<number>/merge", which names
// neither a branch nor a tag; the head ref is the branch under test.
ref := os.Getenv("GITHUB_REF_NAME")
if head := os.Getenv("GITHUB_HEAD_REF"); head != "" {
ref = head
}
var pullRequest string
if gitRef := os.Getenv("GITHUB_REF"); strings.HasPrefix(gitRef, "refs/pull/") {
pullRequest, _, _ = strings.Cut(strings.TrimPrefix(gitRef, "refs/pull/"), "/")
}
return &livekit.SimulationRun_CI{

Check failure on line 581 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with python agent on ubuntu-latest

undefined: livekit.SimulationRun_CI

Check failure on line 581 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with node agent on ubuntu-latest

undefined: livekit.SimulationRun_CI

Check failure on line 581 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with python agent on ubuntu-latest

undefined: livekit.SimulationRun_CI

Check failure on line 581 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / Cross-build Windows artifacts (zig)

undefined: livekit.SimulationRun_CI

Check failure on line 581 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with python agent on macos-latest

undefined: livekit.SimulationRun_CI

Check failure on line 581 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with node agent on macos-latest

undefined: livekit.SimulationRun_CI

Check failure on line 581 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

undefined: livekit.SimulationRun_CI

Check failure on line 581 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / Cross-build Windows artifacts (zig)

undefined: livekit.SimulationRun_CI

Check failure on line 581 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / Build darwin (native)

undefined: livekit.SimulationRun_CI
Provider: "github_actions",
CommitSha: os.Getenv("GITHUB_SHA"),
Ref: ref,
PullRequest: pullRequest,
RunUrl: fmt.Sprintf("%s/%s/actions/runs/%s",
os.Getenv("GITHUB_SERVER_URL"), os.Getenv("GITHUB_REPOSITORY"), os.Getenv("GITHUB_RUN_ID")),
Actor: os.Getenv("GITHUB_ACTOR"),
}
}

func createSimulationRun(ctx context.Context, c *simulateConfig) (string, *livekit.PresignedPostRequest, error) {
req := &livekit.SimulationRun_Create_Request{
AgentName: c.agentName,
Expand All @@ -569,6 +597,7 @@
BackgroundNoise: c.backgroundNoise,
LowQualityMicrophone: c.lowQualityMicrophone,
PacketLoss: c.packetLoss,
Ci: ciFromEnv(),

Check failure on line 600 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with python agent on ubuntu-latest

unknown field Ci in struct literal of type livekit.SimulationRun_Create_Request

Check failure on line 600 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with node agent on ubuntu-latest

unknown field Ci in struct literal of type livekit.SimulationRun_Create_Request

Check failure on line 600 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with python agent on ubuntu-latest

unknown field Ci in struct literal of type livekit.SimulationRun_Create_Request

Check failure on line 600 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / Cross-build Windows artifacts (zig)

unknown field Ci in struct literal of type livekit.SimulationRun_Create_Request

Check failure on line 600 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with python agent on macos-latest

unknown field Ci in struct literal of type livekit.SimulationRun_Create_Request

Check failure on line 600 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / lk agent with node agent on macos-latest

unknown field Ci in struct literal of type livekit.SimulationRun_Create_Request

Check failure on line 600 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unknown field Ci in struct literal of type livekit.SimulationRun_Create_Request (typecheck)

Check failure on line 600 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / Cross-build Windows artifacts (zig)

unknown field Ci in struct literal of type livekit.SimulationRun_Create_Request

Check failure on line 600 in cmd/lk/simulate.go

View workflow job for this annotation

GitHub Actions / Build darwin (native)

unknown field Ci in struct literal of type livekit.SimulationRun_Create_Request
}
if c.concurrency > 0 {
req.Concurrency = &c.concurrency
Expand Down
62 changes: 62 additions & 0 deletions cmd/lk/simulate_ci_env_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2026 LiveKit, Inc.
//
// 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.

package main

import "testing"

func TestCIFromEnvOutsideGitHubActions(t *testing.T) {
t.Setenv("GITHUB_ACTIONS", "")
if ci := ciFromEnv(); ci != nil {
t.Fatalf("expected no CI source, got %v", ci)
}
}

func TestCIFromEnvPullRequest(t *testing.T) {
t.Setenv("GITHUB_ACTIONS", "true")
t.Setenv("GITHUB_SHA", "abc123")
t.Setenv("GITHUB_REF", "refs/pull/42/merge")
t.Setenv("GITHUB_REF_NAME", "42/merge")
t.Setenv("GITHUB_HEAD_REF", "jason/feature")
t.Setenv("GITHUB_SERVER_URL", "https://github.com")
t.Setenv("GITHUB_REPOSITORY", "livekit/e2e")
t.Setenv("GITHUB_RUN_ID", "77")
t.Setenv("GITHUB_ACTOR", "u9g")

ci := ciFromEnv()
if ci.GetPullRequest() != "42" {
t.Errorf("pull request: got %q, want %q", ci.GetPullRequest(), "42")
}
if ci.GetRef() != "jason/feature" {
t.Errorf("ref: got %q, want %q", ci.GetRef(), "jason/feature")
}
if want := "https://github.com/livekit/e2e/actions/runs/77"; ci.GetRunUrl() != want {
t.Errorf("run url: got %q, want %q", ci.GetRunUrl(), want)
}
}

func TestCIFromEnvBranchPush(t *testing.T) {
t.Setenv("GITHUB_ACTIONS", "true")
t.Setenv("GITHUB_REF", "refs/heads/main")
t.Setenv("GITHUB_REF_NAME", "main")
t.Setenv("GITHUB_HEAD_REF", "")

ci := ciFromEnv()
if ci.GetRef() != "main" {
t.Errorf("ref: got %q, want %q", ci.GetRef(), "main")
}
if ci.GetPullRequest() != "" {
t.Errorf("pull request: got %q, want empty", ci.GetPullRequest())
}
}
Loading