Skip to content

Commit 7381bf2

Browse files
authored
Setting up Ubuntu CI workflow (#44)
* fixed ubuntu compiler error * fixed cmake preset * added docker build push workflow for publication against github registry * added on push trigger for debug * fixed tags that were not passed to docker build push action * removed project files copy that was meant for debug * fixed typo for docker image labels * testing ci procedure with container image * harmonization * reverted trigger to workflow dispatch * updated ci to export to github summary * added docker build summary * cleaner emojis * testing with matrix run on clang ci * i want to add a docker build summary! * i want this build summary! * disable push * disable push * reverted changes, did not managed to get the build summary
1 parent b5d98d8 commit 7381bf2

File tree

7 files changed

+229
-6
lines changed

7 files changed

+229
-6
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/*
2+
docker/*
3+
docs/*

.github/workflows/ci.yaml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
workflow_dispatch:
6+
7+
permissions:
8+
contents: read
9+
packages: read
10+
11+
jobs:
12+
linux:
13+
runs-on: ubuntu-latest
14+
15+
container:
16+
image: ghcr.io/hardcode3/ghr-chess-engine-ubuntu:latest
17+
credentials:
18+
username: ${{ github.actor }}
19+
password: ${{ secrets.github_token }}
20+
21+
strategy:
22+
matrix:
23+
preset: [ clang_debug, clang_release ]
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: Configure (${{ matrix.preset }})
29+
run: |
30+
set +e
31+
cmake --preset ${{ matrix.preset }} 2>&1 | tee configure_output.txt
32+
CONFIGURE_EXIT_CODE=$?
33+
set -e
34+
35+
if [ $CONFIGURE_EXIT_CODE -eq 0 ]; then
36+
echo "<details><summary>🟢 Configure Results (click to expand)</summary>" >> $GITHUB_STEP_SUMMARY
37+
else
38+
echo "## 🔴 Configure Results" >> $GITHUB_STEP_SUMMARY
39+
fi
40+
echo '' >> $GITHUB_STEP_SUMMARY
41+
echo '```' >> $GITHUB_STEP_SUMMARY
42+
cat configure_output.txt >> $GITHUB_STEP_SUMMARY
43+
echo '```' >> $GITHUB_STEP_SUMMARY
44+
if [ $CONFIGURE_EXIT_CODE -eq 0 ]; then
45+
echo "</details>" >> $GITHUB_STEP_SUMMARY
46+
fi
47+
48+
exit $CONFIGURE_EXIT_CODE
49+
50+
- name: Build
51+
run: |
52+
set +e
53+
cmake --build --preset ${{ matrix.preset }} 2>&1 | tee build_output.txt
54+
BUILD_EXIT_CODE=$?
55+
set -e
56+
57+
if [ $BUILD_EXIT_CODE -eq 0 ]; then
58+
echo "<details><summary>🟢 Build Results (click to expand)</summary>" >> $GITHUB_STEP_SUMMARY
59+
else
60+
echo "## 🔴 Build Results" >> $GITHUB_STEP_SUMMARY
61+
fi
62+
echo '' >> $GITHUB_STEP_SUMMARY
63+
echo '```' >> $GITHUB_STEP_SUMMARY
64+
cat build_output.txt >> $GITHUB_STEP_SUMMARY
65+
echo '```' >> $GITHUB_STEP_SUMMARY
66+
if [ $BUILD_EXIT_CODE -eq 0 ]; then
67+
echo "</details>" >> $GITHUB_STEP_SUMMARY
68+
fi
69+
70+
exit $BUILD_EXIT_CODE
71+
72+
- name: Test
73+
run: |
74+
set +e
75+
ctest --preset ${{ matrix.preset }} --output-on-failure 2>&1 | tee test_output.txt
76+
TEST_EXIT_CODE=$?
77+
set -e
78+
79+
if [ $TEST_EXIT_CODE -eq 0 ]; then
80+
echo "<details><summary>🟢 Test Results (click to expand)</summary>" >> $GITHUB_STEP_SUMMARY
81+
else
82+
echo "## 🔴 Test Results" >> $GITHUB_STEP_SUMMARY
83+
fi
84+
echo '' >> $GITHUB_STEP_SUMMARY
85+
echo '```' >> $GITHUB_STEP_SUMMARY
86+
cat test_output.txt >> $GITHUB_STEP_SUMMARY
87+
echo '```' >> $GITHUB_STEP_SUMMARY
88+
if [ $TEST_EXIT_CODE -eq 0 ]; then
89+
echo "</details>" >> $GITHUB_STEP_SUMMARY
90+
fi
91+
92+
exit $TEST_EXIT_CODE
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: "Docker image tag (default: latest)"
8+
required: false
9+
default: "latest"
10+
11+
permissions:
12+
contents: read
13+
packages: write
14+
15+
jobs:
16+
docker:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Log in to GitHub Container Registry
27+
uses: docker/login-action@v3
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.github_token }}
32+
33+
- name: Docker metadata
34+
id: meta
35+
uses: docker/metadata-action@v5
36+
with:
37+
context: git
38+
images: ghcr.io/${{ github.repository_owner }}/ghr-chess-engine-ubuntu
39+
tags: |
40+
type=semver,pattern={{version}}
41+
type=semver,pattern={{major}}.{{minor}}
42+
type=semver,pattern={{major}}
43+
type=ref,event=branch
44+
type=sha
45+
latest
46+
labels: |
47+
org.opencontainers.image.source=${{ github.repository }}
48+
org.opencontainers.image.revision=${{ github.sha }}
49+
org.opencontainers.image.created=${{ github.run_started_at }}
50+
51+
- name: Build and push Docker image
52+
uses: docker/build-push-action@v5
53+
with:
54+
context: .
55+
file: docker/ubuntu/Dockerfile
56+
push: true
57+
tags: ${{ steps.meta.outputs.tags }}
58+
labels: ${{ steps.meta.outputs.labels }}
59+
annotations: ${{ steps.meta.outputs.annotations }}
60+
provenance: true

CMakePresets.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"generator": "Visual Studio 17 2022",
4242
"cacheVariables": {
4343
"CMAKE_BUILD_TYPE": "Debug",
44-
"CMAKE_CXX_COMPILER": "x64-windows"
44+
"VCPKG_TARGET_TRIPLET": "x64-windows"
4545
}
4646
},
4747
{
@@ -51,7 +51,7 @@
5151
"generator": "Visual Studio 17 2022",
5252
"cacheVariables": {
5353
"CMAKE_BUILD_TYPE": "Release",
54-
"CMAKE_CXX_COMPILER": "x64-windows"
54+
"VCPKG_TARGET_TRIPLET": "x64-windows"
5555
}
5656
}
5757
],
@@ -75,8 +75,20 @@
7575
],
7676
"testPresets": [
7777
{
78-
"name": "default",
79-
"configurePreset": "default"
78+
"name": "clang_debug",
79+
"configurePreset": "clang_debug"
80+
},
81+
{
82+
"name": "clang_release",
83+
"configurePreset": "clang_release"
84+
},
85+
{
86+
"name": "msvc_debug",
87+
"configurePreset": "msvc_debug"
88+
},
89+
{
90+
"name": "msvc_release",
91+
"configurePreset": "msvc_release"
8092
}
8193
],
8294
"packagePresets": [

docker/ubuntu/Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Commands:
2+
# [build] docker build -t ghr-chess-engine-ubuntu . -f docker/ubuntu/Dockerfile
3+
# [run] docker run -it --rm ghr-chess-engine-ubuntu
4+
# [configure cmake] cmake --preset=clang_release
5+
# [build cmake] cmake --build --preset=clang_release
6+
7+
FROM ubuntu:24.04
8+
9+
ENV DEBIAN_FRONTEND=noninteractive
10+
ENV VCPKG_ROOT=/opt/vcpkg
11+
ENV VCPKG_FEATURE_FLAGS=manifest,binarycaching
12+
ENV VCPKG_BINARY_SOURCES="clear;x-gha,readwrite"
13+
ENV PATH="${VCPKG_ROOT}:${PATH}"
14+
15+
RUN apt-get update && apt-get install -y \
16+
build-essential \
17+
clang \
18+
lldb \
19+
lld \
20+
gcc \
21+
g++ \
22+
git \
23+
curl \
24+
zip \
25+
unzip \
26+
pkg-config \
27+
ninja-build \
28+
cmake \
29+
ca-certificates \
30+
&& rm -rf /var/lib/apt/lists/*
31+
32+
RUN clang++ --version && g++ --version
33+
34+
RUN git clone https://github.com/microsoft/vcpkg.git ${VCPKG_ROOT}
35+
RUN ${VCPKG_ROOT}/bootstrap-vcpkg.sh
36+
37+
WORKDIR /workspace

include/bitbishop/bitboard.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class Bitboard {
280280
* @brief Dereferences the iterator to return the current square.
281281
* @return A `Square` corresponding to the current least significant set bit.
282282
*/
283-
constexpr Square operator*() const noexcept { return Square(std::countr_zero(bits)); }
283+
constexpr Square operator*() const noexcept { return Square(std::countr_zero(bits), std::in_place); }
284284

285285
/**
286286
* @brief Advances the iterator to the next set bit.

include/bitbishop/square.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Square {
4141

4242
public:
4343
/**
44-
* @brief Construct a Square from a raw integer value (flattened index).
44+
* @brief Construct a Square from a raw integer value (flattened index) with runtime validation.
4545
* @param v Integer in range [0, 63].
4646
* @throw std::invalid_argument if v is out of range.
4747
*/
@@ -52,6 +52,25 @@ class Square {
5252
}
5353
}
5454

55+
/**
56+
* @brief Construct a Square from a raw integer value (flattened index).
57+
* @param v Integer in range [0, 63].
58+
* @param std::in_place_t
59+
*
60+
* The std::in_place_t parameter serves as a compile-time tag to disambiguate this constructor
61+
* from other constructors. It doesn't carry any data—it's an empty struct whose sole purpose is
62+
* to enable overload resolution:
63+
*
64+
* ```c++
65+
* // You'd call it like this:
66+
* Square sq(42, std::in_place); // std::in_place is a constexpr instance of std::in_place_t
67+
*
68+
* // Versus a regular constructor:
69+
* Square sq(42); // Calls a different constructor
70+
* ```
71+
*/
72+
constexpr Square(int v, std::in_place_t) noexcept : m_value(static_cast<Value>(v)) {}
73+
5574
/**
5675
* @brief Construct a Square directly from an enum value.
5776
* @param v A valid Value from the Square::Value enum.

0 commit comments

Comments
 (0)