Merge pull request #2 from Encamina/@lmarcos/pipeline_improvements #3
Workflow file for this run
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: GitHubAction | |
on: | |
push: | |
branches: | |
- releases/* | |
env: | |
BuildConfiguration: ${{ startsWith(github.ref, 'refs/heads/releases') && 'Release' || 'Debug' }} | |
jobs: | |
CI: | |
runs-on: ubuntu-latest | |
outputs: | |
release_version: ${{ steps.PassOutputReleaseVersion.releaseVersion }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Using .NET from 'global.json' | |
uses: actions/setup-dotnet@v3 | |
with: | |
global-json-file: global.json | |
- name: Restore NuGet Packages | |
run: dotnet restore --configfile NuGet.config --verbosity Minimal | |
- 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@v3 | |
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 --output nupkg | |
- name: Sonar - Install SonarCloud scanners | |
run: | | |
dotnet tool install --global dotnet-sonarscanner | |
- name: Sonar - Build and analyze | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: | | |
dotnet-sonarscanner begin /k:"${{ secrets.SONAR_PROJECT_KEY }}" /o:"encamina" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.exclusions="**/tst/**/*" /d:sonar.cs.opencover.reportsPaths="**/tst/**/coverage.opencover.xml" | |
dotnet build --configuration ${{env.BuildConfiguration}} | |
dotnet test --collect:"XPlat Code Coverage;Format=opencover" | |
dotnet-sonarscanner end | |
- 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@v3 | |
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') | |
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@v3 | |
with: | |
name: enmarcha-libraries-${{ github.run_number }} | |
path: ./ | |
- name: Unzip Libraries | |
run: | | |
cd ${{ github.workspace }} | |
unzip nupkg.zip -d nupkg | |
- 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 | |
uses: actions/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: "v${{ steps.PassOutputReleaseVersion.outputs.RELEASE_VERSION }}" | |
release_name: "Release ${{ steps.PassOutputReleaseVersion.outputs.RELEASE_VERSION }}" | |
draft: false | |
prerelease: false | |
- name: Upload Release Assets | |
uses: actions/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./nupkg.zip | |
asset_name: enmarcha-libraries-${{ steps.PassOutputReleaseVersion.outputs.RELEASE_VERSION }}.zip | |
asset_content_type: application/zip |