Skip to content

Commit 372011c

Browse files
Optimize CI wrapper tests with prebuilt CLI
Co-authored-by: Ben Schellenberger <bschellenberger2600@users.noreply.github.com>
1 parent 366c69e commit 372011c

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
run: go vet ./...
8585

8686
- name: Check gofmt
87-
run: test -z "$(gofmt -l *.go)"
87+
run: test -z "$(gofmt -l .)"
8888

8989
- name: Run tests
9090
run: go test ./...
@@ -105,6 +105,16 @@ jobs:
105105
with:
106106
go-version: "stable"
107107

108+
- name: Build git-testkit CLI binary once
109+
shell: bash
110+
run: |
111+
mkdir -p bin
112+
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
113+
go build -o ./bin/git-testkit-cli.exe ./cmd/git-testkit-cli
114+
else
115+
go build -o ./bin/git-testkit-cli ./cmd/git-testkit-cli
116+
fi
117+
108118
- name: Setup Python
109119
uses: actions/setup-python@v5
110120
with:
@@ -119,13 +129,17 @@ jobs:
119129

120130
- name: Run Python wrapper smoke tests
121131
shell: bash
132+
env:
133+
GIT_TESTKIT_CLI: ${{ matrix.os == 'windows-latest' && './bin/git-testkit-cli.exe' || './bin/git-testkit-cli' }}
122134
run: |
123135
cd testkit/python
124136
python -m pip install -e ".[dev]"
125137
python -m pytest tests/test_fixtures.py tests/test_snapshots.py -v
126138
127139
- name: Run Java wrapper smoke tests
128140
shell: bash
141+
env:
142+
GIT_TESTKIT_CLI: ${{ matrix.os == 'windows-latest' && './bin/git-testkit-cli.exe' || './bin/git-testkit-cli' }}
129143
run: |
130144
cd testkit/java
131145
mvn -Dtest=CliBridgeTest,SampleRepoFlowSmoke,SampleSnapshotFlowSmoke test

testkit/java/src/main/java/io/gitfire/testkit/CliBridge.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private String toJson() {
151151
private final java.util.function.Function<String, CliResult> cliInvoker;
152152

153153
public CliBridge(Path workspaceRoot) {
154-
this(workspaceRoot, List.of("go", "run", "./cmd/git-testkit-cli"), null);
154+
this(workspaceRoot, defaultCliCommandArgs(), null);
155155
}
156156

157157
public CliBridge() {
@@ -163,7 +163,7 @@ public CliBridge(Path workspaceRoot, String cliCommand) {
163163
}
164164

165165
CliBridge(Path workspaceRoot, java.util.function.Function<String, CliResult> cliInvoker) {
166-
this(workspaceRoot, List.of("go", "run", "./cmd/git-testkit-cli"), cliInvoker);
166+
this(workspaceRoot, defaultCliCommandArgs(), cliInvoker);
167167
}
168168

169169
CliBridge(
@@ -182,6 +182,14 @@ private static List<String> shellCommand(String cliCommand) {
182182
return List.of("sh", "-lc", cliCommand);
183183
}
184184

185+
private static List<String> defaultCliCommandArgs() {
186+
String configuredCli = System.getenv("GIT_TESTKIT_CLI");
187+
if (configuredCli != null && !configuredCli.isBlank()) {
188+
return shellCommand(configuredCli);
189+
}
190+
return List.of("go", "run", "./cmd/git-testkit-cli");
191+
}
192+
185193
private static boolean isWindows() {
186194
return System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win");
187195
}

testkit/python/git_testkit/cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import json
4+
import os
45
import subprocess
56
from dataclasses import dataclass, field
67
from pathlib import Path
@@ -14,6 +15,9 @@ def _repo_root() -> Path:
1415

1516

1617
def _cli_cmd() -> list[str]:
18+
cli = os.environ.get("GIT_TESTKIT_CLI", "").strip()
19+
if cli:
20+
return [cli]
1721
return ["go", "run", "./cmd/git-testkit-cli"]
1822

1923

0 commit comments

Comments
 (0)