-
Notifications
You must be signed in to change notification settings - Fork 9
feat: Add C# SDK #140
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
Open
lox
wants to merge
9
commits into
main
Choose a base branch
from
add-csharp-sdk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: Add C# SDK #140
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bc8a400
feat: add C# SDK
lox 87c1e15
feat: add C# SDK CI/CD integration, example app, and documentation
lox 6c48b6a
fix: address PR review feedback
lox a81d864
fix: add .NET SDK to Docker image for C# builds
lox 0ef7626
feat: add CSharp code generation support to types
lox dfdc34a
fix: add gen:types-csharp target for CI
lox bea510a
feat: refactor C# SDK to use generic union primitives
lox ef7e557
revert: remove generic union types, use simpler object? approach
lox e60b4c3
fix: remove Plugin class, improve Plugins/Secrets docs
lox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,3 +26,7 @@ Gemfile.lock | |
| Thumbs.db | ||
| .vscode | ||
| .zed | ||
|
|
||
| # C# build artifacts | ||
| bin/ | ||
| obj/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,10 @@ RUN mise install [email protected] && \ | |
| RUN mise install [email protected] && \ | ||
| mise use --global [email protected] | ||
|
|
||
| # .NET version support: https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core | ||
| RUN mise install dotnet@9 && \ | ||
| mise use --global dotnet@9 | ||
|
|
||
| # Install Python tools. | ||
| RUN pip install --no-cache-dir uv black | ||
| RUN npm install -g nx | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="../../sdk/csharp/src/Buildkite.Sdk/Buildkite.Sdk.csproj" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using System; | ||
| using System.IO; | ||
| using Buildkite.Sdk; | ||
| using Buildkite.Sdk.Schema; | ||
|
|
||
| var pipeline = new Pipeline(); | ||
|
|
||
| pipeline.AddStep(new CommandStep | ||
| { | ||
| Label = "some-label", | ||
| Command = "echo 'Hello, world!'" | ||
| }); | ||
|
|
||
| Directory.CreateDirectory("../../out/apps/csharp"); | ||
|
|
||
| var json = pipeline.ToJson(); | ||
| File.WriteAllText("../../out/apps/csharp/pipeline.json", json); | ||
|
|
||
| var yaml = pipeline.ToYaml(); | ||
| File.WriteAllText("../../out/apps/csharp/pipeline.yaml", yaml); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| { | ||
| "name": "app-csharp", | ||
| "$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
| "sourceRoot": "apps/csharp", | ||
| "projectType": "application", | ||
| "tags": [], | ||
| "targets": { | ||
| "install": { | ||
| "executor": "nx:run-commands", | ||
| "options": { | ||
| "commands": ["dotnet restore"], | ||
| "cwd": "apps/csharp" | ||
| } | ||
| }, | ||
| "clean": { | ||
| "executor": "nx:run-commands", | ||
| "options": { | ||
| "commands": ["dotnet clean", "rimraf bin", "rimraf obj"], | ||
| "cwd": "apps/csharp" | ||
| }, | ||
| "cache": false | ||
| }, | ||
| "format": { | ||
| "executor": "nx:run-commands", | ||
| "options": { | ||
| "commands": ["dotnet format"], | ||
| "cwd": "apps/csharp" | ||
| }, | ||
| "cache": false | ||
| }, | ||
| "build": { | ||
| "executor": "nx:run-commands", | ||
| "outputs": ["{workspaceRoot}/dist/apps/csharp"], | ||
| "options": { | ||
| "commands": [ | ||
| "rimraf ../../dist/apps/csharp", | ||
| "mkdir -p ../../dist/apps/csharp", | ||
| "dotnet build --configuration Release --output ../../dist/apps/csharp" | ||
| ], | ||
| "cwd": "apps/csharp", | ||
| "parallel": false | ||
| }, | ||
| "cache": false | ||
| }, | ||
| "run": { | ||
| "executor": "nx:run-commands", | ||
| "dependsOn": ["build"], | ||
| "options": { | ||
| "commands": ["dotnet run"], | ||
| "cwd": "apps/csharp" | ||
| } | ||
| }, | ||
| "test": { | ||
| "options": { | ||
| "passWithNoTests": true | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/buildkite/buildkite-sdk/internal/gen/csharp" | ||
| "github.com/buildkite/buildkite-sdk/internal/gen/types" | ||
| "github.com/buildkite/buildkite-sdk/internal/gen/utils" | ||
| ) | ||
|
|
||
| func generateCSharpTypes( | ||
| generator types.PipelineSchemaGenerator, | ||
| outDir string, | ||
| ) error { | ||
| // Track written types and their dependencies for ordering | ||
| writtenTypes := make(map[string]bool) | ||
| allTypes := make(map[string]types.Value) | ||
| allDeps := make(map[string][]string) | ||
|
|
||
| // First pass: convert all definitions to values | ||
| for _, name := range generator.Definitions.Keys() { | ||
| prop, err := generator.Definitions.Get(name) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| value, deps, err := generator.PropertyDefinitionToValue(name, prop) | ||
| if err != nil { | ||
| return fmt.Errorf("converting property definition to value: %v", err) | ||
| } | ||
|
|
||
| allTypes[name] = value | ||
| allDeps[name] = deps | ||
| } | ||
|
|
||
| // Second pass: write types in dependency order | ||
| var writeType func(name string) error | ||
| writeType = func(name string) error { | ||
| if writtenTypes[name] { | ||
| return nil | ||
| } | ||
|
|
||
| // Write dependencies first | ||
| for _, dep := range allDeps[name] { | ||
| if err := writeType(dep); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| value, exists := allTypes[name] | ||
| if !exists { | ||
| return nil // Reference to external type | ||
| } | ||
|
|
||
| contents, err := value.CSharp() | ||
| if err != nil { | ||
| return fmt.Errorf("generating C# for [%s]: %v", name, err) | ||
| } | ||
|
|
||
| if contents == "" { | ||
| writtenTypes[name] = true | ||
| return nil | ||
| } | ||
|
|
||
| fileName := fmt.Sprintf("%s/%s.cs", outDir, utils.ToTitleCase(name)) | ||
| file := csharp.NewCSharpFile( | ||
| "Buildkite.Sdk.Schema", | ||
| fileName, | ||
| []string{ | ||
| "System.Collections.Generic", | ||
| "System.Text.Json.Serialization", | ||
| }, | ||
| contents, | ||
| ) | ||
|
|
||
| if err := file.Write(); err != nil { | ||
| return fmt.Errorf("writing file [%s]: %v", fileName, err) | ||
| } | ||
|
|
||
| writtenTypes[name] = true | ||
| return nil | ||
| } | ||
|
|
||
| // Write all types | ||
| for _, name := range generator.Definitions.Keys() { | ||
| if err := writeType(name); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| // Generate the main BuildkitePipeline class | ||
| pipelineContents, err := generator.GenerateCSharpPipelineSchema() | ||
| if err != nil { | ||
lox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return fmt.Errorf("generating pipeline schema: %v", err) | ||
| } | ||
|
|
||
| pipelineFile := csharp.NewCSharpFile( | ||
| "Buildkite.Sdk.Schema", | ||
| fmt.Sprintf("%s/BuildkitePipeline.cs", outDir), | ||
| []string{ | ||
| "System.Collections.Generic", | ||
| "System.Text.Json.Serialization", | ||
| }, | ||
| pipelineContents, | ||
| ) | ||
|
|
||
| if err := pipelineFile.Write(); err != nil { | ||
| return fmt.Errorf("writing pipeline file: %v", err) | ||
| } | ||
|
|
||
| // Generate interfaces file | ||
| interfacesContents := csharp.GenerateInterfaces() | ||
| interfacesFile := csharp.NewCSharpFile( | ||
| "Buildkite.Sdk.Schema", | ||
| fmt.Sprintf("%s/Interfaces.cs", outDir), | ||
| []string{ | ||
| "System.Collections.Generic", | ||
| "System.Text.Json.Serialization", | ||
| }, | ||
| interfacesContents, | ||
| ) | ||
|
|
||
| if err := interfacesFile.Write(); err != nil { | ||
| return fmt.Errorf("writing interfaces file: %v", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.