-
Notifications
You must be signed in to change notification settings - Fork 0
Per-lib CI/release workflows and build.cs scripts #21
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Bullseye" Version="6.1.0" /> | ||
| <PackageReference Include="SimpleExec" Version="12.1.0" /> | ||
| </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,92 @@ | ||
| using static Bullseye.Targets; | ||
| using static SimpleExec.Command; | ||
|
|
||
| namespace BuildHelpers; | ||
|
|
||
| /// <summary> | ||
| /// Registers build targets for per-lib build scripts. | ||
| /// </summary> | ||
| public static class Targets | ||
| { | ||
| private static readonly Lazy<string> RepoRoot = new(FindRoot); | ||
|
|
||
| public const string Restore = "restore"; | ||
| public const string Build = "build"; | ||
| public const string Clean = "clean"; | ||
| public const string Pack = "pack"; | ||
| public const string Test = "test"; | ||
|
|
||
| private const string Default = "default"; | ||
|
|
||
| /// <summary> | ||
| /// Registers all shared targets parameterized by the lib's solution filter path. | ||
| /// </summary> | ||
| /// <param name="slnfPath"> | ||
| /// Repo-relative path to the lib's solution filter | ||
| /// (e.g. <c>signatures/signatures.slnf</c>). | ||
| /// </param> | ||
| /// <param name="packProjectPath"> | ||
| /// Repo-relative path to the lib's packable src project | ||
| /// (e.g. <c>signatures/src/Http.HttpSignatures</c>). | ||
| /// </param> | ||
| public static void SharedTargets(string slnfPath, string packProjectPath) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(slnfPath); | ||
| ArgumentNullException.ThrowIfNull(packProjectPath); | ||
|
|
||
| var libDir = slnfPath.Split('/')[0]; | ||
|
|
||
| Target(Restore, () => | ||
| RunAsync("dotnet", $"restore {slnfPath}", RepoRoot.Value)); | ||
|
|
||
| Target(Build, dependsOn: [Restore], () => | ||
| RunAsync("dotnet", $"build {slnfPath} --no-restore -c Release", RepoRoot.Value)); | ||
|
|
||
| Target(Clean, () => | ||
| RunAsync("dotnet", $"clean {slnfPath}", RepoRoot.Value)); | ||
|
|
||
| Target(Pack, dependsOn: [Build], () => | ||
| RunAsync( | ||
| "dotnet", | ||
| $"pack {packProjectPath} --no-build -c Release -o {libDir}/artifacts", | ||
| RepoRoot.Value)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Registers a test target that runs <c>dotnet test</c> on a test project with standard options. | ||
| /// </summary> | ||
| /// <param name="targetName">The target name (e.g. <c>"test"</c>).</param> | ||
| /// <param name="testProjectPath"> | ||
| /// Repo-relative path to the test project | ||
| /// (e.g. <c>"signatures/test/Http.HttpSignatures.Tests"</c>). | ||
| /// </param> | ||
| public static void TestTarget(string targetName, string testProjectPath) => | ||
| Target(targetName, dependsOn: [Restore], () => | ||
| RunAsync( | ||
| "dotnet", | ||
| $"test --project {testProjectPath} -c Release --no-restore --report-xunit-trx " + | ||
| $"--report-xunit-trx-filename {testProjectPath.Replace('/', '-')}-tests.trx", | ||
| RepoRoot.Value)); | ||
|
|
||
| public static void DefaultTarget(IEnumerable<string> dependsOn) => | ||
| Target(Default, dependsOn); | ||
|
|
||
| public static Task RunTargetsAndExitAsync(IEnumerable<string> args) => | ||
| Bullseye.Targets.RunTargetsAndExitAsync(args, messageOnly: ex => ex is SimpleExec.ExitCodeException); | ||
|
|
||
| private static string FindRoot() | ||
| { | ||
| var root = Directory.GetCurrentDirectory(); | ||
|
|
||
| // Repositories have a .git folder, worktrees have a .git file, so check for both. | ||
| while (!Directory.Exists(Path.Combine(root, ".git")) && !File.Exists(Path.Combine(root, ".git"))) | ||
| { | ||
| root = Directory.GetParent(root) is { } parent | ||
| ? parent.FullName | ||
| : throw new InvalidOperationException( | ||
| "Could not find repository root (no .git directory or file found)"); | ||
| } | ||
|
|
||
| return root; | ||
| } | ||
| } | ||
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,71 @@ | ||
| name: ci-template | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| product: | ||
| description: "Lib folder name (e.g. signatures, structured-field-values)" | ||
| required: true | ||
| type: string | ||
| test-targets: | ||
| description: 'JSON array of build.cs test targets (e.g. ["test"]). Empty array or "[]" to skip.' | ||
| required: false | ||
| type: string | ||
| default: '["test"]' | ||
| os-matrix: | ||
| description: 'JSON array of OS runners for the test job. Defaults to ubuntu only.' | ||
| required: false | ||
| type: string | ||
| default: '["ubuntu-latest"]' | ||
|
|
||
| env: | ||
| DOTNET_NOLOGO: true | ||
| DOTNET_CLI_TELEMETRY_OPTOUT: true | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| timeout-minutes: 15 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - uses: actions/setup-dotnet@v4 | ||
| with: | ||
| dotnet-version: '10.0.x' | ||
| - name: Build | ||
| run: dotnet run ${{ inputs.product }}/build.cs -- build | ||
|
|
||
| test: | ||
| name: "Test: ${{ matrix.target }} (${{ matrix.os }})" | ||
| if: inputs.test-targets != '[]' | ||
|
damianh marked this conversation as resolved.
|
||
| runs-on: ${{ matrix.os }} | ||
| permissions: | ||
| contents: read | ||
| strategy: | ||
| matrix: | ||
| target: ${{ fromJson(inputs.test-targets) }} | ||
| os: ${{ fromJson(inputs.os-matrix) }} | ||
| fail-fast: false | ||
| timeout-minutes: 15 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - uses: actions/setup-dotnet@v4 | ||
| with: | ||
| dotnet-version: '10.0.x' | ||
| - name: Test | ||
| run: dotnet run ${{ inputs.product }}/build.cs -- ${{ matrix.target }} | ||
| - name: Test report | ||
| if: success() || failure() | ||
| uses: phoenix-actions/test-reporting@f957cd93fc2d848d556fa0d03c57bc79127b6b5e | ||
| with: | ||
| name: "${{ inputs.product }}: ${{ matrix.target }} (${{ matrix.os }})" | ||
| path: "**/*-tests.trx" | ||
| reporter: dotnet-trx | ||
| output-to: step-summary | ||
| fail-on-error: true | ||
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
| name: file-distributed-cache/ci | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - main | ||
| - '**' | ||
| paths: | ||
| - .github/BuildHelpers/** | ||
| - .github/workflows/file-distributed-cache-ci.yml | ||
| - .github/workflows/ci-template.yml | ||
| - file-distributed-cache/** | ||
| - .editorconfig | ||
| - Directory.Build.props | ||
| - global.json | ||
| - http-lib.slnx | ||
| pull_request: | ||
| paths: | ||
| - .github/BuildHelpers/** | ||
| - .github/workflows/file-distributed-cache-ci.yml | ||
| - .github/workflows/ci-template.yml | ||
| - file-distributed-cache/** | ||
| - .editorconfig | ||
| - Directory.Build.props | ||
| - global.json | ||
| - http-lib.slnx | ||
|
|
||
| jobs: | ||
| build: | ||
| uses: ./.github/workflows/ci-template.yml | ||
| with: | ||
| product: file-distributed-cache | ||
| test-targets: '["test"]' |
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 @@ | ||
| name: file-distributed-cache/release | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: 'Version number (x.y.z or x.y.z-prerelease.1)' | ||
| required: true | ||
| type: string | ||
|
|
||
| jobs: | ||
| release: | ||
| uses: ./.github/workflows/release-template.yml | ||
| with: | ||
| product: file-distributed-cache | ||
| package: DamianH.FileDistributedCache | ||
| tag-prefix: fdc-v | ||
| version: ${{ inputs.version }} | ||
| secrets: | ||
| NUGET_ORG_APIKEY: ${{ secrets.NUGET_ORG_APIKEY }} |
Oops, something went wrong.
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.