|
| 1 | +# CI/CD Pipeline for TimeWarp.Fixie |
| 2 | + |
| 3 | +This folder contains the CI/CD pipeline scripts for the TimeWarp.Fixie project. The pipeline is designed to be testable locally using PowerShell scripts, with minimal GitHub Actions orchestration. |
| 4 | + |
| 5 | +## Scripts |
| 6 | + |
| 7 | +### `ci-cd.ps1` - Main Orchestration Script |
| 8 | +The main entry point for the CI/CD pipeline. Can run individual phases or the complete pipeline. |
| 9 | + |
| 10 | +**Usage:** |
| 11 | +```powershell |
| 12 | +# Run complete pipeline (build + test only) |
| 13 | +./CI-CD/ci-cd.ps1 |
| 14 | +
|
| 15 | +# Run only build and test |
| 16 | +./CI-CD/ci-cd.ps1 -Phase build |
| 17 | +
|
| 18 | +# Run complete pipeline with NuGet publishing |
| 19 | +./CI-CD/ci-cd.ps1 -PublishToNuGet $true |
| 20 | +
|
| 21 | +# Run only publish phase |
| 22 | +./CI-CD/ci-cd.ps1 -Phase publish -PublishToNuGet $true |
| 23 | +``` |
| 24 | + |
| 25 | +**Parameters:** |
| 26 | +- `Phase`: 'build', 'publish', or 'all' (default: 'all') |
| 27 | +- `Configuration`: 'Debug' or 'Release' (default: 'Release') |
| 28 | +- `PublishToNuGet`: Whether to publish to NuGet (default: false) |
| 29 | +- `NuGetApiKey`: NuGet API key (uses NUGET_API_KEY env var if not provided) |
| 30 | + |
| 31 | +### `build-and-test.ps1` - Build and Test Phase |
| 32 | +Handles the build and test phase of the pipeline. |
| 33 | + |
| 34 | +**What it does:** |
| 35 | +1. Restores dotnet tools |
| 36 | +2. Runs `dotnet cleanup` |
| 37 | +3. Restores dependencies |
| 38 | +4. Builds the project |
| 39 | +5. Runs tests |
| 40 | +6. Creates NuGet packages |
| 41 | + |
| 42 | +**Usage:** |
| 43 | +```powershell |
| 44 | +./CI-CD/build-and-test.ps1 -Configuration Release -OutputPath ./artifacts |
| 45 | +``` |
| 46 | + |
| 47 | +### `publish-nuget.ps1` - NuGet Publishing Phase |
| 48 | +Handles publishing NuGet packages to NuGet.org. |
| 49 | + |
| 50 | +**What it does:** |
| 51 | +1. Validates NuGet API key |
| 52 | +2. Finds packages in the specified directory |
| 53 | +3. Publishes packages to NuGet.org |
| 54 | +4. Supports skip-duplicate option |
| 55 | + |
| 56 | +**Usage:** |
| 57 | +```powershell |
| 58 | +# Using environment variable |
| 59 | +$env:NUGET_API_KEY = "your-api-key" |
| 60 | +./CI-CD/publish-nuget.ps1 |
| 61 | +
|
| 62 | +# Using parameter |
| 63 | +./CI-CD/publish-nuget.ps1 -NuGetApiKey "your-api-key" |
| 64 | +``` |
| 65 | + |
| 66 | +## GitHub Actions Integration |
| 67 | + |
| 68 | +The pipeline integrates with GitHub Actions through [`.github/workflows/ci-cd.yml`](../.github/workflows/ci-cd.yml): |
| 69 | + |
| 70 | +- **Build and Test**: Runs on every push and PR to master branch |
| 71 | +- **Publish**: Runs only on GitHub releases, publishes to NuGet.org |
| 72 | + |
| 73 | +## Local Testing |
| 74 | + |
| 75 | +You can test the entire pipeline locally: |
| 76 | + |
| 77 | +```powershell |
| 78 | +# Test build and test phase |
| 79 | +./CI-CD/ci-cd.ps1 -Phase build |
| 80 | +
|
| 81 | +# Test complete pipeline (without publishing) |
| 82 | +./CI-CD/ci-cd.ps1 |
| 83 | +
|
| 84 | +# Test with publishing (requires API key) |
| 85 | +$env:NUGET_API_KEY = "your-test-api-key" |
| 86 | +./CI-CD/ci-cd.ps1 -PublishToNuGet $true |
| 87 | +``` |
| 88 | + |
| 89 | +## Environment Variables |
| 90 | + |
| 91 | +- `NUGET_API_KEY`: Required for publishing to NuGet.org |
| 92 | + |
| 93 | +## Migration from Manual Process |
| 94 | + |
| 95 | +The previous manual [`publish.ps1`](../publish.ps1) script functionality has been integrated into this CI/CD pipeline: |
| 96 | + |
| 97 | +| Old Script Step | New Location | |
| 98 | +|----------------|--------------| |
| 99 | +| `Push-Location $PSScriptRoot` | Handled in each script | |
| 100 | +| `dotnet tool restore` | `build-and-test.ps1` | |
| 101 | +| `dotnet cleanup -y` | `build-and-test.ps1` | |
| 102 | +| `dotnet pack` | `build-and-test.ps1` | |
| 103 | +| `dotnet nuget push` | `publish-nuget.ps1` | |
| 104 | +| Error handling | Enhanced in all scripts | |
| 105 | + |
| 106 | +## Security Considerations |
| 107 | + |
| 108 | +- NuGet API key is handled through GitHub Secrets in CI/CD |
| 109 | +- Scripts validate API key presence before attempting to publish |
| 110 | +- Local testing can use environment variables |
| 111 | +- No API keys are stored in source code |
| 112 | + |
| 113 | +## Troubleshooting |
| 114 | + |
| 115 | +### Build Failures |
| 116 | +1. Check that all dependencies are properly restored |
| 117 | +2. Ensure .NET 9.0 SDK is installed |
| 118 | +3. Verify project builds locally with `dotnet build` |
| 119 | + |
| 120 | +### Test Failures |
| 121 | +1. Run tests locally with `dotnet fixie` |
| 122 | +2. Check test output for specific failure details |
| 123 | +3. Ensure test dependencies are properly configured |
| 124 | + |
| 125 | +### Publish Failures |
| 126 | +1. Verify NuGet API key is correctly set |
| 127 | +2. Check that packages don't already exist (unless using skip-duplicate) |
| 128 | +3. Ensure network connectivity to NuGet.org |
| 129 | +4. Verify package metadata is valid |
0 commit comments