Skip to content

Commit

Permalink
Update CI workflow and Makefile (#19)
Browse files Browse the repository at this point in the history
This adds more tests to the CI process. Furthermore, a new workflow for automatic building and publishing the binaries after a release has been added. To ensure compatibility with all OSes, minor fixes have been made on the Makefile and the codebase.

No functional change
  • Loading branch information
ruicoelhopedro authored Nov 30, 2023
1 parent 7c3e10d commit e276c44
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 19 deletions.
87 changes: 77 additions & 10 deletions .github/workflows/pawn-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Pawn tests
name: Build and test pawn

on:
push:
Expand All @@ -11,20 +11,87 @@ on:

jobs:
build:
name: Building and testing pawn
runs-on: ubuntu-latest
name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
env:
CC: ${{ matrix.config.cc }}
CXX: ${{ matrix.config.cxx }}
strategy:
fail-fast: false
matrix:
config:
- name: "Ubuntu Latest - GCC"
os: ubuntu-latest
cc: gcc
cxx: g++
shell: bash
- name: "Ubuntu Latest - Clang"
os: ubuntu-latest
cc: clang
cxx: clang++
shell: bash
- name: "Ubuntu 20.04 - GCC"
os: ubuntu-20.04
cc: gcc
cxx: g++
shell: bash
- name: "Ubuntu 20.04 - Clang"
os: ubuntu-20.04
cc: clang
cxx: clang++
shell: bash
- name: "MacOS - GCC 11"
os: macos-latest
cc: gcc-11
cxx: g++-11
shell: bash
- name: "MacOS - Clang"
os: macos-latest
cc: clang
cxx: clang++
shell: bash
- name: "Windows 2022 - GCC"
os: windows-2022
cc: gcc
cxx: g++
sys: mingw64
packages: mingw-w64-x86_64-gcc
shell: msys2 {0}
- name: "Windows 2022 - Clang"
os: windows-2022
cc: clang
cxx: clang++
sys: mingw64
packages: mingw-w64-x86_64-clang mingw-w64-x86_64-lld
shell: msys2 {0}
defaults:
run:
shell: ${{ matrix.config.shell }}
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Extract bench signature
run: "git log HEAD | grep 'Bench: ' | head -n 1 | awk '{print $2}' > bench.sig"
- name: Prepare Windows with MSYS2
if: runner.os == 'Windows'
uses: msys2/setup-msys2@v2
with:
msystem: ${{matrix.config.sys}}
install: make git diffutils ${{matrix.config.packages}}
- name: Fetch bench signature
run: "git log HEAD | grep 'Bench: ' | head -n 1 | awk '{print $2}' > bench.sig_ref"
- name: Build pawn
run: "make"
- name: Run bench
run: "build/pawn bench 2>&1 | grep 'Nodes searched:' | awk '{print $3}' > bench.out"
- name: Verify bench signature
run: "cmp bench.sig bench.out"
run: |
build/pawn bench > bench.out 2>&1
cat bench.out
- name: Extract and verify bench signature
run: |
cat bench.out | grep 'Nodes searched:' | awk '{print $3}' > bench.sig
cmp bench.sig bench.sig_ref
- name: Run tests
run: "build/pawn test | grep -q 'All tests passed'"
run: |
build/pawn test > test.out
cat test.out
grep -q 'All tests passed' test.out
77 changes: 77 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Upload binaries to release

on:
release:
types: [published]

permissions:
contents: write

jobs:
build:
name: ${{matrix.config.name}}
runs-on: ${{matrix.config.os}}
env:
CC: ${{matrix.config.cc}}
CXX: ${{matrix.config.cxx}}
strategy:
fail-fast: false
matrix:
config:
- name: ubuntu
os: ubuntu-20.04
cc: gcc
cxx: g++
shell: bash
- name: macos
os: macos-latest
cc: gcc-11
cxx: g++-11
shell: bash
- name: windows
os: windows-2022
cc: gcc
cxx: g++
sys: mingw64
packages: mingw-w64-x86_64-gcc
shell: msys2 {0}
binaries:
- x86-64
- haswell
defaults:
run:
shell: ${{matrix.config.shell}}
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Prepare Windows with MSYS2
if: runner.os == 'Windows'
uses: msys2/setup-msys2@v2
with:
msystem: ${{matrix.config.sys}}
install: make git diffutils mingw-w64-x86_64-github-cli ${{matrix.config.packages}}
- name: Build
run: make ARCH=${{matrix.binaries}} -j
- name: Verify bench signature
run: |
git log HEAD | grep 'Bench: ' | head -n 1 | awk '{print $2}' > bench.sig_ref
build/pawn bench > bench.out 2>&1
cat bench.out
cat bench.out | grep 'Nodes searched:' | awk '{print $3}' > bench.sig
cmp bench.sig bench.sig_ref
- name: Upload Release Asset
if: runner.os != 'Windows'
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
cp build/pawn pawn-${{github.event.release.tag_name}}-${{matrix.config.name}}-${{matrix.binaries}}
gh release upload ${{github.event.release.tag_name}} pawn-${{github.event.release.tag_name}}-${{matrix.config.name}}-${{matrix.binaries}}
- name: Upload Release Asset (Windows)
if: runner.os == 'Windows'
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
cp build/pawn.exe pawn-${{github.event.release.tag_name}}-${{matrix.config.name}}-${{matrix.binaries}}.exe
gh release upload ${{github.event.release.tag_name}} pawn-${{github.event.release.tag_name}}-${{matrix.config.name}}-${{matrix.binaries}}.exe
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@ SRC_DIR=src
ARCH = native

# Compiler flags
CFLAGS = -Wall -Isrc/syzygy/Fathom/src -O3 -flto -march=$(ARCH)
CXXFLAGS = -Wall -std=c++17 -Isrc/syzygy/Fathom/src -O3 -flto -march=$(ARCH)
LDFLAGS = -pthread -flto -march=$(ARCH)
COMMON = -Wall -Isrc/syzygy/Fathom/src -O3 -flto -march=$(ARCH)
CFLAGS = $(COMMON)
CXXFLAGS = $(COMMON) -std=c++17
LDFLAGS = -flto -march=$(ARCH)

# Windows-specific stuff
ifeq ($(OS), Windows_NT)
LDFLAGS += -static
BIN_NAME := $(BIN_NAME).exe
ifeq ($(CC), clang)
# Needed for -flto to work on Windows Clang
# This is also the only case where we don't use -pthread
CFLAGS += -fuse-ld=lld
CXXFLAGS += -fuse-ld=lld
LDFLAGS += -fuse-ld=lld
else
LDFLAGS += -pthread
endif
else
LDFLAGS += -pthread
endif

SRC_FILES := $(shell find $(SRC_DIR) -name *.cpp) src/syzygy/Fathom/src/tbprobe.c
Expand Down
1 change: 1 addition & 0 deletions src/NNUE.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "incbin/incbin.h"
#include "Types.hpp"
#include "NNUE.hpp"
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion src/NNUE.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "incbin/incbin.h"
#include "Types.hpp"


#define NNUE_Default_File "nnue-10427ad1e4e6.dat"


Expand Down
4 changes: 2 additions & 2 deletions src/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ namespace Tests
for (auto& test : tests)
{
Position pos(test.fen());
Histories hists;
auto result = Search::perft<false>(pos, test.depth(), hists);
auto hists = std::make_unique<Histories>();
auto result = Search::perft<false>(pos, test.depth(), *hists);
if (result == test.result())
{
std::cout << "[ OK ] " << test.fen() << " (" << result << ")" << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions src/Tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ namespace Tests
int n_failed = 0;
for (auto& test : tests)
{
Histories hists;
Position pos(test.fen());
auto result_base = Search::perft<false>(pos, test.depth() - 1, hists);
auto result_test = Search::template perft<false, USE_ORDER, TT, LEGALITY, VALIDITY>(pos, test.depth() - 1, hists);
auto hists = std::make_unique<Histories>();
auto result_base = Search::perft<false>(pos, test.depth() - 1, *hists);
auto result_test = Search::template perft<false, USE_ORDER, TT, LEGALITY, VALIDITY>(pos, test.depth() - 1, *hists);
if (result_base == result_test)
{
std::cout << "[ OK ] " << test.fen() << " (" << result_test << ")" << std::endl;
Expand Down

0 comments on commit e276c44

Please sign in to comment.