Fix version script to exclude merge commits and order logs correctly #455
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: .NET Workflow | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
pull_request: | |
schedule: | |
- cron: "0 14 * * *" | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
permissions: | |
packages: write | |
contents: write | |
env: | |
OUTPUT_PATH: 'output' | |
STAGING_PATH: 'staging' | |
DOTNET_VERSION: '9.0' | |
jobs: | |
dotnet: | |
name: .NET Workflow | |
runs-on: windows-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
persist-credentials: true | |
- name: Fetch tags | |
shell: pwsh | |
run: | | |
git fetch --prune --unshallow --tags | |
$global:LASTEXITCODE = 0 | |
- name: Configure Environment | |
shell: pwsh | |
run: | | |
$IS_MAIN = "${{ github.ref }}" -eq "refs/heads/main" | |
$IS_TAGGED = (git show-ref --tags -d | Out-String).Contains("${{ github.sha }}") | |
$SHOULD_RELEASE = ($IS_MAIN -AND -NOT $IS_TAGGED) | |
$USE_DOTNET_SCRIPT = (Get-ChildItem -Recurse -Filter *.csx).Count -gt 0 | |
$PACKAGE_PATTERN = Join-Path -Path "${{ github.workspace }}" -ChildPath "${{ env.STAGING_PATH }}" -AdditionalChildPath "*.nupkg" | |
$SYMBOLS_PATTERN = Join-Path -Path "${{ github.workspace }}" -ChildPath "${{ env.STAGING_PATH }}" -AdditionalChildPath "*.snupkg" | |
$APPLICATION_PATTERN = Join-Path -Path "${{ github.workspace }}" -ChildPath "${{ env.STAGING_PATH }}" -AdditionalChildPath "*.zip" | |
$BUILD_ARGS = "" | |
$BUILD_ARGS += $USE_DOTNET_SCRIPT ? "-maxCpuCount:1" : "" | |
"IS_MAIN=$IS_MAIN" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
"IS_TAGGED=$IS_TAGGED" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
"SHOULD_RELEASE=$SHOULD_RELEASE" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
"USE_DOTNET_SCRIPT=$USE_DOTNET_SCRIPT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
"PACKAGE_PATTERN=$PACKAGE_PATTERN" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
"SYMBOLS_PATTERN=$SYMBOLS_PATTERN" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
"APPLICATION_PATTERN=$APPLICATION_PATTERN" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
"BUILD_ARGS=$BUILD_ARGS" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
Write-Host "IS_MAIN: $IS_MAIN" | |
Write-Host "IS_TAGGED: $IS_TAGGED" | |
Write-Host "SHOULD_RELEASE: $SHOULD_RELEASE" | |
Write-Host "USE_DOTNET_SCRIPT: $USE_DOTNET_SCRIPT" | |
Write-Host "PACKAGE_PATTERN: $PACKAGE_PATTERN" | |
Write-Host "SYMBOLS_PATTERN: $SYMBOLS_PATTERN" | |
Write-Host "APPLICATION_PATTERN: $APPLICATION_PATTERN" | |
Write-Host "BUILD_ARGS: $BUILD_ARGS" | |
$global:LASTEXITCODE = 0 | |
- name: Make Version | |
shell: pwsh | |
run: scripts/make-version.ps1 "${{ github.sha }}" | |
- name: Make License | |
shell: pwsh | |
run: scripts/make-license.ps1 "${{ github.server_url }}" "${{ github.repository_owner }}" "${{ github.repository }}" | |
- name: Make Changelog | |
shell: pwsh | |
run: scripts/make-changelog.ps1 "${{ env.VERSION }}" "${{ github.sha }}" | |
- name: Commit Metadata | |
shell: pwsh | |
run: scripts/commit-metadata.ps1 | |
- name: Setup .NET Core SDK | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: | | |
${{ env.DOTNET_VERSION }}.x | |
- name: Install dotnet-script | |
if: ${{ env.USE_DOTNET_SCRIPT == 'True' }} | |
shell: pwsh | |
run: dotnet tool install -g dotnet-script | |
- name: Build | |
shell: pwsh | |
run: dotnet build --configuration Release --verbosity normal --no-incremental ${{ env.BUILD_ARGS }} | |
- name: Test | |
shell: pwsh | |
run: dotnet test --configuration Release --verbosity normal --no-build | |
- name: Detect Dependencies | |
if: ${{ env.SHOULD_RELEASE == 'True' }} | |
uses: advanced-security/component-detection-dependency-submission-action@v0.0.2 | |
- name: Package Libraries | |
if: ${{ env.SHOULD_RELEASE == 'True' }} | |
shell: pwsh | |
run: dotnet pack --configuration Release --output ${{ github.workspace }}/${{ env.STAGING_PATH }} | |
- name: Package Applications | |
if: ${{ env.SHOULD_RELEASE == 'True' }} | |
shell: pwsh | |
run: | | |
if (Test-Path ${{ github.workspace }}/${{ env.OUTPUT_PATH }}) { | |
Remove-Item -Recurse -Force ${{ github.workspace }}/${{ env.OUTPUT_PATH }} | |
} | |
Get-ChildItem -Recurse -Filter *.csproj | ForEach-Object { | |
$csproj = $_ | |
$projName = [System.IO.Path]::GetFileNameWithoutExtension($csproj) | |
$outDir = "${{ github.workspace }}/${{ env.OUTPUT_PATH }}/$projName" | |
$stageDir = "${{ github.workspace }}/${{ env.STAGING_PATH }}" | |
$stageFile = "$stageDir/$projName-${{ env.VERSION }}.zip" | |
New-Item -Path $outDir -ItemType Directory -Force | |
New-Item -Path $stageDir -ItemType Directory -Force | |
dotnet publish $csproj --no-build --configuration Release --framework net${{ env.DOTNET_VERSION }} --output $outDir | |
Compress-Archive -Path $outDir/* -DestinationPath $stageFile | |
} | |
- name: Publish Libraries to GitHub | |
if: ${{ env.SHOULD_RELEASE == 'True' && hashFiles(env.PACKAGE_PATTERN) != '' }} | |
shell: pwsh | |
run: dotnet nuget push ${{ env.PACKAGE_PATTERN }} --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate | |
- name: Publish Libraries to NuGet | |
if: ${{ env.SHOULD_RELEASE == 'True' && hashFiles(env.PACKAGE_PATTERN) != '' }} | |
shell: pwsh | |
run: dotnet nuget push ${{ env.PACKAGE_PATTERN }} --api-key ${{ secrets.NUGET_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate | |
- name: Release | |
if: ${{ env.SHOULD_RELEASE == 'True' }} | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: "${{ env.PACKAGE_PATTERN }},${{ env.SYMBOLS_PATTERN }},${{ env.APPLICATION_PATTERN }}" | |
tag: v${{ env.VERSION }} | |
commit: ${{ env.RELEASE_HASH }} | |
allowUpdates: false | |
skipIfReleaseExists: true | |
omitBody: true | |
generateReleaseNotes: true | |
replacesArtifacts: false | |
makeLatest: true |