Merge pull request #142 from Encamina/@mramos/factorial-improvements #330
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: ENMARCHA NuGet | |
on: | |
push: | |
branches: | |
- releases/** | |
- main | |
paths-ignore: | |
- '/**/*.md' | |
pull_request: | |
types: | |
- opened | |
- reopened | |
- synchronize | |
- ready_for_review | |
branches: | |
- releases/** | |
- main | |
workflow_dispatch: | |
env: | |
BuildConfiguration: ${{ (startsWith(github.ref, 'refs/heads/releases') || startsWith(github.ref, 'refs/heads/main')) && 'Release' || 'Debug' }} | |
jobs: | |
CI: | |
runs-on: ubuntu-latest | |
outputs: | |
release_version: ${{ steps.PassOutputReleaseVersion.releaseVersion }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set Java for SonarCloud | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'microsoft' | |
java-version: '21' | |
- name: Using .NET from 'global.json' | |
uses: actions/setup-dotnet@v4 | |
with: | |
global-json-file: global.json | |
- name: Restore NuGet Packages | |
run: dotnet restore --configfile NuGet.config --verbosity Minimal | |
- name: Sonar - Install SonarCloud scanners | |
run: dotnet tool install --global dotnet-sonarscanner --version 6.0.0 | |
- name: Sonar - Begin Analyze | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: dotnet-sonarscanner begin /k:"${{ secrets.SONAR_PROJECT_KEY }}" /o:"${{ secrets.SONAR_ORGANIZATION }}" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.exclusions="**/tst/**/*" /d:sonar.cs.opencover.reportsPaths="**/tst/**/coverage.opencover.xml" | |
- name: Test | |
run: dotnet test --nologo --no-restore --collect:"XPlat Code Coverage" --configuration ${{env.BuildConfiguration}} --settings coverlet.runsettings | |
- name: Install Report Generator Tool | |
run: dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools --ignore-failed-sources | |
- name: Generate Coverage Report | |
run: ./tools/reportgenerator -reports:./**/coverage.cobertura.xml -targetdir:coverage/Cobertura -reporttypes:'MarkdownSummaryGithub;Cobertura' | |
- name: Publish Coverage Report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: code-coverage-report | |
path: coverage/Cobertura/ | |
- name: Write Coverage Report to Job Summary | |
run: cat coverage/Cobertura/SummaryGithub.md >> $GITHUB_STEP_SUMMARY | |
- name: Build & Pack Libraries | |
run: dotnet pack --nologo --no-restore --configuration ${{env.BuildConfiguration}} -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg -p:SourceLinkCreate=true -p:DebugType=full --output nupkg | |
- name: Sonar - End Analyze | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" | |
- name: Zip Libraries | |
run: | | |
cd ${{ github.workspace }}/nupkg | |
zip -r nupkg.zip * | |
mv ./nupkg.zip ${{ github.workspace }} | |
- name: Upload Libraries for Continuous Deployment | |
uses: actions/upload-artifact@v4 | |
with: | |
name: enmarcha-libraries-${{ github.run_number }} | |
path: nupkg.zip | |
CD: | |
runs-on: ubuntu-latest | |
needs: CI | |
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/heads/releases') || github.ref == 'refs/heads/main') | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Read and Store Version | |
id: PassOutputReleaseVersion | |
shell: pwsh | |
run: | | |
$xml = [Xml] (Get-Content "${{ github.workspace }}/Directory.Build.props") | |
$prefix = [System.Linq.Enumerable]::FirstOrDefault($xml.Project.PropertyGroup.VersionPrefix, [Func[object,bool]]{ param($x) $x -ne $null }) | |
$suffix = [System.Linq.Enumerable]::FirstOrDefault($xml.Project.PropertyGroup.VersionSuffix, [Func[object,bool]]{ param($x) $x -ne $null }) | |
$release_version = ($prefix, $suffix) | ? { $_ } | Join-String -Separator "-" | |
echo "RELEASE_VERSION=$release_version" >> $env:GITHUB_OUTPUT | |
- name: Download Libraries for Continuous Deployment | |
uses: actions/download-artifact@v4 | |
with: | |
name: enmarcha-libraries-${{ github.run_number }} | |
path: ./ | |
- name: Unzip Libraries | |
run: | | |
cd ${{ github.workspace }} | |
unzip nupkg.zip -d nupkg | |
# Use --skip-duplicate to prevent errors if a package with the same version already exists. | |
# When retrying a failed workflow, already published packages will be skipped without error. | |
- name: Push Libraries to NuGet.org | |
run: dotnet nuget push **/*.nupkg --api-key ${{ secrets.NUGET_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate | |
- name: Create Tag | |
run: | | |
git config --global user.name "${{ github.actor }}" | |
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
git tag -a "Release-${{ steps.PassOutputReleaseVersion.outputs.RELEASE_VERSION }}" -m "Version from build ${{ github.run_number }}" | |
- name: Create Release | |
id: create_release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
tag: "v${{ steps.PassOutputReleaseVersion.outputs.RELEASE_VERSION }}" | |
title: "Release ${{ steps.PassOutputReleaseVersion.outputs.RELEASE_VERSION }}" | |
run: | | |
gh release create "$tag" \ | |
--repo="$GITHUB_REPOSITORY" \ | |
--title="$title" \ | |
--generate-notes | |
- name: Upload Release Assets | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
releaseAssetName: enmarcha-libraries-${{ steps.PassOutputReleaseVersion.outputs.RELEASE_VERSION }}.zip | |
tag: "v${{ steps.PassOutputReleaseVersion.outputs.RELEASE_VERSION }}" | |
run: | | |
mv nupkg.zip $releaseAssetName | |
gh release upload "$tag" "$releaseAssetName" --repo="$GITHUB_REPOSITORY" |