Files
azerothcore-wotlk/.github/actions/linux-build/action.yml
2026-07-21 17:22:01 +02:00

225 lines
8.0 KiB
YAML

name: linux build
description: a helper action to shorten running a build on linux
inputs:
CC:
default: clang
description: C Compiler to use
type: string
required: true
CXX:
default: clang++
description: C++ compiler to use
type: string
required: true
modules:
default: false
description: Flag to install modules or not
required: true
type: boolean
tools:
default: none
description: Flag to enable tools build
required: false
type: string
pch:
default: false
description: Flag to enable or disable PCH
required: false
type: boolean
maxerrors:
default: 1
description: Max allowed error count before compilation stops
required: false
type: number
keepgoing:
default: false
description: Flag to continue build after errors
required: false
type: boolean
runs:
using: composite
steps:
- name: echo cache key
shell: bash
run: echo "Cache key -> ccache:${{ runner.os }}:${{ inputs.CC }}_${{ inputs.CXX }}:${{ inputs.modules }}:pch=${{ inputs.pch }}:${{ github.ref_name }}-${{ github.run_id }}"
# The primary key is unique per run (`-${{ github.run_id }}`) so every run
# saves a fresh cache. A static key would hit on itself on the second run
# and `actions/cache` would then skip the upload, freezing the cache after
# the first commit on a branch (and permanently on master). The restore-keys
# walk back from the most-recent cache on this branch to progressively
# broader fallbacks (branch -> pch variant -> modules variant -> compiler).
- name: Cache
uses: actions/cache@v6
with:
path: ${{ github.workspace }}/var/ccache
key: ccache:${{ runner.os }}:${{ inputs.CC }}_${{ inputs.CXX }}:${{ inputs.modules }}:pch=${{ inputs.pch }}:${{ github.ref_name }}-${{ github.run_id }}
restore-keys: |
ccache:${{ runner.os }}:${{ inputs.CC }}_${{ inputs.CXX }}:${{ inputs.modules }}:pch=${{ inputs.pch }}:${{ github.ref_name }}-
ccache:${{ runner.os }}:${{ inputs.CC }}_${{ inputs.CXX }}:${{ inputs.modules }}:pch=${{ inputs.pch }}
ccache:${{ runner.os }}:${{ inputs.CC }}_${{ inputs.CXX }}:${{ inputs.modules }}
ccache:${{ runner.os }}:${{ inputs.CC }}_${{ inputs.CXX }}
# This script moves sql files from "data/sql/updates/pending_$DB" to the
# proper folder for the db
- name: Process pending sql
shell: bash
run: bash apps/ci/ci-pending-sql.sh
- name: Install build dependencies
shell: bash
run: |
sudo apt update
sudo apt remove needrestart #refer: https://github.com/actions/runner-images/issues/9937
sudo apt-get -y install ccache clang cmake curl \
make unzip build-essential cmake-data \
libboost-all-dev libbz2-dev libmysql++-dev \
libreadline6-dev libssl-dev libtool openssl zlib1g-dev
if [[ "$(lsb_release -sr)" == "26.04" ]]; then
sudo apt-get -y install libgoogle-perftools-dev default-libmysqlclient-dev
else
sudo apt-get -y install google-perftools libmysqlclient-dev libncurses5-dev
fi
- name: setup ccache
shell: bash
env:
CCACHE_DIR: $GITHUB_WORKSPACE/var/ccache
# CCACHE_COMPRESSLEVEL=3: level 9 burns CPU for marginal size gains on a
# cache that never approaches max_size.
run: |
mkdir -p "$CCACHE_DIR"
cat <<EOF >> "$GITHUB_ENV"
CCACHE_BASEDIR=${GITHUB_WORKSPACE}
CCACHE_DIR=${{ env.CCACHE_DIR }}
CCACHE_HASHDIR=1
CCACHE_MAXSIZE=5G
CCACHE_SLOPPINESS=pch_defines,time_macros,include_file_mtime
CCACHE_COMPRESS=1
CCACHE_COMPRESSLEVEL=3
CCACHE_COMPILERCHECK=content
CCACHE_LOGFILE=${{ env.CCACHE_DIR }}/cache.debug
CC=${{ inputs.CC }}
CXX=${{ inputs.CXX }}
EOF
- name: ccache config snapshot
shell: bash
run: |
echo "==== Effective ccache configuration ===="
ccache -p | egrep 'base_dir|hash_dir|compiler_check|sloppiness|max_size' || true
echo
echo "==== Compiler info ===="
which ${{ inputs.CC }} && ${{ inputs.CC }} --version || true
which ${{ inputs.CXX }} && ${{ inputs.CXX }} --version || true
echo
echo "==== Previous cache stats ===="
ccache -s || true
echo
echo "==== Top cache results ===="
grep -o 'result: .*' "$CCACHE_DIR/cache.debug" 2>/dev/null | sort | uniq -c | sort -nr | head || true
- name: reset ccache stats
shell: bash
run: ccache -z || true
- name: Configure
shell: bash
run: |
set -x
mkdir build
cd build
cmake "$GITHUB_WORKSPACE" \
-DCMAKE_C_COMPILER="${{ inputs.CC }}" \
-DCMAKE_CXX_COMPILER="${{ inputs.CXX }}" \
-DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/env/dist" \
-DAPPS_BUILD="all" \
-DTOOLS_BUILD=${{ inputs.tools }} \
-DSCRIPTS="static" \
-DMODULES="static" \
-DWITH_WARNINGS="ON" \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
-DCMAKE_C_FLAGS="-Werror ${{ startsWith(inputs.CC, 'clang') && '-ferror-limit=' || '-fmax-errors=' }}${{inputs.maxerrors}} -fdebug-prefix-map=${GITHUB_WORKSPACE}=." \
-DCMAKE_CXX_FLAGS="-Werror ${{ startsWith(inputs.CXX, 'clang') && '-ferror-limit=' || '-fmax-errors=' }}${{inputs.maxerrors}} -fdebug-prefix-map=${GITHUB_WORKSPACE}=." \
-DBUILD_TESTING="ON" \
-DUSE_SCRIPTPCH=${{ inputs.pch == 'true' && 'ON' || '' }} \
-DUSE_COREPCH=${{ inputs.pch == 'true' && 'ON' || '' }} \
${{ inputs.pch == 'true' && '' || '-DNOPCH=true' }}
- name: build
shell: bash
working-directory: "${{ github.workspace }}/build"
run: |
# '--' passes '--keep-going' to the underlying build system (make)
cmake --build . --config "Release" -j "$(($(nproc) + 2))" ${{ inputs.keepgoing == 'true' && '-- --keep-going' || '' }}
- name: install
shell: bash
working-directory: "${{ github.workspace }}/build"
run: cmake --install . --config "Release"
- name: Setup config
shell: bash
run: |
ls -1 env/dist/etc/*.conf.dist | while read -r dist; do
# chop the ".dist" off the end
config_name="$(<<< $dist rev | cut -f1 -d\. --complement | rev)"
cp -v "$dist" "$config_name"
done
cat <<EOF >> $GITHUB_ENV
AC_LOGIN_DATABASE_INFO=localhost;3306;root;root;acore_auth
AC_CHARACTER_DATABASE_INFO=localhost;3306;root;root;acore_characters
AC_WORLD_DATABASE_INFO=localhost;3306;root;root;acore_world
AC_DATA_DIR=env/dist/data
AC_LOGS_DIR=env/dist/logs
EOF
- name: get dbc files
shell: bash
run: |
git clone --depth 1 --branch master --single-branch https://github.com/ac-data/ac-data.git "$AC_DATA_DIR"
- name: Start MySQL container
shell: bash
run: sudo systemctl start mysql.service
- name: Dry run authserver
shell: bash
run: timeout 5m env/dist/bin/authserver --dry-run
- name: Dry run worldserver
shell: bash
run: timeout 5m env/dist/bin/worldserver --dry-run
- name: Check startup errors
shell: bash
run: |
error_log="$AC_LOGS_DIR/Errors.log"
# -s checks if the file's size is greater than 0 bytes
# ! -s checks if the file's size is less than/equal to 0 bytes
# if the error log is empty, exit without error
[[ ! -s "$error_log" ]] && exit 0
printf "The Errors.log file contains startup errors:\n\n"
cat "$error_log"
printf "\nPlease solve the startup errors listed above!\n"
exit 1
- name: Run unit tests
shell: bash
run: |
if [[ -f build/src/test/unit_tests ]]; then
build/src/test/unit_tests
else
exit 0
fi
- name: ccache stats
shell: bash
run: ccache -s || true