From 4992685e945ee26782a1c70f1fcd4046aaadcc8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Wed, 8 May 2024 06:42:19 +0000 Subject: [PATCH] Add devcontainer to repository Fix update_coverage.py with lcov2.1 output --- .devcontainer/Dockerfile | 57 ++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 37 ++++++++++++++++++++ .devcontainer/reinstall-cmake.sh | 59 ++++++++++++++++++++++++++++++++ .github/dependabot.yml | 12 +++++++ .gitignore | 1 + Makefile | 5 +-- update_coverage.py | 17 +++++---- 7 files changed, 180 insertions(+), 8 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/reinstall-cmake.sh create mode 100644 .github/dependabot.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..f660ce5 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,57 @@ +FROM mcr.microsoft.com/devcontainers/cpp:ubuntu22.04 + +ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="3.22.2" + +# Optionally install the cmake for vcpkg +COPY ./reinstall-cmake.sh /tmp/ + +RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \ + chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \ + fi \ + && rm -f /tmp/reinstall-cmake.sh + + +# [Optional] Uncomment this section to install additional vcpkg ports. +# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install " + +# [Optional] Uncomment this section to install additional packages. +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends wget software-properties-common libdatetime-perl libcapture-tiny-perl libdatetime-format-dateparse-perl libgd-perl + +# Add PPA for GCC 13 +RUN add-apt-repository ppa:ubuntu-toolchain-r/test +RUN apt-get update + +# Install GCC 13.1 +RUN apt-get install -y gcc-13 g++-13 + +# Install lcov 2.1 +RUN wget --quiet https://github.com/linux-test-project/lcov/releases/download/v2.1/lcov-2.1.tar.gz && \ + tar -xvf lcov-2.1.tar.gz && \ + cd lcov-2.1 && \ + make install +RUN rm lcov-2.1.tar.gz +RUN rm -fr lcov-2.1 + +# Install Miniconda +RUN mkdir -p /opt/conda +RUN wget --quiet "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh" -O /opt/conda/miniconda.sh && \ + bash /opt/conda/miniconda.sh -b -p /opt/miniconda + +# Add conda to PATH +ENV PATH=/opt/miniconda/bin:$PATH + +# add CXX and CC to the environment with gcc 13 +ENV CXX=/usr/bin/g++-13 +ENV CC=/usr/bin/gcc-13 + +# link the last gcov version +RUN rm /usr/bin/gcov +RUN ln -s /usr/bin/gcov-13 /usr/bin/gcov + +# change ownership of /opt/miniconda to vscode user +RUN chown -R vscode:vscode /opt/miniconda + +USER vscode +RUN conda init +RUN conda install -y -c conda-forge yaml pytorch \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..f3bb68b --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,37 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/cpp +{ + "name": "C++", + "build": { + "dockerfile": "Dockerfile" + }, + // "features": { + // "ghcr.io/devcontainers/features/conda:1": {} + // } + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "make release && make debug && echo 'Done!'", + // Configure tool-specific properties. + // "customizations": {}, + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + "settings": {}, + "extensions": [ + "ms-vscode.cpptools", + "ms-vscode.cpptools-extension-pack", + "ms-vscode.cpptools-themes", + "ms-vscode.cmake-tools", + "ms-azuretools.vscode-docker", + "jbenden.c-cpp-flylint", + "matepek.vscode-catch2-test-adapter", + "GitHub.copilot" + ] + } + } + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/.devcontainer/reinstall-cmake.sh b/.devcontainer/reinstall-cmake.sh new file mode 100644 index 0000000..408b81d --- /dev/null +++ b/.devcontainer/reinstall-cmake.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- +# +set -e + +CMAKE_VERSION=${1:-"none"} + +if [ "${CMAKE_VERSION}" = "none" ]; then + echo "No CMake version specified, skipping CMake reinstallation" + exit 0 +fi + +# Cleanup temporary directory and associated files when exiting the script. +cleanup() { + EXIT_CODE=$? + set +e + if [[ -n "${TMP_DIR}" ]]; then + echo "Executing cleanup of tmp files" + rm -Rf "${TMP_DIR}" + fi + exit $EXIT_CODE +} +trap cleanup EXIT + + +echo "Installing CMake..." +apt-get -y purge --auto-remove cmake +mkdir -p /opt/cmake + +architecture=$(dpkg --print-architecture) +case "${architecture}" in + arm64) + ARCH=aarch64 ;; + amd64) + ARCH=x86_64 ;; + *) + echo "Unsupported architecture ${architecture}." + exit 1 + ;; +esac + +CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh" +CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt" +TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX) + +echo "${TMP_DIR}" +cd "${TMP_DIR}" + +curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O +curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O + +sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}" +sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license + +ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake +ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..f33a02c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for more information: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +# https://containers.dev/guide/dependabot + +version: 2 +updates: + - package-ecosystem: "devcontainers" + directory: "/" + schedule: + interval: weekly diff --git a/.gitignore b/.gitignore index 658ff9b..a1c4460 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,5 @@ cmake-build*/** puml/** .vscode/settings.json sample/build +**/.DS_Store diff --git a/Makefile b/Makefile index 766c7ab..8d8db25 100644 --- a/Makefile +++ b/Makefile @@ -123,8 +123,9 @@ coverage: ## Run tests and generate coverage report (build/index.html) $(lcov) --remove coverage.info 'lib/*' --output-file coverage.info >/dev/null 2>&1; \ $(lcov) --remove coverage.info 'libtorch/*' --output-file coverage.info >/dev/null 2>&1; \ $(lcov) --remove coverage.info 'tests/*' --output-file coverage.info >/dev/null 2>&1; \ - $(lcov) --summary coverage.info; \ - $(lcov) --remove coverage.info 'bayesnet/utils/loguru.*' --ignore-errors unused --output-file coverage.info >/dev/null 2>&1 + $(lcov) --remove coverage.info 'bayesnet/utils/loguru.*' --ignore-errors unused --output-file coverage.info >/dev/null 2>&1; \ + $(lcov) --remove coverage.info '/opt/miniconda/*' --ignore-errors unused --output-file coverage.info >/dev/null 2>&1; \ + $(lcov) --summary coverage.info @$(MAKE) updatebadge @echo ">>> Done"; diff --git a/update_coverage.py b/update_coverage.py index 238a27f..584a41d 100644 --- a/update_coverage.py +++ b/update_coverage.py @@ -11,16 +11,21 @@ readme_file = "README.md" print("Updating coverage...") # Generate badge line output = subprocess.check_output( - "lcov --summary " + sys.argv[1] + "/coverage.info|cut -d' ' -f4 |head -2|" - "tail -1", + "lcov --summary " + sys.argv[1] + "/coverage.info", shell=True, ) -value = float(output.decode("utf-8").strip().replace("%", "")) -if value < 90: +value = output.decode("utf-8").strip() +percentage = 0 +for line in value.splitlines(): + if "lines" in line: + percentage = float(line.split(":")[1].split("%")[0]) + break +print(f"Coverage: {percentage}%") +if percentage < 90: print("â›”Coverage is less than 90%. I won't update the badge.") sys.exit(1) -percentage = output.decode("utf-8").strip().replace(".", ",") -coverage_line = f"[![Coverage Badge](https://img.shields.io/badge/Coverage-{percentage}25-green)](html/index.html)" +percentage_label = str(percentage).replace('.', ',') +coverage_line = f"[![Coverage Badge](https://img.shields.io/badge/Coverage-{percentage_label}%25-green)](html/index.html)" # Update README.md with open(readme_file, "r") as f: lines = f.readlines()