|
| 1 | +# dotnet.CI.template |
| 2 | + |
| 3 | +[](https://github.com/AGIBuild/dotnet.CI.template/actions/workflows/ci.yml) |
| 4 | +[](https://github.com/AGIBuild/dotnet.CI.template/actions/workflows/codeql.yml) |
| 5 | +[](LICENSE) |
| 6 | + |
| 7 | +**Stop wiring CI from scratch.** Start with a production-grade pipeline that builds, tests, packages, and releases your .NET projects across platforms -- with a single approval click. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## What You Get |
| 12 | + |
| 13 | +Use this template and you instantly have: |
| 14 | + |
| 15 | +``` |
| 16 | +Push to main |
| 17 | + | |
| 18 | + v |
| 19 | +resolve-version ── Reads VersionPrefix, computes matrix, outputs version info |
| 20 | + | |
| 21 | + v |
| 22 | +build-and-test ─── Matrix build (linux / windows / macos) |
| 23 | + | + Pack NuGet + Publish + Package installers |
| 24 | + | |
| 25 | + v |
| 26 | +release ────────── [requires approval] NuGet push + Git tag + GitHub Release |
| 27 | + | |
| 28 | + v |
| 29 | +deploy-docs ────── DocFX to GitHub Pages (optional) |
| 30 | +``` |
| 31 | + |
| 32 | +On **pull requests**, only a fast linux build + test runs. On **main**, the full multi-platform pipeline kicks in. |
| 33 | + |
| 34 | +### Pipeline Highlights |
| 35 | + |
| 36 | +| Feature | Details | |
| 37 | +|---------|---------| |
| 38 | +| **NUKE Build** | All build logic lives in C# targets -- no scattered shell scripts in YAML | |
| 39 | +| **Single Approval** | One `release` environment gate controls the entire release flow | |
| 40 | +| **Multi-Platform Matrix** | linux-x64, win-x64, osx-arm64 (+ optional Android/iOS) | |
| 41 | +| **NuGet Publishing** | Auto-push to NuGet.org with SHA256 manifest verification | |
| 42 | +| **Installer Packages** | Platform-specific zip archives attached to GitHub Releases | |
| 43 | +| **Version from Code** | `VersionPrefix` in `Directory.Build.props` is the single source of truth | |
| 44 | +| **Four-Part Release Tags** | `v0.2.0.42` format ensures unique tags per build | |
| 45 | +| **CodeQL Security** | Automated vulnerability scanning on every push and weekly | |
| 46 | +| **Graceful Degradation** | Missing NuGet key? Skipped. No DocFX config? Skipped. Nothing breaks. | |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +## Quick Start |
| 51 | + |
| 52 | +### 1. Create your repo from this template |
| 53 | + |
| 54 | +Click **[Use this template](https://github.com/AGIBuild/dotnet.CI.template/generate)** on GitHub. |
| 55 | + |
| 56 | +### 2. Configure environments |
| 57 | + |
| 58 | +Go to **Settings > Environments** and create a `release` environment with at least one required reviewer. |
| 59 | + |
| 60 | +### 3. Set secrets (optional) |
| 61 | + |
| 62 | +| Secret | Purpose | |
| 63 | +|--------|---------| |
| 64 | +| `NUGET_API_KEY` | Push packages to NuGet.org | |
| 65 | + |
| 66 | +### 4. Push code and watch it go |
| 67 | + |
| 68 | +```bash |
| 69 | +git push origin main |
| 70 | +``` |
| 71 | + |
| 72 | +The pipeline runs automatically. When `build-and-test` completes, go to **Actions > Review deployments** to approve the release. |
| 73 | + |
| 74 | +--- |
| 75 | + |
| 76 | +## Project Structure |
| 77 | + |
| 78 | +``` |
| 79 | +. |
| 80 | +├── .github/workflows/ |
| 81 | +│ ├── ci.yml # CI + Release pipeline |
| 82 | +│ └── codeql.yml # Security analysis |
| 83 | +├── build/ |
| 84 | +│ ├── BuildTask.*.cs # NUKE targets (Build, Test, Pack, Publish, PackageApp, ...) |
| 85 | +│ └── _build.csproj |
| 86 | +├── src/ # Your application code |
| 87 | +├── tests/ # Your test projects |
| 88 | +├── docs/ # Guides (add docfx.json for auto-deploy) |
| 89 | +├── Directory.Build.props # Version + shared build properties |
| 90 | +└── global.json # SDK version pinning |
| 91 | +``` |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## Version Management |
| 96 | + |
| 97 | +Versions follow a simple rule: |
| 98 | + |
| 99 | +- **Edit `VersionPrefix`** in `Directory.Build.props` via PR (e.g., `0.2.0` -> `1.0.0`) |
| 100 | +- **CI appends the build number** on release: `0.2.0` becomes `0.2.0.42` |
| 101 | +- **Tags are created automatically**: `v0.2.0.42` |
| 102 | + |
| 103 | +No manual tagging. No version input fields. Just change the number in one file. |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +## Extending the Build |
| 108 | + |
| 109 | +Build logic is in `build/BuildTask.*.cs` using [NUKE](https://nuke.build). Add new targets in C# and call them from workflows: |
| 110 | + |
| 111 | +```csharp |
| 112 | +Target MyTarget => _ => _ |
| 113 | + .DependsOn(Build) |
| 114 | + .Executes(() => |
| 115 | + { |
| 116 | + // your build logic here |
| 117 | + }); |
| 118 | +``` |
| 119 | + |
| 120 | +```yaml |
| 121 | +# in ci.yml |
| 122 | +- run: ./build.sh MyTarget |
| 123 | +``` |
| 124 | +
|
| 125 | +--- |
| 126 | +
|
| 127 | +## Mobile Platform Support |
| 128 | +
|
| 129 | +Android and iOS builds are supported but disabled by default. Toggle them in `ci.yml`: |
| 130 | + |
| 131 | +```yaml |
| 132 | +env: |
| 133 | + ENABLE_ANDROID: 'true' |
| 134 | + ENABLE_IOS: 'true' |
| 135 | +``` |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## Documentation Deployment |
| 140 | + |
| 141 | +To enable automatic documentation deployment to GitHub Pages: |
| 142 | + |
| 143 | +1. Add a `docs/docfx.json` configuration file |
| 144 | +2. Enable GitHub Pages in **Settings > Pages > Source: GitHub Actions** |
| 145 | +3. The `deploy-docs` job will automatically build and deploy after each release |
| 146 | + |
| 147 | +--- |
| 148 | + |
| 149 | +## License |
| 150 | + |
| 151 | +[MIT](LICENSE) |
0 commit comments