Skip to content

Bump the aspnetcore group with 1 update #399

Bump the aspnetcore group with 1 update

Bump the aspnetcore group with 1 update #399

Workflow file for this run

name: publish
on:
push:
branches:
- "main"
pull_request:
workflow_dispatch:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: false
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NUGET_DIRECTORY: ${{ github.workspace}}/artifacts
defaults:
run:
shell: pwsh
jobs:
lint_config:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
- name: Create artifacts directory
run: mkdir -p artifacts
- run: dotnet run --project=tools/ConfigFilesGenerator/ConfigFilesGenerator.csproj
compute_version:
runs-on: ubuntu-latest
outputs:
package_version: ${{ steps.compute-version.outputs.package_version }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-dotnet@v5
- id: compute-version
run: |
$LatestTag = git describe --tags --abbrev=0 2>$null
if ($LatestTag -and $LatestTag -match '^v([0-9]+\.[0-9]+\.[0-9]+)$')
{
$NewVersion = $Matches[1]
Write-Host "Using tag version: $NewVersion"
}
else
{
try
{
# Match version like 1.1.X or 1.0.X
$(Invoke-WebRequest "https://www.nuget.org/api/v2/package/ANcpLua.NET.Sdk/").BaseResponse.RequestMessage.RequestUri -match "ANcpLua\.net\.sdk\.(\d+)\.(\d+)\.(\d+)\.nupkg"
$Major = [int]$Matches.1
$Minor = [int]$Matches.2
$Patch = [int]$Matches.3 + 1
$NewVersion = "$Major.$Minor.$Patch"
}
catch
{
$NewVersion = "1.1.3"
}
}
Write-Host "New version: $NewVersion"
"package_version=$NewVersion" >> $env:GITHUB_OUTPUT
create_nuget:
needs: [compute_version]
runs-on: windows-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
- name: Create artifacts directory
run: New-Item -ItemType Directory -Force -Path artifacts
- run: ./build.ps1 -Version ${{ needs.compute_version.outputs.package_version }}
- uses: actions/upload-artifact@v7
with:
name: nuget
if-no-files-found: error
retention-days: 3
path: "${{ env.NUGET_DIRECTORY }}/*.nupkg"
test:
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.runs-on }}
needs: [create_nuget, compute_version]
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: actions/download-artifact@v8
with:
name: nuget
path: ${{ env.NUGET_DIRECTORY }}
- uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- run: Get-ChildItem "${{ env.NUGET_DIRECTORY }}/*" -Recurse
- run: dotnet --info
- run: dotnet nuget locals all --clear
# CheckEnforcement is for SDK consumers, not the SDK repo itself
# (SDK repo uses Microsoft.NET.Sdk, can't dogfood ANcpLua.NET.Sdk)
- run: dotnet test --project tests/ANcpLua.Sdk.Tests/ANcpLua.Sdk.Tests.csproj --report-xunit-trx --report-github --results-directory test_results
env:
CI: true
NUGET_DIRECTORY: ${{ env.NUGET_DIRECTORY }}
PACKAGE_VERSION: ${{ needs.compute_version.outputs.package_version }}
- uses: actions/upload-artifact@v7
if: always()
with:
name: test_results_${{ matrix.runs-on }}
path: test_results
deploy:
runs-on: ubuntu-latest
needs: [create_nuget, lint_config, test, compute_version]
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: actions/download-artifact@v8
with:
name: nuget
path: ${{ env.NUGET_DIRECTORY }}
- uses: actions/setup-dotnet@v5
- name: Must Publish Packages
id: has_changes
run: |
# When HEAD is tagged (release commit), diff against the PREVIOUS tag
# to detect changes. Without this, git diff $tag HEAD is always empty.
$ExactTag = git describe --tags --exact-match HEAD 2>$null
if ($ExactTag) {
Write-Host "HEAD is tagged: $ExactTag — finding previous tag"
$PreviousTag = git describe --tags --abbrev=0 "$ExactTag~1" 2>$null
} else {
$PreviousTag = git describe --tags --abbrev=0 2>$null
}
if ($PreviousTag) {
Write-Host "Previous tag: $PreviousTag"
$Changes = git diff --name-only $PreviousTag HEAD -- '*.nuspec' 'src/**/*'
} else {
Write-Host "No previous tag found, checking all files"
$Changes = $true
}
if ($Changes) {
Write-Host "Changes: $Changes"
echo "has_changes=true" >> $env:GITHUB_OUTPUT
exit 0
} else {
Write-Host "No changes detected in .nuspec or src/ files"
echo "has_changes=false" >> $env:GITHUB_OUTPUT
exit 0
}
- name: Publish NuGet packages
if: ${{ steps.has_changes.outputs.has_changes == 'true' && github.ref == 'refs/heads/main' }}
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
Write-Host "Publishing to NuGet.org"
$files = Get-ChildItem "${{ env.NUGET_DIRECTORY }}/*" -Recurse -Include *.nupkg
foreach ($file in $files) {
Write-Host "Pushing: $($file.Name)"
& dotnet nuget push "$($file.FullName)" --api-key "$env:NUGET_API_KEY" --source https://api.nuget.org/v3/index.json --skip-duplicate
}
- run: gh release create "${{ needs.compute_version.outputs.package_version }}" --generate-notes
if: ${{ steps.has_changes.outputs.has_changes == 'true' && github.ref == 'refs/heads/main' }}
env:
GH_TOKEN: ${{ github.token }}