feat: add reusable .NET build & test workflow
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
commit
ca875ea6a4
2 files changed
+117
No files matched your search
@@ -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[@]}"
|
||||
@@ -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.
|
||||
Reference in new issue
Block a user