-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathci-cd.ps1
More file actions
94 lines (83 loc) · 3.19 KB
/
ci-cd.ps1
File metadata and controls
94 lines (83 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Main CI/CD orchestration script for TimeWarp.Fixie
.DESCRIPTION
This script orchestrates the complete CI/CD pipeline including build, test, and publish phases.
It can be run locally for testing or called from GitHub Actions.
.PARAMETER Phase
The phase to run: 'build', 'publish', or 'all'. Default is 'all'.
.PARAMETER Configuration
The build configuration (Debug or Release). Default is Release.
.PARAMETER PublishToNuGet
Whether to publish to NuGet. Default is false for safety.
.PARAMETER NuGetApiKey
The NuGet API key. If not provided, will use the NUGET_API_KEY environment variable.
#>
param(
[ValidateSet("build", "publish", "all")]
[string]$Phase = "all",
[string]$Configuration = "Release",
[bool]$PublishToNuGet = $false,
[string]$NuGetApiKey = $env:NUGET_API_KEY
)
$ErrorActionPreference = "Stop"
$ArtifactsPath = "./artifacts"
function Write-PhaseHeader {
param([string]$PhaseName)
Write-Host ""
Write-Host "=" * 60 -ForegroundColor Magenta
Write-Host " $PhaseName" -ForegroundColor Magenta
Write-Host "=" * 60 -ForegroundColor Magenta
Write-Host ""
}
try {
Push-Location $PSScriptRoot
Write-Host "TimeWarp.Fixie CI/CD Pipeline" -ForegroundColor Green
Write-Host "Phase: $Phase" -ForegroundColor Cyan
Write-Host "Configuration: $Configuration" -ForegroundColor Cyan
Write-Host "Publish to NuGet: $PublishToNuGet" -ForegroundColor Cyan
# Build and Test Phase
if ($Phase -eq "build" -or $Phase -eq "all") {
Write-PhaseHeader "BUILD AND TEST PHASE"
& ./build-and-test.ps1 -Configuration $Configuration -OutputPath $ArtifactsPath
if ($LASTEXITCODE -ne 0) {
throw "Build and test phase failed"
}
}
# Publish Phase
if (($Phase -eq "publish" -or $Phase -eq "all") -and $PublishToNuGet) {
Write-PhaseHeader "PUBLISH PHASE"
if ([string]::IsNullOrWhiteSpace($NuGetApiKey)) {
Write-Warning "NuGet API key not provided. Skipping publish phase."
Write-Host "To publish, provide the API key via -NuGetApiKey parameter or NUGET_API_KEY environment variable." -ForegroundColor Yellow
} else {
& ./publish-nuget.ps1 -PackagePath $ArtifactsPath -NuGetApiKey $NuGetApiKey
if ($LASTEXITCODE -ne 0) {
throw "Publish phase failed"
}
}
} elseif ($Phase -eq "publish" -or $Phase -eq "all") {
Write-Host "Publish phase skipped (PublishToNuGet = $PublishToNuGet)" -ForegroundColor Yellow
}
Write-PhaseHeader "PIPELINE COMPLETED SUCCESSFULLY"
Write-Host "All phases completed successfully!" -ForegroundColor Green
# Show artifacts
if (Test-Path $ArtifactsPath) {
$artifacts = Get-ChildItem -Path $ArtifactsPath -Filter "*.nupkg"
if ($artifacts) {
Write-Host ""
Write-Host "Generated artifacts:" -ForegroundColor Green
foreach ($artifact in $artifacts) {
Write-Host " - $($artifact.Name)" -ForegroundColor Cyan
}
}
}
}
catch {
Write-Error "CI/CD Pipeline failed: $_"
exit 1
}
finally {
Pop-Location
}