Skip to content

.NET Build

.NET Build #102

Workflow file for this run

name: .NET Build
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
env:
VERSION: 1.2.${{ github.run_number }}
USERNAME: lk-code
NUGET_FILE: "**/*.nupkg"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 8.0.x
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu'
- name: Restore dependencies
run: dotnet restore source/
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: pwsh
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Start Analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: pwsh
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"lk-code_fluent-data-builder" /o:"lk-code-github" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
- name: Initialize GitHub NuGet Provider
shell: pwsh
run: |
dotnet nuget add source --username ${{ env.USERNAME }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/lk-code/index.json"
- name: Build FluentDataBuilder
shell: pwsh
run: |
dotnet build -c Release source/FluentDataBuilder/FluentDataBuilder.csproj
- name: Pack FluentDataBuilder
shell: pwsh
run: |
dotnet pack -c Release source/FluentDataBuilder/FluentDataBuilder.csproj /p:PackageVersion=${{ env.VERSION }}
- name: Temporary NuGet FluentDataBuilder
shell: pwsh
run: |
dotnet nuget push source/FluentDataBuilder/nupkg/FluentDataBuilder.${{ env.VERSION }}.nupkg --source https://nuget.pkg.github.com/lk-code/index.json --api-key ${{ secrets.GITHUB_TOKEN }}
- name: Wait for FluentDataBuilder Published
shell: pwsh
run: |
$i = 0
$max = 10
$sleep = 5
$url = "https://nuget.pkg.github.com/lk-code/fluentdatabuilder/${{ env.VERSION }}.json"
$headers = @{
"Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}"
}
do {
$i++
Write-Host "Waiting for NuGet to publish $url"
Start-Sleep -Seconds $sleep
} while ((Invoke-WebRequest -Uri $url -UseBasicParsing -Headers $headers).StatusCode -ne 200 -and $i -lt $max)
if ($i -eq $max) {
throw "NuGet not published after $max tries"
}
- name: Add NuGets FluentDataBuilder.Json
shell: pwsh
run: |
dotnet add source/FluentDataBuilder.Json/FluentDataBuilder.Json.csproj package FluentDataBuilder --version ${{ env.VERSION }}
- name: Build FluentDataBuilder.Json
shell: pwsh
run: |
dotnet build -c Release source/FluentDataBuilder.Json/FluentDataBuilder.Json.csproj
- name: Pack FluentDataBuilder.Json
shell: pwsh
run: |
dotnet pack -c Release source/FluentDataBuilder.Json/FluentDataBuilder.Json.csproj /p:PackageVersion=${{ env.VERSION }}
- name: Temporary NuGet FluentDataBuilder.Json
shell: pwsh
run: |
dotnet nuget push source/FluentDataBuilder.Json/nupkg/FluentDataBuilder.Json.${{ env.VERSION }}.nupkg --source https://nuget.pkg.github.com/lk-code/index.json --api-key ${{ secrets.GITHUB_TOKEN }}
- name: Wait for FluentDataBuilder.Json Published
shell: pwsh
run: |
$i = 0
$max = 10
$sleep = 5
$url = "https://nuget.pkg.github.com/lk-code/fluentdatabuilder.json/${{ env.VERSION }}.json"
$headers = @{
"Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}"
}
do {
$i++
Write-Host "Waiting for NuGet to publish $url"
Start-Sleep -Seconds $sleep
} while ((Invoke-WebRequest -Uri $url -UseBasicParsing -Headers $headers).StatusCode -ne 200 -and $i -lt $max)
if ($i -eq $max) {
throw "NuGet not published after $max tries"
}
- name: Add NuGets FluentDataBuilder.NewtonsoftJson
shell: pwsh
run: |
dotnet add source/FluentDataBuilder.NewtonsoftJson/FluentDataBuilder.NewtonsoftJson.csproj package FluentDataBuilder --version ${{ env.VERSION }}
- name: Build FluentDataBuilder.NewtonsoftJson
shell: pwsh
run: |
dotnet build -c Release source/FluentDataBuilder.NewtonsoftJson/FluentDataBuilder.NewtonsoftJson.csproj
- name: Pack FluentDataBuilder.NewtonsoftJson
shell: pwsh
run: |
dotnet pack -c Release source/FluentDataBuilder.NewtonsoftJson/FluentDataBuilder.NewtonsoftJson.csproj /p:PackageVersion=${{ env.VERSION }}
- name: Temporary NuGet FluentDataBuilder.NewtonsoftJson
shell: pwsh
run: |
dotnet nuget push source/FluentDataBuilder.NewtonsoftJson/nupkg/FluentDataBuilder.NewtonsoftJson.${{ env.VERSION }}.nupkg --source https://nuget.pkg.github.com/lk-code/index.json --api-key ${{ secrets.GITHUB_TOKEN }}
- name: Wait for FluentDataBuilder.NewtonsoftJson Published
shell: pwsh
run: |
$i = 0
$max = 10
$sleep = 5
$url = "https://nuget.pkg.github.com/lk-code/fluentdatabuilder.newtonsoftjson/${{ env.VERSION }}.json"
$headers = @{
"Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}"
}
do {
$i++
Write-Host "Waiting for NuGet to publish $url"
Start-Sleep -Seconds $sleep
} while ((Invoke-WebRequest -Uri $url -UseBasicParsing -Headers $headers).StatusCode -ne 200 -and $i -lt $max)
if ($i -eq $max) {
throw "NuGet not published after $max tries"
}
- name: Add NuGets FluentDataBuilder.Xml
shell: pwsh
run: |
dotnet add source/FluentDataBuilder.Xml/FluentDataBuilder.Xml.csproj package FluentDataBuilder --version ${{ env.VERSION }}
- name: Build FluentDataBuilder.Xml
shell: pwsh
run: |
dotnet build -c Release source/FluentDataBuilder.Xml/FluentDataBuilder.Xml.csproj
- name: Pack FluentDataBuilder.Xml
shell: pwsh
run: |
dotnet pack -c Release source/FluentDataBuilder.Xml/FluentDataBuilder.Xml.csproj /p:PackageVersion=${{ env.VERSION }}
- name: Temporary NuGet FluentDataBuilder.Xml
shell: pwsh
run: |
dotnet nuget push source/FluentDataBuilder.Xml/nupkg/FluentDataBuilder.Xml.${{ env.VERSION }}.nupkg --source https://nuget.pkg.github.com/lk-code/index.json --api-key ${{ secrets.GITHUB_TOKEN }}
- name: Wait for FluentDataBuilder.Xml Published
shell: pwsh
run: |
$i = 0
$max = 10
$sleep = 5
$url = "https://nuget.pkg.github.com/lk-code/fluentdatabuilder.xml/${{ env.VERSION }}.json"
$headers = @{
"Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}"
}
do {
$i++
Write-Host "Waiting for NuGet to publish $url"
Start-Sleep -Seconds $sleep
} while ((Invoke-WebRequest -Uri $url -UseBasicParsing -Headers $headers).StatusCode -ne 200 -and $i -lt $max)
if ($i -eq $max) {
throw "NuGet not published after $max tries"
}
- name: Add NuGets FluentDataBuilder.Yaml
shell: pwsh
run: |
dotnet add source/FluentDataBuilder.Yaml/FluentDataBuilder.Yaml.csproj package FluentDataBuilder --version ${{ env.VERSION }}
- name: Build FluentDataBuilder.Yaml
shell: pwsh
run: |
dotnet build -c Release source/FluentDataBuilder.Yaml/FluentDataBuilder.Yaml.csproj
- name: Pack FluentDataBuilder.Yaml
shell: pwsh
run: |
dotnet pack -c Release source/FluentDataBuilder.Yaml/FluentDataBuilder.Yaml.csproj /p:PackageVersion=${{ env.VERSION }}
- name: Temporary NuGet FluentDataBuilder.Yaml
shell: pwsh
run: |
dotnet nuget push source/FluentDataBuilder.Yaml/nupkg/FluentDataBuilder.Yaml.${{ env.VERSION }}.nupkg --source https://nuget.pkg.github.com/lk-code/index.json --api-key ${{ secrets.GITHUB_TOKEN }}
- name: Wait for FluentDataBuilder.Yaml Published
shell: pwsh
run: |
$i = 0
$max = 10
$sleep = 5
$url = "https://nuget.pkg.github.com/lk-code/fluentdatabuilder.yaml/${{ env.VERSION }}.json"
$headers = @{
"Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}"
}
do {
$i++
Write-Host "Waiting for NuGet to publish $url"
Start-Sleep -Seconds $sleep
} while ((Invoke-WebRequest -Uri $url -UseBasicParsing -Headers $headers).StatusCode -ne 200 -and $i -lt $max)
if ($i -eq $max) {
throw "NuGet not published after $max tries"
}
- name: Add NuGets FluentDataBuilder.Microsoft.Extensions.Configuration
shell: pwsh
run: |
dotnet add source/FluentDataBuilder.Microsoft.Extensions.Configuration/FluentDataBuilder.Microsoft.Extensions.Configuration.csproj package FluentDataBuilder --version ${{ env.VERSION }}
dotnet add source/FluentDataBuilder.Microsoft.Extensions.Configuration/FluentDataBuilder.Microsoft.Extensions.Configuration.csproj package FluentDataBuilder.Json --version ${{ env.VERSION }}
- name: Build FluentDataBuilder.Microsoft.Extensions.Configuration
shell: pwsh
run: |
dotnet build -c Release source/FluentDataBuilder.Microsoft.Extensions.Configuration/FluentDataBuilder.Microsoft.Extensions.Configuration.csproj
- name: Pack FluentDataBuilder.Microsoft.Extensions.Configuration
shell: pwsh
run: |
dotnet pack -c Release source/FluentDataBuilder.Microsoft.Extensions.Configuration/FluentDataBuilder.Microsoft.Extensions.Configuration.csproj /p:PackageVersion=${{ env.VERSION }}
- name: Temporary NuGet FluentDataBuilder.Microsoft.Extensions.Configuration
shell: pwsh
run: |
dotnet nuget push source/FluentDataBuilder.Microsoft.Extensions.Configuration/nupkg/FluentDataBuilder.Microsoft.Extensions.Configuration.${{ env.VERSION }}.nupkg --source https://nuget.pkg.github.com/lk-code/index.json --api-key ${{ secrets.GITHUB_TOKEN }}
- name: Wait for FluentDataBuilder.Microsoft.Extensions.Configuration Published
shell: pwsh
run: |
$i = 0
$max = 10
$sleep = 5
$url = "https://nuget.pkg.github.com/lk-code/fluentdatabuilder.microsoft.extensions.configuration/${{ env.VERSION }}.json"
$headers = @{
"Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}"
}
do {
$i++
Write-Host "Waiting for NuGet to publish $url"
Start-Sleep -Seconds $sleep
} while ((Invoke-WebRequest -Uri $url -UseBasicParsing -Headers $headers).StatusCode -ne 200 -and $i -lt $max)
if ($i -eq $max) {
throw "NuGet not published after $max tries"
}
- name: Finish Analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: pwsh
run: |
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
- name: Set Version Git Tag
run: |
git tag ${{ env.VERSION }}
git push origin ${{ env.VERSION }}
- name: Upload Build Artifact
uses: actions/[email protected]
with:
name: ${{ env.VERSION }}
path: "**/*.${{ env.VERSION }}.nupkg"
- name: Publish
run: dotnet nuget push "**/*.${{ env.VERSION }}.nupkg" --no-symbols --skip-duplicate --api-key ${{ secrets.NUGET_API_KEY }} --source "nuget.org"