Skip to content

Commit

Permalink
Update deploy (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
teociaps authored Aug 19, 2024
2 parents 017da0f + e46a200 commit e22b4ce
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
17 changes: 3 additions & 14 deletions .github/workflows/pack_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
- published

env:
PROJECTS_PATH: 'src/*.Themes'
CONFIGURATION: 'Release'
PACKAGE_OUTPUT: ${{ github.workspace }}/artifacts
NUGET_SOURCE_URL: 'https://api.nuget.org/v3/index.json'
Expand All @@ -32,16 +31,6 @@ jobs:
7.0.x
8.0.x
- name: Pack
run: |
dotnet pack ${{ env.PROJECTS_PATH }} --configuration ${{ env.CONFIGURATION }} --output ${{ env.PACKAGE_OUTPUT }}
- name: Publish Artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts
path: ${{ env.PACKAGE_OUTPUT }}

- name: Push to NuGet
run: |
dotnet nuget push ${{ env.PACKAGE_OUTPUT }}/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s ${{ env.NUGET_SOURCE_URL }}
- name: Pack & Push to NuGet
shell: pwsh
run: ./deploy.ps1 -Configuration ${{ env.CONFIGURATION }} -PackageOutput ${{ env.PACKAGE_OUTPUT }} -NuGetSourceUrl ${{ env.NUGET_SOURCE_URL }} -NuGetApiKey ${{ secrets.NUGET_API_KEY }}
7 changes: 7 additions & 0 deletions build/Versioning.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@
<Version>$(MajorVersion).$(MinorVersion).$(PatchVersion)$(VersionSuffix)</Version>
</PropertyGroup>

<Target Name="GetVersion">
<Message Importance="High" Text="$(Version)" />
<PropertyGroup>
<VersionOutput>$(Version)</VersionOutput>
</PropertyGroup>
</Target>

</Project>
45 changes: 45 additions & 0 deletions deploy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# deploy.ps1
param (
[string]$Configuration = "Release",
[string]$PackageOutput = "$(pwd)/artifacts",
[string]$NuGetSourceUrl = "https://api.nuget.org/v3/index.json",
[string]$NuGetApiKey
)

# Ensure the output directory exists
if (-not (Test-Path -Path $PackageOutput)) {
New-Item -ItemType Directory -Path $PackageOutput | Out-Null
}

# Iterate over each project to pack
Get-ChildItem -Path src -Filter *.Themes -Directory | ForEach-Object {
$projectPath = $_.FullName
$projectName = $_.Name
$csprojPath = Join-Path -Path $projectPath -ChildPath "${projectName}.csproj"

try {
$version = dotnet msbuild $csprojPath -nologo -t:GetVersion -p:Configuration=$configuration | ForEach-Object { $_.Trim() }

if (-not $version) {
throw "Failed to retrieve version for project ${projectName}"
}

Write-Host "> Packing ${projectName} version: ${version}" -ForegroundColor "Cyan"

dotnet pack $projectPath --configuration $Configuration --output $PackageOutput

$packageName = "${projectName}.${version}.nupkg"
$packagePath = Join-Path -Path $PackageOutput -ChildPath $packageName

if (Test-Path -Path $packagePath) {
dotnet nuget push $packagePath -k $NuGetApiKey -s $NuGetSourceUrl --skip-duplicate
Write-Host "Package ${packageName} pushed." -ForegroundColor "Green"
} else {
Write-Host "Package ${packageName} already exists on NuGet. Skipping push." -ForegroundColor "Yellow"
}
} catch {
Write-Error "Error processing project ${projectName}: $_"
}
}

Write-Host "Deploy finished."

0 comments on commit e22b4ce

Please sign in to comment.