Update test results badge path in dotnetcore.yml workflow #251
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: Publish | |
on: | |
push: | |
paths-ignore: | |
- 'badges/**' # Ignore pushes to the badges directory to prevent infinite loops | |
jobs: | |
build: | |
strategy: | |
matrix: | |
runs-on: [windows-latest] | |
runs-on: ${{ matrix.runs-on }} | |
name: Running tests on ${{ matrix.runs-on }}. | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
dotnet-version: '8.0.x' | |
ref: ${{ github.ref }} | |
- name: Install trx2junit | |
run: dotnet tool install -g trx2junit | |
- name: Build & Run tests | |
run: dotnet test --configuration Release --filter Name~CheckEmptyString_ShouldReturnWordToken --logger "trx;LogFileName=test-results.trx" | |
- name: Convert TRX to JUnit | |
run: | | |
$trxFiles = Get-ChildItem -Recurse -Filter test-results.trx | |
$trx2junitPath = (Get-Command trx2junit).Source | |
foreach ($trxFile in $trxFiles) { | |
& $trx2junitPath $trxFile.FullName --output ($trxFile.DirectoryName + "\test-results.xml") | |
} | |
- name: Merge JUnit results | |
run: | | |
$xmlFiles = Get-ChildItem -Recurse -File -Filter test-results.xml | |
$mergedXml = [xml]"<testsuites></testsuites>" | |
foreach ($xmlFile in $xmlFiles) { | |
$content = [xml](Get-Content $xmlFile.FullName) | |
foreach ($testsuite in $content.testsuites.testsuite) { | |
$importedNode = $mergedXml.ImportNode($testsuite, $true) | |
$mergedXml.DocumentElement.AppendChild($importedNode) > $null | |
} | |
} | |
$mergedXml.Save("merged-test-results.xml") | |
- name: Parse test results | |
id: parse | |
run: | | |
[xml]$testResults = Get-Content merged-test-results.xml | |
$total = ($testResults.testsuites.testsuite | Measure-Object -Property tests -Sum).Sum | |
$failures = ($testResults.testsuites.testsuite | Measure-Object -Property failures -Sum).Sum | |
$skipped = ($testResults.testsuites.testsuite | Measure-Object -Property skipped -Sum).Sum | |
$passed = $total - $failures - $skipped | |
echo "total=$total" >> $GITHUB_ENV | |
echo "passed=$passed" >> $GITHUB_ENV | |
echo "failed=$failures" >> $GITHUB_ENV | |
echo "skipped=$skipped" >> $GITHUB_ENV | |
echo "total=$total" >> $GITHUB_OUTPUT | |
echo "passed=$passed" >> $GITHUB_OUTPUT | |
- name: Create badge | |
if: "!contains(github.event.head_commit.message, '[skip ci]')" | |
run: | | |
curl -o tests-badge.svg "https://img.shields.io/badge/tests-${{ steps.parse.outputs.total }}%20%2F%20${{ steps.parse.outputs.passed }}-green" | |
- name: Commit badge | |
if: "!contains(github.event.head_commit.message, '[skip ci]')" | |
run: | | |
git config --global user.name "github-actions" | |
git config --global user.email "github-actions@github.com" | |
rm ./badges/tests-badge.svg | |
mv tests-badge.svg badges/tests-badge.svg | |
git add badges/tests-badge.svg | |
git commit -m "Update test results badge [skip ci]" | |
git push | |
- name: Publish | |
if: github.ref == 'refs/heads/master' | |
run: | | |
$scriptLocationDirectory=(Get-Location).ToString() | |
$scriptLocationFilePath=[System.IO.Path]::Combine($scriptLocationDirectory, "Publish.Nuget.ps1") | |
$nugetExecutable=[System.IO.Path]::Combine($scriptLocationDirectory, "nuget", "nuget.exe") | |
$projects = @('Musoq.Converter', 'Musoq.Evaluator', 'Musoq.Parser', 'Musoq.Plugins', 'Musoq.Schema') | |
foreach ($project in $projects) { | |
pushd | |
cd "./$project/bin/Release" | |
Invoke-Expression "$scriptLocationFilePath $nugetExecutable $project '${{ secrets.nuget_musoq_key }}'" | |
popd | |
} |