-
-
Notifications
You must be signed in to change notification settings - Fork 0
test: running SPRT in CI #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
96b00af
test: initial commit of sprt workflow
benthevining 3ccc769
Merge branch 'main' into sprt-ci
benthevining 8d53a7f
test: updating sprt workflow
benthevining f19d871
test: updating sprt workflow
benthevining a70f879
test: updating sprt workflow
benthevining 5f04325
test: updating sprt workflow
benthevining 163fe57
test: updating sprt workflow
benthevining 4f583b4
test: updating sprt workflow
benthevining c8e3450
test: updating sprt workflow
benthevining 0909a71
refactor: cmake
benthevining 52626ea
fix: sprt workflow
benthevining dacad60
refactor: sprt workflow
benthevining File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| # ====================================================================================== | ||
| # | ||
| # ░▒▓███████▓▒░░▒▓████████▓▒░▒▓███████▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░▒▓████████▓▒░ | ||
| # ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ | ||
| # ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ | ||
| # ░▒▓███████▓▒░░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ | ||
| # ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ | ||
| # ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ | ||
| # ░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░ | ||
| # | ||
| # ====================================================================================== | ||
|
|
||
| from pathlib import Path | ||
| import sys | ||
| import re | ||
| from enum import Enum | ||
|
|
||
| LOG_FILE = Path(sys.argv[1]) | ||
|
|
||
| with open(LOG_FILE, 'r') as file: | ||
| SPRT_OUTPUT = file.readlines() | ||
|
|
||
| # finds the indices of the last 2 '-----------------' lines in the output | ||
| # the final results report is in the fenced section between these 2 lines | ||
| def find_last_two_fences(): | ||
| indices = [] | ||
|
|
||
| for i, line in enumerate(reversed(SPRT_OUTPUT)): | ||
| if re.search(r"(--)+", line): | ||
| indices.append(len(SPRT_OUTPUT) - i) | ||
| if len(indices) == 2: | ||
| break | ||
|
|
||
| return sorted(indices) | ||
|
|
||
| def get_final_results_report(): | ||
| start, end = find_last_two_fences() | ||
|
|
||
| return SPRT_OUTPUT[start + 1 : end] | ||
|
|
||
| RESULTS = get_final_results_report() | ||
|
|
||
| # returns the first string that matches the given regex | ||
| def find_first_match(regex, strings): | ||
| for str in strings: | ||
| if re.search(regex, str): | ||
| return str | ||
|
|
||
| return '' | ||
|
|
||
| class EmojiType(Enum): | ||
| NEUTRAL = 1, | ||
| POSITIVE = 2, | ||
| NEGATIVE = 3 | ||
|
|
||
| def get_emoji(type): | ||
| match type: | ||
| case EmojiType.NEUTRAL: return '🟰' | ||
| case EmojiType.POSITIVE: return '✅' | ||
| case EmojiType.NEGATIVE: return '❌' | ||
|
|
||
| def get_elo(): | ||
| elo_line = find_first_match('Elo:', RESULTS) | ||
|
|
||
| first_space_idx = elo_line.find(' ') | ||
| second_space_idx = elo_line.find(' ', first_space_idx + 1) | ||
|
|
||
| return float( | ||
| elo_line[first_space_idx:second_space_idx] | ||
| ) | ||
|
|
||
| def get_elo_emoji(elo): | ||
| if abs(elo) <= 1: | ||
| return get_emoji(EmojiType.NEUTRAL) | ||
|
|
||
| if elo > 0: | ||
| return get_emoji(EmojiType.POSITIVE) | ||
|
|
||
| return get_emoji(EmojiType.NEGATIVE) | ||
|
|
||
| def get_result_breakdown(): | ||
| games_line = find_first_match('Games:', RESULTS) | ||
|
|
||
| second_space_idx = games_line.find(' ', | ||
| games_line.find(' ') + 1) | ||
|
|
||
| after_second_space = games_line[second_space_idx+1:] | ||
|
|
||
| # string format is: | ||
| # Wins: W, Losses: L, Draws: D, Points: 50.5 (50.50 %) | ||
|
|
||
| wins_comma_idx = after_second_space.find(',') | ||
|
|
||
| num_wins = int( | ||
| after_second_space[after_second_space.find(' ')+1:wins_comma_idx] | ||
| ) | ||
|
|
||
| after_wins = (after_second_space[after_second_space.find(' ', wins_comma_idx + 1):]).lstrip() | ||
|
|
||
| losses_comma_idx = after_wins.find(',') | ||
|
|
||
| num_losses = int( | ||
| after_wins[after_wins.find(' ')+1:losses_comma_idx] | ||
| ) | ||
|
|
||
| after_losses = (after_wins[after_wins.find(' ', losses_comma_idx + 1):]).lstrip() | ||
|
|
||
| draws_comma_idx = after_losses.find(',') | ||
|
|
||
| num_draws = int( | ||
| after_losses[after_losses.find(' ')+1:draws_comma_idx] | ||
| ) | ||
|
|
||
| after_draws = (after_losses[after_losses.find(' ', draws_comma_idx+1):]).lstrip() | ||
|
|
||
| pcnt = float( | ||
| after_draws[after_draws.find('(')+1:after_draws.find('%')] | ||
| ) | ||
|
|
||
| return ( | ||
| num_wins, num_losses, num_draws, pcnt | ||
| ) | ||
|
|
||
| def get_wins_emoji(wins): | ||
| if wins in range(45, 55): | ||
| return get_emoji(EmojiType.NEUTRAL) | ||
|
|
||
| if wins > 50: | ||
| return get_emoji(EmojiType.POSITIVE) | ||
|
|
||
| return get_emoji(EmojiType.NEGATIVE) | ||
|
|
||
| def get_losses_emoji(losses): | ||
| if losses in range(45, 55): | ||
| return get_emoji(EmojiType.NEUTRAL) | ||
|
|
||
| if losses > 50: | ||
| return get_emoji(EmojiType.NEGATIVE) | ||
|
|
||
| return get_emoji(EmojiType.POSITIVE) | ||
|
|
||
| def get_draws_emoji(draws, losses, wins): | ||
| if draws < losses: | ||
| return get_emoji(EmojiType.NEGATIVE) | ||
|
|
||
| if draws > wins: | ||
| return get_emoji(EmojiType.POSITIVE) | ||
|
|
||
| return get_emoji(EmojiType.NEUTRAL) | ||
|
|
||
| def get_pcnt_emoji(pcnt): | ||
| if pcnt in range(0, 45): | ||
| return get_emoji(EmojiType.NEGATIVE) | ||
|
|
||
| if pcnt in range(45, 55): | ||
| return get_emoji(EmojiType.NEUTRAL) | ||
|
|
||
| return get_emoji(EmojiType.POSITIVE) | ||
|
|
||
| # | ||
|
|
||
| def replace_pairs(old_values, new_values, string): | ||
| text = string | ||
|
|
||
| for old, new in zip(old_values, new_values): | ||
| text = text.replace(old, new) | ||
|
|
||
| return text | ||
|
|
||
| SCRIPT_DIR = Path(__file__).resolve().parent | ||
|
|
||
| with open(f'{SCRIPT_DIR}/sprt-results.md', 'r') as file: | ||
| MD_TEMPLATE_TEXT = file.read() | ||
|
|
||
| elo = get_elo() | ||
|
|
||
| num_wins, num_losses, num_draws, pcnt = get_result_breakdown() | ||
|
|
||
| print( | ||
| replace_pairs( | ||
| ['%ELO%', '%ELO_EMOJI%', | ||
| '%WINS%', '%WINS_EMOJI%', | ||
| '%LOSSES%', '%LOSSES_EMOJI%', | ||
| '%DRAWS%', '%DRAWS_EMOJI%', | ||
| '%PCNT%', '%PCNT_EMOJI%'], | ||
| [f'{elo}', get_elo_emoji(elo), | ||
| f'{num_wins}', get_wins_emoji(num_wins), | ||
| f'{num_losses}', get_losses_emoji(num_losses), | ||
| f'{num_draws}', get_draws_emoji(num_draws, num_losses, num_wins), | ||
| f'{pcnt}%', get_pcnt_emoji(pcnt)], | ||
| MD_TEMPLATE_TEXT | ||
| ) | ||
| ) | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # SPRT results | ||
|
|
||
| | ELO | | | ||
| | :---: | :---------: | | ||
| | %ELO% | %ELO_EMOJI% | | ||
|
|
||
| | Wins | | | ||
| | :----: | :----------: | | ||
| | %WINS% | %WINS_EMOJI% | | ||
|
|
||
| | Losses | | | ||
| | :------: | :------------: | | ||
| | %LOSSES% | %LOSSES_EMOJI% | | ||
|
|
||
| | Draws. | | | ||
| | :-----: | :-----------: | | ||
| | %DRAWS% | %DRAWS_EMOJI% | | ||
|
|
||
| | Percent | | | ||
| | :-----: | :----------: | | ||
| | %PCNT% | %PCNT_EMOJI% | |
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 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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # ====================================================================================== | ||
| # | ||
| # ░▒▓███████▓▒░░▒▓████████▓▒░▒▓███████▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░▒▓████████▓▒░ | ||
| # ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ | ||
| # ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ | ||
| # ░▒▓███████▓▒░░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ | ||
| # ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ | ||
| # ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ | ||
| # ░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░ | ||
| # | ||
| # ====================================================================================== | ||
|
|
||
| name: SPRT | ||
|
|
||
| run-name: Run SPRT test | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| types: [opened, reopened, synchronize] | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}.${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| defaults: | ||
| run: | ||
| shell: bash | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
|
|
||
| sprt: | ||
| if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }} | ||
| runs-on: ubuntu-latest | ||
| name: Run SPRT test | ||
| timeout-minutes: 60 | ||
| env: | ||
| CMAKE_BUILD_PARALLEL_LEVEL: 8 | ||
| BUILD_DIR: Builds/clang | ||
| FASTCHESS_PATH: fastchess/fastchess-ubuntu-22.04 | ||
| BASELINE_PATH: baseline/ben_bot-1.3.0-Linux-Clang | ||
| SPRT_OUTPUT_LOG: ${{ github.workspace }}/logs/sprt/output.log | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Download fastchess release | ||
| uses: robinraju/release-downloader@v1.12 | ||
|
||
| with: | ||
| repository: Disservin/fastchess | ||
| latest: true | ||
| preRelease: true | ||
| fileName: '*-ubuntu-*' | ||
| tarBall: false | ||
| zipBall: false | ||
| out-file-path: fastchess | ||
| extract: true | ||
|
|
||
| - name: Download latest BenBot release | ||
| uses: robinraju/release-downloader@v1.12 | ||
|
||
| with: | ||
| latest: true | ||
| fileName: '*-Linux-Clang' | ||
| tarBall: false | ||
| zipBall: false | ||
| out-file-path: baseline | ||
|
|
||
| - name: Add execution permissions | ||
| run: chmod --preserve-root 777 ${{ env.FASTCHESS_PATH }} ${{ env.BASELINE_PATH }} | ||
|
|
||
| - name: Configure CMake | ||
| run: cmake --preset clang -D BENBOT_DOCS=OFF -D FASTCHESS_PROGRAM=${{ env.FASTCHESS_PATH }} | ||
|
|
||
| - name: Inject baseline binary | ||
| run: cmake -D BASELINE_BINARY=${{ env.BASELINE_PATH }} -P ${{ env.BUILD_DIR }}/InjectSPRTBaseline-Release.cmake | ||
|
|
||
| - name: Build | ||
| run: cmake --build . --target ben_bot --config Release | ||
| working-directory: ${{ env.BUILD_DIR }} | ||
|
|
||
| - name: Run SPRT test | ||
| run: | | ||
| mkdir -p ${{ github.workspace }}/logs/sprt | ||
| cmake --build . --target sprt --config Release | tee ${{ env.SPRT_OUTPUT_LOG }} | ||
| working-directory: ${{ env.BUILD_DIR }} | ||
|
|
||
| - name: Upload logs | ||
| if: always() | ||
| uses: actions/upload-artifact@v4.6.2 | ||
| with: | ||
| name: sprt-logs | ||
| path: logs/sprt | ||
| if-no-files-found: error | ||
|
|
||
| - name: Report results | ||
| if: always() | ||
| run: python3 ReportSPRTResults.py ${{ env.SPRT_OUTPUT_LOG }} >> $GITHUB_STEP_SUMMARY | ||
| working-directory: .github/scripts | ||
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 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.