diff --git a/.github/scripts/update_badge.py b/.github/scripts/update_badge.py index d155b6f..0428dcd 100644 --- a/.github/scripts/update_badge.py +++ b/.github/scripts/update_badge.py @@ -1,30 +1,20 @@ -import glob -import json +import os import re -# Search for mutation-report.json in directories under a specific path -report_files = glob.glob('/home/runner/work/SO/SO/SO/Tests/UnitTests/StrykerOutput/*/reports/mutation-report.json') +# Retrieve mutation score from environment variable +mutation_score = os.environ.get("MUTATION_SCORE", "N/A") -if report_files: - # Take the first (or latest, depending on your criteria) report found - report_file = report_files[0] - - with open(report_file, 'r') as f: - data = json.load(f) - - mutation_score = data.get('mutationScore', None) - - # Read README file - with open('/home/runner/work/SO/SO/README.md', 'r') as readme_file: - readme_content = readme_file.read() - - # Update badge using a regular expression to match the old badge - updated_readme_content = re.sub( - r'!\[Mutation Score\]\(https://img\.shields\.io/badge/Mutation%20Score-[0-9.]+%-blue\)', - f'![Mutation Score](https://img.shields.io/badge/Mutation%20Score-{mutation_score}%25-blue)', - readme_content - ) - - # Write back updated content to README - with open('/home/runner/work/SO/SO/README.md', 'w') as readme_file: - readme_file.write(updated_readme_content) \ No newline at end of file +# Read README file +with open('/path/to/README.md', 'r') as readme_file: + readme_content = readme_file.read() + +# Update badge using a regular expression to match the old badge +updated_readme_content = re.sub( + r'!\[Mutation Score\]\(https://img\.shields\.io/badge/Mutation%20Score-[0-9.]+%-blue\)', + f'![Mutation Score](https://img.shields.io/badge/Mutation%20Score-{mutation_score}%25-blue)', + readme_content +) + +# Write back updated content to README +with open('/path/to/README.md', 'w') as readme_file: + readme_file.write(updated_readme_content) \ No newline at end of file diff --git a/.github/workflows/mutation-tests.yml b/.github/workflows/mutation-tests.yml index 3cf001e..d9bcae0 100644 --- a/.github/workflows/mutation-tests.yml +++ b/.github/workflows/mutation-tests.yml @@ -24,7 +24,7 @@ jobs: - name: Install dotnet-stryker run: dotnet tool install dotnet-stryker --tool-path /usr/local/bin - name: Run dotnet-stryker - run: /usr/local/bin/dotnet-stryker --project "Logic.csproj" --reporter "json" + run: /usr/local/bin/dotnet-stryker --project "Logic.csproj" >> stryker_log.txt working-directory: ./SO/Tests/UnitTests - name: Install Python Dependencies run: pip install PyGithub