From ef44a2a0a0d7d470b4b91c0ee3634a9a7737388f Mon Sep 17 00:00:00 2001 From: Hassan Abedi Date: Fri, 17 Jan 2025 16:13:10 +0100 Subject: [PATCH] Fix the examples and improve the README.md - Added information about searching for games to the main README.md - Debugged the PowerShell example script - Added code coverage and code quality badges to README.md - Updated the GitHub Actions workflow to generate the code coverage report - Updated the Makefile to include a target for generating the coverage report --- .github/workflows/tests.yml | 9 +++++++- .gitignore | 1 + Makefile | 6 +++++ README.md | 34 ++++++++++++++++++++-------- docs/examples/download_all_games.ps1 | 22 +++++++++--------- 5 files changed, 51 insertions(+), 21 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f00352f..fb1ca88 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,7 +28,14 @@ jobs: make format continue-on-error: false - - name: Run Tests + - name: Run Tests and Generate Coverage Report run: | make test + make codecov continue-on-error: false + + # Upload the coverage report to Codecov + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 3556360..f9a551d 100644 --- a/.gitignore +++ b/.gitignore @@ -84,3 +84,4 @@ catalogue.csv gogg/ games/ gogg_catalogue* +coverage.txt diff --git a/Makefile b/Makefile index 3b0e7f6..e51eafe 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ help: @echo " snap Build the Snap package" @echo " install-deps Install development dependencies on Debian-based systems" @echo " lint Lint Go files to check for potential errors" + @echo " codecov Create test coverage report for Codecov" @echo " help Show this help message" # Building the project @@ -98,3 +99,8 @@ install-deps: lint: @echo "Linting Go files..." golangci-lint run ./... + +# Create Test Coverage Report for Codecov +codecov: format + @echo "Uploading coverage report to Codecov..." + go test -coverprofile=coverage.txt ./... diff --git a/README.md b/README.md index be14882..c0bfc3a 100644 --- a/README.md +++ b/README.md @@ -11,24 +11,33 @@ Tests + + Linux Build + + + Windows Build + + + MacOS Build + +
Go Report Card Go Reference - - Release + + Code Coverage -
- - Linux Build + + CodeFactor - - Windows Build + + Release - - MacOS Build + + Total Downloads

@@ -94,6 +103,13 @@ gogg auth gogg catalogue refresh ``` +#### Searching for Games + +```bash +# Will search for games with the the term `witcher` in their title +gogg catalogue search --term witcher +``` + #### Downloading a Game ```bash diff --git a/docs/examples/download_all_games.ps1 b/docs/examples/download_all_games.ps1 index f867fe8..694c043 100644 --- a/docs/examples/download_all_games.ps1 +++ b/docs/examples/download_all_games.ps1 @@ -12,7 +12,7 @@ Write-Host "${GREEN}The code in this script downloads all games owned by the use Write-Host "${GREEN}============================================================================================${NC}" $DEBUG_MODE = 1 # Debug mode enabled -$GOGG = (Get-Command "bin\gogg" -ErrorAction SilentlyContinue) -or (Get-Command "gogg" -ErrorAction SilentlyContinue) +$GOGG = ".\gogg" # Path to Gogg's executable file (for example, ".\bin\gogg") $LANG = "en" # Language English $PLATFORM = "windows" # Platform Windows @@ -22,19 +22,18 @@ $RESUME_DOWNLOAD = 1 # Resume download $NUM_THREADS = 4 # Number of worker threads for downloading # Function to clean up the CSV file -function Cleanup { - if ($latest_csv) { +function Cleanup +{ + if ($latest_csv) + { Remove-Item -Force $latest_csv - if ($?) { + if ($?) + { Write-Host "${RED}Cleanup: removed $latest_csv${NC}" } } } -# Trap Ctrl+C and call Cleanup -$global:latest_csv = $null -Register-ObjectEvent -InputObject $Host -EventName "CancelKeyPress" -Action { Cleanup } - # Update game catalogue and export it to a CSV file & $GOGG catalogue refresh & $GOGG catalogue export --format csv --dir ./ @@ -43,12 +42,13 @@ Register-ObjectEvent -InputObject $Host -EventName "CancelKeyPress" -Action { Cl $latest_csv = Get-ChildItem -Path . -Filter "gogg_catalogue_*.csv" | Sort-Object LastWriteTime -Descending | Select-Object -First 1 # Check if the catalogue file exists -if (-not $latest_csv) { +if (-not $latest_csv) +{ Write-Host "${RED}No CSV file found.${NC}" exit 1 } -Write-Host "${GREEN}Using catalogue file: $($latest_csv.Name)${NC}" +Write-Host "${GREEN}Using catalogue file: $( $latest_csv.Name )${NC}" # Download each game listed in catalogue file, skipping the first line Get-Content $latest_csv.FullName | Select-Object -Skip 1 | ForEach-Object { @@ -56,10 +56,10 @@ Get-Content $latest_csv.FullName | Select-Object -Skip 1 | ForEach-Object { $game_id = $fields[0] $game_title = $fields[1] Write-Host "${YELLOW}Game ID: $game_id, Title: $game_title${NC}" + $env:DEBUG_GOGG = $DEBUG_MODE & $GOGG download --id $game_id --dir "./games" --platform $PLATFORM --lang $LANG ` --dlcs $INCLUDE_DLC --extras $INCLUDE_EXTRA_CONTENT --resume $RESUME_DOWNLOAD --threads $NUM_THREADS Start-Sleep -Seconds 1 - # Remove the break to download all games } # Clean up