Create a presubmit CI (#4934)

This commit is contained in:
Guillaume Chatelet
2025-12-15 15:26:50 +01:00
committed by Corentin Le Molgat
parent 39b915c763
commit 7f22b7208c
33 changed files with 176 additions and 74 deletions

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -6,7 +6,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

View File

@@ -5,7 +5,6 @@ on:
branches:
- main
- v99bugfix
pull_request:
workflow_dispatch:
concurrency:

127
.github/workflows/presubmit.yml vendored Normal file
View File

@@ -0,0 +1,127 @@
# ref: https://github.com/actions/runner-images
name: Presubmit
on:
pull_request:
branches:
- main
concurrency:
group: ortools-presubmit
cancel-in-progress: true
env:
PYTHON_VERSION: '3.12'
JAVA_DISTRIBUTION: 'temurin'
JAVA_VERSION: '17'
jobs:
###############################################################################
clang-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: jidicula/clang-format-action@v4.16.0
with:
exclude-regex: '\.tab\.hh$'
###############################################################################
Bazel:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-15-intel, macos-latest, windows-2022]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-java@v5
with:
distribution: ${{env.JAVA_DISTRIBUTION}}
java-version: ${{env.JAVA_VERSION}}
- uses: actions/setup-python@v6
with:
python-version: ${{env.PYTHON_VERSION}}
- uses: bazel-contrib/setup-bazel@0.15.0
- name: Build
run: bazel test --config=ci //ortools/...
shell: bash
###############################################################################
CMake:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-15-intel, macos-latest, windows-2022]
build: [cpp, java, dotnet, python]
include:
# Map build to CMake
- build: cpp
cmake: ''
- build: java
cmake: '-DBUILD_CXX_SAMPLES=OFF -DBUILD_CXX_EXAMPLES=OFF -DBUILD_JAVA=ON -DSKIP_GPG=ON'
- build: dotnet
cmake: '-DBUILD_CXX_SAMPLES=OFF -DBUILD_CXX_EXAMPLES=OFF -DBUILD_DOTNET=ON'
- build: python
cmake: '-DBUILD_CXX_SAMPLES=OFF -DBUILD_CXX_EXAMPLES=OFF -DBUILD_PYTHON=ON'
# Map os to platform / generator
- os: ubuntu-latest
platform: linux
generator: Ninja
- os: macos-15-intel
platform: macos
generator: Xcode
- os: macos-latest
platform: macos
generator: Xcode
- os: windows-2022
platform: windows
generator: 'Visual Studio 17 2022'
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-java@v5
if: ${{ matrix.build == 'java' }}
with:
distribution: ${{env.JAVA_DISTRIBUTION}}
java-version: ${{env.JAVA_VERSION}}
- uses: actions/setup-python@v6
with:
python-version: ${{env.PYTHON_VERSION}}
- name: Setup linux
if: ${{ matrix.platform == 'linux' }}
run: sudo apt install -y ninja-build ccache swig
- name: Setup macos
if: ${{ matrix.platform == 'macos' }}
run: brew install ccache swig
- name: Setup Linux Python Env
if: ${{ matrix.build == 'python' && matrix.platform == 'linux' }}
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Setup MacOs Python Env
if: ${{ matrix.build == 'python' && matrix.platform == 'macos' }}
run: |
echo "$HOME/Library/Python/${{env.PYTHON_VERSION}}/bin" >> $GITHUB_PATH
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Setup Windows Python Env
if: ${{ matrix.build == 'python' && matrix.platform == 'windows' }}
run: |
python3 -m pip install --user mypy-protobuf absl-py setuptools wheel numpy pandas
echo "$((Get-Item ~).FullName)/AppData/Roaming/Python/Python312/Scripts" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Config
run: >
cmake
-S.
-Bbuild
-G "${{matrix.generator}}"
-DBUILD_DEPS=ON
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_FLAGS_RELEASE="-O1 -DNDEBUG"
-DCMAKE_CXX_FLAGS_RELEASE="-O1 -DNDEBUG"
-DCMAKE_INSTALL_PREFIX=install
-DUSE_COINOR=OFF
-DUSE_HIGHS=OFF
-DUSE_SCIP=OFF
${{matrix.cmake}}
- name: Build
run: cmake --build build --config Release -j --target ${{ matrix.generator == 'Ninja' && 'all' || 'ALL_BUILD'}}
- name: Test
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: cmake --build build --config Release -j --target ${{ matrix.generator == 'Ninja' && 'test' || 'RUN_TESTS'}}

View File

@@ -8,32 +8,33 @@ using namespace operations_research;
using namespace operations_research::sat;
int main() {
std::vector<int> w = {3, 4, 5, 5};
std::vector<int> c = {9, 9};
std::vector<int> w = {3, 4, 5, 5};
std::vector<int> c = {9, 9};
sat::CpModelBuilder builder;
std::vector<std::vector<BoolVar>> assignment(w.size());
for (size_t i = 0; i < w.size(); i++) {
assignment[i].reserve(c.size());
for (size_t j = 0; j < c.size(); j++) {
assignment[i].emplace_back(builder.NewBoolVar());
}
builder.AddExactlyOne(assignment[i]);
}
sat::CpModelBuilder builder;
std::vector<std::vector<BoolVar>> assignment(w.size());
for (size_t i = 0; i < w.size(); i++) {
assignment[i].reserve(c.size());
for (size_t j = 0; j < c.size(); j++) {
LinearExpr expr;
for (size_t i = 0; i < w.size(); i++) {
expr += LinearExpr::Term(assignment[i][j], w[i]);
}
builder.AddLinearConstraint(expr, Domain(0, c[j]));
assignment[i].emplace_back(builder.NewBoolVar());
}
sat::Model model;
sat::SatParameters parameters;
parameters.set_num_search_workers(4);
parameters.set_max_time_in_seconds(10.0);
model.Add(sat::NewSatParameters(parameters));
auto response = sat::SolveCpModel(builder.Build(), &model);
if (response.status() == sat::CpSolverStatus::OPTIMAL || response.status() == sat::CpSolverStatus::FEASIBLE) {
std::cout << "all ok";
builder.AddExactlyOne(assignment[i]);
}
for (size_t j = 0; j < c.size(); j++) {
LinearExpr expr;
for (size_t i = 0; i < w.size(); i++) {
expr += LinearExpr::Term(assignment[i][j], w[i]);
}
builder.AddLinearConstraint(expr, Domain(0, c[j]));
}
sat::Model model;
sat::SatParameters parameters;
parameters.set_num_search_workers(4);
parameters.set_max_time_in_seconds(10.0);
model.Add(sat::NewSatParameters(parameters));
auto response = sat::SolveCpModel(builder.Build(), &model);
if (response.status() == sat::CpSolverStatus::OPTIMAL ||
response.status() == sat::CpSolverStatus::FEASIBLE) {
std::cout << "all ok";
}
}

View File

@@ -25,7 +25,8 @@ using namespace operations_research;
/**
* This method shows two ways to initialize a Xpress solver instance.
* Two environment variables are used to specify the Xpress installation paths:
* * XPRESSDIR : Path to the Xpress root directory (containing bin and lib folders)
* * XPRESSDIR : Path to the Xpress root directory containing bin and lib
* folders
* * XPRESS : Path to the directory containing Xpress license
*/
void useXpressSolver(bool solveAsMip, bool useFactory) {
@@ -36,9 +37,9 @@ void useXpressSolver(bool solveAsMip, bool useFactory) {
std::string xpressName = (solveAsMip ? "XPRESS" : "XPRESS_LP");
solver.reset(MPSolver::CreateSolver(xpressName));
} else {
MPSolver::OptimizationProblemType problemType = (solveAsMip ?
MPSolver::XPRESS_MIXED_INTEGER_PROGRAMMING
: MPSolver::XPRESS_LINEAR_PROGRAMMING);
MPSolver::OptimizationProblemType problemType =
(solveAsMip ? MPSolver::XPRESS_MIXED_INTEGER_PROGRAMMING
: MPSolver::XPRESS_LINEAR_PROGRAMMING);
/* MPSolver::SupportsProblemType(problem_type) will test if Xpress is
correctly loaded and has a valid license. This check is important to keep
the program running if Xpress is not correctly installed. With the
@@ -46,12 +47,12 @@ void useXpressSolver(bool solveAsMip, bool useFactory) {
with the license, the program will abort (SIGABRT)
*/
if (MPSolver::SupportsProblemType(problemType)) {
solver.reset(new MPSolver("IntegerProgrammingExample", problemType));
solver.reset(new MPSolver("IntegerProgrammingExample", problemType));
}
}
if (solver == nullptr) {
LOG(WARNING) << "Xpress solver is not available";
return;
LOG(WARNING) << "Xpress solver is not available";
return;
}
// Use the solver
/*
@@ -78,7 +79,6 @@ void useXpressSolver(bool solveAsMip, bool useFactory) {
c1->SetCoefficient(x1, 30.0);
c1->SetCoefficient(x2, 3.5);
const MPSolver::ResultStatus result_status = solver->Solve();
// Check that the problem has an optimal solution.
@@ -94,9 +94,9 @@ int main(int argc, char** argv) {
InitGoogle(argv[0], &argc, &argv, true);
std::cout << "start\n";
LOG(WARNING) << "start";
for (bool solveAsMip: {true, false}) {
for (bool useFactory: {true, false}) {
useXpressSolver(solveAsMip, useFactory);
for (bool solveAsMip : {true, false}) {
for (bool useFactory : {true, false}) {
useXpressSolver(solveAsMip, useFactory);
}
}
return EXIT_SUCCESS;

View File

@@ -12,8 +12,8 @@
// limitations under the License.
#include "absl/flags/parse.h"
#include "ortools/base/logging.h"
#include "ortools/base/hash.h"
#include "ortools/base/logging.h"
#include "ortools/base/map_util.h"
#include "ortools/base/stl_util.h"
#include "ortools/constraint_solver/constraint_solver.h"

View File

@@ -26,9 +26,9 @@
#include "base/callback.h"
#include "base/commandlineflags.h"
#include "base/types.h"
#include "base/join.h"
#include "base/random.h"
#include "base/types.h"
#include "base/unique_ptr.h"
#include "constraint_solver/routing.h"

View File

@@ -224,16 +224,17 @@ INSTANTIATE_TEST_SUITE_P(HighsStatusTest, StatusTest,
INSTANTIATE_TEST_SUITE_P(
HighsMessageCallbackTest, MessageCallbackTest,
Values(MessageCallbackTestParams(SolverType::kHighs,
/*support_message_callback=*/true,
/*support_interrupter=*/false,
/*integer_variables=*/false,
/*ending_substring=*/"HiGHS run time"),
MessageCallbackTestParams(SolverType::kHighs,
/*support_message_callback=*/true,
/*support_interrupter=*/false,
/*integer_variables=*/true,
/*ending_substring=*/"LP iterations 0")));
Values(
MessageCallbackTestParams(SolverType::kHighs,
/*support_message_callback=*/true,
/*support_interrupter=*/false,
/*integer_variables=*/false,
/*ending_substring=*/"HiGHS run time"),
MessageCallbackTestParams(SolverType::kHighs,
/*support_message_callback=*/true,
/*support_interrupter=*/false,
/*integer_variables=*/true,
/*ending_substring=*/"LP iterations 0")));
// HiGHS does not support callbacks other than message callback.
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CallbackTest);