From ca875ea6a41b4f48c02c9e8476051cc36784f826 Mon Sep 17 00:00:00 2001 From: UltimateCoder Date: Thu, 15 Oct 2026 21:41:38 +0200 Subject: [PATCH] feat: add reusable .NET build & test workflow Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/dotnet-build-test.yaml | 79 +++++++++++++++++++++++++ README.md | 38 ++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 .gitea/workflows/dotnet-build-test.yaml create mode 100644 README.md diff --git a/.gitea/workflows/dotnet-build-test.yaml b/.gitea/workflows/dotnet-build-test.yaml new file mode 100644 index 0000000..2fd7731 --- /dev/null +++ b/.gitea/workflows/dotnet-build-test.yaml @@ -0,0 +1,79 @@ +name: .NET Build & Test (Reusable) + +on: + workflow_call: + inputs: + solution: + description: "Solution/project file to build (relative to working-directory). Empty = let dotnet pick the single sln/proj in working-directory" + required: false + default: "" + type: string + dotnet-version: + description: ".NET SDK version" + required: false + default: "10.0.x" + type: string + configuration: + description: "Build configuration" + required: false + default: "Release" + type: string + warnaserror: + description: "Treat build warnings as errors" + required: false + default: true + type: boolean + working-directory: + description: "Path where dotnet commands are executed (relative to repo root)" + required: false + default: "." + type: string + test-filter: + description: "Optional dotnet test --filter expression" + required: false + default: "" + type: string + +jobs: + build-and-test: + runs-on: ubuntu-latest + env: + DOTNET_CLI_TELEMETRY_OPTOUT: "1" + DOTNET_NOLOGO: "1" + SOLUTION: ${{ inputs.solution }} + CONFIGURATION: ${{ inputs.configuration }} + WARNASERROR: ${{ inputs.warnaserror }} + TEST_FILTER: ${{ inputs.test-filter }} + + defaults: + run: + shell: bash + working-directory: ${{ inputs.working-directory }} + + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Setup .NET + uses: actions/setup-dotnet@v5 + with: + dotnet-version: ${{ inputs.dotnet-version }} + + - name: Restore + run: dotnet restore ${SOLUTION:+"$SOLUTION"} + + - name: Build + run: | + ARGS=(-c "$CONFIGURATION" --no-restore) + if [ "$WARNASERROR" = "true" ]; then + ARGS+=(-warnaserror) + fi + dotnet build ${SOLUTION:+"$SOLUTION"} "${ARGS[@]}" + + - name: Test + run: | + ARGS=(-c "$CONFIGURATION" --no-build) + if [ -n "$TEST_FILTER" ]; then + ARGS+=(--filter "$TEST_FILTER") + fi + dotnet test ${SOLUTION:+"$SOLUTION"} "${ARGS[@]}" diff --git a/README.md b/README.md new file mode 100644 index 0000000..af85768 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# dotnet-build-test + +Reusable Gitea Actions workflow: `dotnet restore` → `build` → `test`, with no Docker. Meant as a PR gate, for example so Renovate can automerge. + +## Usage + +```yaml +on: + pull_request: + +jobs: + build-test: + uses: templates/dotnet-build-test/.gitea/workflows/dotnet-build-test.yaml@v1 + with: + solution: MyApp.slnx + # dotnet-version: 10.0.x + # configuration: Release + # warnaserror: true + # working-directory: . + # test-filter: "Category!=Integration" +``` + +## Inputs + +| Name | Default | Description | +|---|---|---| +| `solution` | `""` | Solution/project file, relative to `working-directory`. If empty, dotnet uses the single sln/proj in that directory. | +| `dotnet-version` | `10.0.x` | .NET SDK version | +| `configuration` | `Release` | Build configuration | +| `warnaserror` | `true` | Pass `-warnaserror` to `dotnet build` | +| `working-directory` | `.` | Where dotnet commands run | +| `test-filter` | `""` | Optional `dotnet test --filter` expression | + +No secrets. + +## Versioning + +Only major tags (`v1`, `v2`, …). Fixes and new optional inputs move the existing tag. Changing or removing inputs, or changing behavior, needs a new major tag.