Merge pull request #15 from magic5644/feat-refactor-code #164
This file contains hidden or 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
| # This workflow will build a .NET project | |
| # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net | |
| name: .NET | |
| on: | |
| push: | |
| branches: ["main"] | |
| pull_request: | |
| branches: ["main"] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: 9.0.x | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build | |
| run: dotnet build --no-restore | |
| - run: dotnet test --results-directory "test-results" --collect:"Code Coverage" | |
| - run: dotnet tool update --global dotnet-coverage | |
| - run: dotnet-coverage merge --output test-result.cobertura.xml --output-format cobertura "test-results/**/*.coverage" | |
| - run: dotnet tool install --global dotnet-reportgenerator-globaltool | |
| - run: reportgenerator -reports:test-result.cobertura.xml -targetdir:coverage-report -reporttypes:"Html;JsonSummary;MarkdownSummaryGithub;Badges" | |
| - run: cat coverage-report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY | |
| - name: ReportGenerator | |
| uses: danielpalme/[email protected] | |
| with: | |
| reports: "test-result.cobertura.xml" | |
| targetdir: "coverage-report" | |
| reporttypes: "Html;JsonSummary;MarkdownSummaryGithub;Badges" | |
| - name: Upload coverage report artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: coverage-report | |
| - name: Upload coverage badge artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-badge.svg | |
| path: coverage-report/badge_combined.svg | |
| - name: Add comment to PR | |
| if: github.event_name == 'pull_request' | |
| run: gh pr comment $PR_NUMBER --body-file coverage-report/SummaryGithub.md | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| - name: Publish coverage in build summary # Only applicable if 'MarkdownSummaryGithub' or one of the other Markdown report types is generated | |
| run: cat coverage-report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY # Adjust path and filename if necessary | |
| shell: bash | |
| - name: Generate Coverage Badge | |
| run: | | |
| echo "" > coverage-badge.md | |
| cat coverage-badge.md >> README.md | |
| publish_badge: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Checkout gh-pages | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GH_PAT }} | |
| repository: "magic5644/magic5644" | |
| ref: gh-pages | |
| - name: download badge | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: coverage-badge.svg | |
| path: coverage-report/badge_combined.svg | |
| - name: Deploy Badges | |
| uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| commit_message: "Update badges [skip ci]" | |
| branch: gh-pages | |
| skip_fetch: true | |
| skip_checkout: true | |
| file_pattern: "*.svg" |