MCPcopy Index your code
hub / github.com/github/copilot-sdk / validateGo

Function validateGo

scripts/docs-validation/validate.ts:212–278  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

210}
211
212async function validateGo(): Promise<ValidationResult[]> {
213 const results: ValidationResult[] = [];
214 const goDir = path.join(VALIDATION_DIR, "go");
215 const manifest = loadManifest();
216
217 if (!fs.existsSync(goDir)) {
218 console.log(" No Go files to validate");
219 return results;
220 }
221
222 // Create a go.mod for the validation directory
223 const goMod = `module docs-validation
224
225go 1.21
226
227require github.com/github/copilot-sdk/go v0.0.0
228
229replace github.com/github/copilot-sdk/go => ${path.join(ROOT_DIR, "go")}
230`;
231 fs.writeFileSync(path.join(goDir, "go.mod"), goMod);
232
233 // Run go mod tidy to fetch dependencies
234 try {
235 execFileSync("go", ["mod", "tidy"], {
236 encoding: "utf-8",
237 cwd: goDir,
238 env: { ...process.env, GO111MODULE: "on" },
239 });
240 } catch (err: any) {
241 // go mod tidy might fail if there are syntax errors, continue anyway
242 }
243
244 const files = await glob("*.go", { cwd: goDir });
245
246 // Try to compile each file individually
247 for (const file of files) {
248 const fullPath = path.join(goDir, file);
249 const block = manifest.blocks.find((b) => b.outputFile === `go/${file}`);
250 const errors: string[] = [];
251
252 try {
253 // Use go vet for syntax and basic checks
254 execFileSync("go", ["build", "-o", "/dev/null", fullPath], {
255 encoding: "utf-8",
256 cwd: goDir,
257 env: { ...process.env, GO111MODULE: "on" },
258 });
259 } catch (err: any) {
260 const output = err.stdout || err.stderr || err.message || "";
261 errors.push(
262 ...output
263 .split("\n")
264 .filter((l: string) => l.trim() && !l.startsWith("#")),
265 );
266 }
267
268 results.push({
269 file: `go/${file}`,

Callers

nothing calls this directly

Calls 4

loadManifestFunction · 0.85
joinMethod · 0.80
logMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…