Skip to content

Commit

Permalink
maint: Adds update to the build workflow (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickfloyd committed Mar 29, 2024
1 parent fb91690 commit 18f7c63
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions post-processors/csharp/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package main

import (
"encoding/json"
"fmt"
"io/fs"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
Expand Down Expand Up @@ -55,6 +57,38 @@ func run() error {
}
}

initialDir, _ := os.Getwd() // Used for the dotnet add package command and traversal
packageInstallDir := fmt.Sprintf("%s/../dotnet-sdk/src", initialDir)

cmd := exec.Command("kiota", "info", "-l", "CSharp", "--json")
cmd.Dir = dirPath

output, err := cmd.Output()

if err != nil {
return fmt.Errorf("could not run kiota info: %v\n", err)
}

var infoResult map[string]interface{}
if err := json.Unmarshal(output, &infoResult); err != nil {
return fmt.Errorf("could not parse kiota info output: %v", err)
}
deps := infoResult["dependencies"].([]interface{})

for _, d := range deps {
dep := d.(map[string]interface{})
name := dep["name"].(string)
version := dep["version"].(string)

cmd = exec.Command("dotnet", "add", "package", name, "--version", version)
cmd.Dir = packageInstallDir

_, err := cmd.Output()
if err != nil {
return fmt.Errorf("could not update dependency: %s\n - %v", dep, err)
}
fmt.Printf("installed dependency %s\n", dep)
}
return nil
}

Expand Down

0 comments on commit 18f7c63

Please sign in to comment.