diff --git a/.github/workflows/github-packages-baseline.yml b/.github/workflows/go-compile-yourself.yml similarity index 73% rename from .github/workflows/github-packages-baseline.yml rename to .github/workflows/go-compile-yourself.yml index 2812ca79..1d46eee3 100644 --- a/.github/workflows/github-packages-baseline.yml +++ b/.github/workflows/go-compile-yourself.yml @@ -1,35 +1,35 @@ -name: LagoVista.Core Package Canary +name: Go Compile Yourself on: - pull_request: - branches: - - master push: + branches: + - 'feature/**' + pull_request: branches: - master workflow_dispatch: inputs: - publish: - description: Publish LagoVista.Core to GitHub Packages - required: true - type: boolean - default: false version: - description: LagoVista.Core semantic version + description: Package version to build required: true type: string default: 5.0.0 + publish: + description: Publish the package to the shared GitHub Packages feed + required: true + type: boolean + default: false permissions: contents: read jobs: - build-pack: + build-package: runs-on: windows-latest timeout-minutes: 30 env: - PACKAGE_VERSION: ${{ github.event_name == 'workflow_dispatch' && inputs.version || '5.0.0' }} + PACKAGE_VERSION: ${{ github.event_name == 'workflow_dispatch' && inputs.version || format('5.0.0-feature.{0}', github.run_number) }} PACKAGE_SOURCE: https://nuget.pkg.github.com/nuviot/index.json NUGET_GITHUB_TOKEN: ${{ secrets.NUGET_GITHUB_TOKEN }} @@ -45,29 +45,31 @@ jobs: - name: Setup NuGet uses: NuGet/setup-nuget@v2 - - name: Add GitHub Packages source + - name: Configure shared package feed if: ${{ env.NUGET_GITHUB_TOKEN != '' }} shell: pwsh run: | - dotnet nuget remove source github 2>$null + dotnet nuget remove source nuviot 2>$null dotnet nuget add source "$env:PACKAGE_SOURCE" ` - --name github ` + --name nuviot ` --username "${{ github.actor }}" ` --password "$env:NUGET_GITHUB_TOKEN" ` --store-password-in-clear-text - - name: Build and pack LagoVista.Core + - name: Build and pack repository packages shell: pwsh run: ./Build-GitHubPackages.ps1 -Version $env:PACKAGE_VERSION - - name: Upload package artifact + - name: Upload package build uses: actions/upload-artifact@v4 with: name: LagoVista.Core-${{ env.PACKAGE_VERSION }} - path: artifacts/packages/LagoVista.Core.${{ env.PACKAGE_VERSION }}.nupkg + path: | + artifacts/packages/LagoVista.Core.${{ env.PACKAGE_VERSION }}.nupkg + artifacts/package-catalog.json if-no-files-found: error - - name: Publish to GitHub Packages + - name: Publish package if: ${{ github.event_name == 'workflow_dispatch' && inputs.publish }} shell: pwsh run: | @@ -77,7 +79,7 @@ jobs: $package = "artifacts/packages/LagoVista.Core.$env:PACKAGE_VERSION.nupkg" dotnet nuget push $package ` - --source github ` + --source nuviot ` --api-key "$env:NUGET_GITHUB_TOKEN" ` --skip-duplicate diff --git a/Build-GitHubPackages.ps1 b/Build-GitHubPackages.ps1 index 05686bc5..6efb6293 100644 --- a/Build-GitHubPackages.ps1 +++ b/Build-GitHubPackages.ps1 @@ -3,7 +3,10 @@ param( [string]$Version = '5.0.0', [Parameter(Mandatory = $false)] - [string]$OutputDirectory = './artifacts/packages' + [string]$OutputDirectory = './artifacts/packages', + + [Parameter(Mandatory = $false)] + [string]$CatalogPath = './artifacts/package-catalog.json' ) $ErrorActionPreference = 'Stop' @@ -15,6 +18,7 @@ Set-Location $repoRoot $projectPath = Join-Path $repoRoot 'src/LagoVista.Core/LagoVista.Core.csproj' $nuspecPath = Join-Path $repoRoot 'src/LagoVista.Core/Package.nuspec' $outputPath = [System.IO.Path]::GetFullPath((Join-Path $repoRoot $OutputDirectory)) +$catalogFullPath = [System.IO.Path]::GetFullPath((Join-Path $repoRoot $CatalogPath)) if (-not (Test-Path $projectPath)) { throw "Project not found: $projectPath" } if (-not (Test-Path $nuspecPath)) { throw "NuSpec not found: $nuspecPath" } @@ -23,6 +27,7 @@ if (Test-Path $outputPath) { Remove-Item -Recurse -Force $outputPath } New-Item -ItemType Directory -Force -Path $outputPath | Out-Null +New-Item -ItemType Directory -Force -Path (Split-Path $catalogFullPath -Parent) | Out-Null Write-Host "Building LagoVista.Core package $Version" Write-Host "Output: $outputPath" @@ -45,7 +50,7 @@ if ($internalDependencies.Count -gt 0) { throw "LagoVista.Core canary must not have internal LagoVista dependencies. Found: $names" } -# Stamp only the CI checkout. The committed NuSpec remains historical source metadata. +# Stamp only the build checkout. The committed NuSpec remains historical source metadata. $metadata.version = $Version $settings = New-Object System.Xml.XmlWriterSettings $settings.Indent = $true @@ -80,4 +85,30 @@ if (-not (Test-Path $packagePath)) { throw "Expected package was not produced: $packagePath" } +$sourceRepository = if ($env:GITHUB_REPOSITORY) { $env:GITHUB_REPOSITORY } else { 'LagoVista/Core' } +$sourceCommit = if ($env:GITHUB_SHA) { $env:GITHUB_SHA } else { (git rev-parse HEAD).Trim() } +$sourceRef = if ($env:GITHUB_REF_NAME) { $env:GITHUB_REF_NAME } else { (git branch --show-current).Trim() } + +$catalog = [ordered]@{ + schemaVersion = 1 + generatedUtc = [DateTime]::UtcNow.ToString('o') + source = [ordered]@{ + repository = $sourceRepository + commit = $sourceCommit + ref = $sourceRef + } + packages = @( + [ordered]@{ + id = 'LagoVista.Core' + version = $Version + file = [System.IO.Path]::GetFileName($packagePath) + targetFrameworks = @('netstandard2.0') + internalDependencies = @() + } + ) +} + +$catalog | ConvertTo-Json -Depth 8 | Set-Content -Path $catalogFullPath -Encoding utf8 + Write-Host "Created $packagePath" +Write-Host "Created $catalogFullPath"