diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 00000000..17dfffe2 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,40 @@ +name: Build and Test + +on: + push: + branches: [ master, main ] + pull_request: + branches: [ master, main ] + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install vcpkg + run: | + git clone https://github.com/Microsoft/vcpkg.git /opt/vcpkg + cd /opt/vcpkg + ./bootstrap-vcpkg.sh + echo "VCPKG_ROOT=/opt/vcpkg" >> $GITHUB_ENV + + - name: Cache vcpkg packages + uses: actions/cache@v3 + with: + path: /opt/vcpkg/installed + key: ${{ runner.os }}-vcpkg-${{ hashFiles('**/vcpkg.json') }} + restore-keys: | + ${{ runner.os }}-vcpkg- + + - name: Build and run tests + run: | + python dev_scripts/build_and_run_tests.py \ No newline at end of file diff --git a/dev_scripts/build_and_run_tests.py b/dev_scripts/build_and_run_tests.py new file mode 100644 index 00000000..00b65bcc --- /dev/null +++ b/dev_scripts/build_and_run_tests.py @@ -0,0 +1,100 @@ +"""Run all tests and re-record the golden data.""" + +import argparse +import os +import pathlib +import shutil +import subprocess +import sys +import uuid + + +def main() -> int: + """Execute the main routine.""" + parser = argparse.ArgumentParser(description=__doc__) + _ = parser.parse_args() + + repo_root = pathlib.Path(os.path.realpath(__file__)).parent.parent + + print("Building and running all tests...") + env = os.environ.copy() + env["AAS_CORE_AAS_3_1_TEST_DATA_DIR"] = str(repo_root / "test_data") + + if "VCPKG_ROOT" not in os.environ: + print( + "The environment variable VCPKG_ROOT is not set -- we use VCPKG to install " + "the dependencies in the development scripts. See the article " + "Getting Started in documentation for more details how to install VCPKG " + "or visit https://vcpkg.io.", + file=sys.stderr, + ) + return 1 + + vcpkg_root = pathlib.Path(env["VCPKG_ROOT"]) + if not vcpkg_root.exists(): + print( + f"The VCPKG directory pointed to by the environment variable VCPKG_ROOT " + f"does not exist: {vcpkg_root}", + file=sys.stderr, + ) + return 1 + + vcpkg_cmake = vcpkg_root / "scripts/buildsystems/vcpkg.cmake" + if not vcpkg_cmake.exists(): + print( + f"The vcpkg.cmake file does not exist: {vcpkg_cmake}. " + f"Is your VCPKG properly set up?", + file=sys.stderr, + ) + return 1 + + # NOTE (mristin): + # We specify build ID in a separate statement in case we want to debug + # the re-recording of tests and want to re-build in the same directory. + build_id = str(uuid.uuid4()) + + build_dir = repo_root / f"build-for-update-{build_id}" + + # NOTE (mristin): + # When we debug this script, we usually override ``build_id`` so that we can + # repeatedly run it. Hence, we allow the build directory to exist here. + build_dir.mkdir(exist_ok=True) + + cmd = [ + "cmake", + "-DBUILD_TESTS=ON", + "-DCMAKE_BUILD_TYPE=Debug", + f"-DCMAKE_TOOLCHAIN_FILE={vcpkg_cmake}", + "-S.", + f"-B{build_dir}", + ] + cmd_joined = " ".join(cmd) + print(f"Executing: {cmd_joined}") + subprocess.check_call( + cmd, + env=env, + cwd=repo_root, + ) + + cmd = ["cmake", "--build", str(build_dir), "-j", "8"] + cmd_joined = " ".join(cmd) + print(f"Executing: {cmd_joined}") + subprocess.check_call(cmd, env=env, cwd=repo_root) + + cmd = ["ctest", "-C", "DEBUG"] + cmd_joined = " ".join(cmd) + print(f"Executing: {cmd_joined}") + subprocess.check_call(cmd, env=env, cwd=build_dir) + + # NOTE (mristin): + # We delete the build directory only if everything succeeded. Otherwise, + # we leave it lingering so that we can investigate the issue. + + if build_dir.exists(): + shutil.rmtree(build_dir) + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/portfile.cmake b/portfile.cmake index 6dc8ab20..32166eda 100644 --- a/portfile.cmake +++ b/portfile.cmake @@ -1,6 +1,6 @@ vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH - REPO aas-core-works/aas-core3.0-cpp + REPO aas-core-works/aas-core3.1-cpp REF "${VERSION}" SHA512 0 # This is a temporary value. We will modify this value in the next section. HEAD_REF main @@ -13,7 +13,7 @@ vcpkg_cmake_configure( vcpkg_cmake_install() -vcpkg_cmake_config_fixup(PACKAGE_NAME "aas-core3-0-cpp") +vcpkg_cmake_config_fixup(PACKAGE_NAME "aas-core3-1-cpp") file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") diff --git a/usage-for-vcpkg b/usage-for-vcpkg index 3350a6f4..503c7f01 100644 --- a/usage-for-vcpkg +++ b/usage-for-vcpkg @@ -1,4 +1,4 @@ -aas-core3-0-cpp provides CMake targets: +aas-core3-1-cpp provides CMake targets: -find_package(aas_core3 CONFIG REQUIRED) -target_link_libraries(main PRIVATE aas_core3::aas_core3) +find_package(aas_core3_1 CONFIG REQUIRED) +target_link_libraries(main PRIVATE aas_core3_1::aas_core3_1)