diff --git a/.ci/micromamba/README.md b/.ci/micromamba/README.md new file mode 100644 index 00000000..dd765f16 --- /dev/null +++ b/.ci/micromamba/README.md @@ -0,0 +1,72 @@ +Micromamba +========== + +Micromamba is a fast, lightweight package manager compatible with conda packages. +Read more: https://mamba.readthedocs.io/en/latest/user_guide/micromamba.html +You can use micromamba to quickly set up a development environment with all required tools. + + +Files +----- + +File | Description +--------------------------- | ----------- +.ci/micromamba/dev.yaml | Conda environment specification with all dependencies +.ci/micromamba/init.sh | Source this script to install micromamba and create environment +.ci/micromamba/uninstall.sh | Script to remove micromamba installation + + +How to use +---------- + +### Install & init + +To install micromamba and create the development environment: +```bash +source .ci/micromamba/init.sh +``` + +This script automatically: +- Downloads and installs micromamba to `.ci/micromamba/bin/` +- Creates a conda environment from `dev.yaml` +- Activates the environment + +> [!IMPORTANT] +> You must source the `init.sh` script (not just execute it) to properly activate +> the micromamba environment in your current shell session. + +For verbose output, use the `-v` or `-vv` flags: +```bash +source .ci/micromamba/init.sh -v +``` + +### After installation + +Once the environment is activated, all tools (Python, Bazel, CodeChecker, clang, etc.) +are available in your PATH. + +To deactivate the environment: +```bash +micromamba deactivate +``` + +To reactivate later without reinstalling: +```bash +source .ci/micromamba/init.sh +``` + +### Custom environments + +You can create additional environment files (e.g., `prod.yaml`) and activate them: +```bash +source .ci/micromamba/init.sh prod +``` + +### Uninstall + +To completely remove micromamba and all environments: +```bash +bash .ci/micromamba/uninstall.sh +``` + +Then exit your shell session to complete the cleanup. diff --git a/.ci/micromamba/dev.yaml b/.ci/micromamba/dev.yaml new file mode 100644 index 00000000..49133464 --- /dev/null +++ b/.ci/micromamba/dev.yaml @@ -0,0 +1,14 @@ +name: dev +channels: + - conda-forge +dependencies: + - python=3.11 + - pytest + - pylint + - pycodestyle + - buildifier + - clang + - clang-tools + - bazel=6 + - pip: + - codechecker==6.25 diff --git a/.ci/micromamba/init.sh b/.ci/micromamba/init.sh new file mode 100644 index 00000000..50c6d950 --- /dev/null +++ b/.ci/micromamba/init.sh @@ -0,0 +1,105 @@ +# Make sure we source the script +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + echo "ERROR: This script must be 'sourced':" + echo " source ${0}" + exit 1 +fi + +# Parse arguments +unset VERBOSE +MAMBA_VERBOSITY="--quiet" +args=() +for arg in "$@"; do + if [[ "$arg" == "-v" ]]; then + VERBOSE=1 + elif [[ "$arg" == "-vv" ]]; then + VERBOSE=2 + MAMBA_VERBOSITY="" + else + args+=("${arg}") + fi +done +set -- "${args[@]}" +unset args + +# Logging function +function log() { + [[ -n "$VERBOSE" ]] && echo "[micromamba] $@" +} + +# Logging function +function info() { + echo "[micromamba] $@" +} + +# Get the environment name +log "Arguments: \"$@\"" +ENV_NAME="${1:-dev}" +log "Environment: $ENV_NAME" + +# Get the location of this script +THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +log "Location: $THIS_DIR" + +# Check if we have environment file +if [ ! -f $THIS_DIR/$ENV_NAME.yaml ]; then + info "ERROR: No environment file found: $THIS_DIR/$ENV_NAME.yaml" + return 1 +fi + +# Install micromamba if not installed +# See https://mamba.readthedocs.io +if [ ! -f $THIS_DIR/bin/micromamba ]; then + info "Installing to $THIS_DIR/bin ..." + pushd $THIS_DIR > /dev/null + curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba + popd > /dev/null +else + info "Using: $(ls $THIS_DIR/bin/micromamba)" +fi + +# Initialize shell with micromamba +export MAMBA_EXE="$THIS_DIR/bin/micromamba"; +export MAMBA_ROOT_PREFIX="$THIS_DIR/micromamba"; +eval "$($MAMBA_EXE shell hook --shell bash --root-prefix $MAMBA_ROOT_PREFIX)" +log "Micromamba:" +log "MAMBA_EXE=$MAMBA_EXE" +log "MAMBA_ROOT_PREFIX=$MAMBA_ROOT_PREFIX" +if [[ "$VERBOSE" -ge 2 ]]; then + micromamba info +fi + +# Create environment +info "Creating environment [$ENV_NAME]..." +micromamba deactivate +micromamba create --file $THIS_DIR/$ENV_NAME.yaml --name $ENV_NAME --yes $MAMBA_VERBOSITY +# micromamba config set env_prompt "[{name}] " +micromamba activate $ENV_NAME + +# # Create environment +# info "Creating environment [$ENV_NAME]..." +# micromamba create --file $THIS_DIR/$ENV_NAME.yaml --prefix $THIS_DIR/$ENV_NAME --yes $MAMBA_VERBOSITY +# micromamba config set env_prompt "[{name}] " +# micromamba activate $THIS_DIR/$ENV_NAME + +# Print out tools information +if [[ -n "$VERBOSE" ]]; then + log "Tools:" + which python3 + which bazel + which CodeChecker + which pytest + which pylint + which pycodestyle + which buildifier + which clang + which clang-tidy + which diagtool + which clang-extdef-mapping +fi + +# Unset variables +unset ENV_NAME +unset THIS_DIR +unset MAMBA_VERBOSITY +info "To exit session run: micromamba deactivate" diff --git a/.ci/micromamba/uninstall.sh b/.ci/micromamba/uninstall.sh new file mode 100644 index 00000000..5a64fb1b --- /dev/null +++ b/.ci/micromamba/uninstall.sh @@ -0,0 +1,20 @@ +THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +MICROMAMBA="micromamba" +if [[ "$(basename $THIS_DIR)" == "$MICROMAMBA" ]]; then + PROCESSES="bazel java python3 CodeChecker" + echo "Killing: $PROCESSES" + timeout 10s killall --quiet --wait $PROCESSES + killall --quiet -SIGKILL $PROCESSES + + echo "Removing micromamba from: $THIS_DIR" + rm -rf $THIS_DIR/bin + chmod -R +w $THIS_DIR/micromamba + rm -rf $THIS_DIR/micromamba + + echo "Please exit current shell session" +else + echo "Error: wrong location $THIS_DIR" + echo " $MICROMAMBA is not there" + exit 1 +fi diff --git a/.github/workflows/micromamba.yaml b/.github/workflows/micromamba.yaml new file mode 100644 index 00000000..23d3e7da --- /dev/null +++ b/.github/workflows/micromamba.yaml @@ -0,0 +1,52 @@ +# Copyright 2023 Ericsson AB +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: codechecker-bazel-micromamba-tests + +# Trigger the workflow manually +on: + workflow_dispatch: + inputs: + arguments: + description: "Arguments: test to run" + default: "pytest test/unit -v" + required: true + type: string + +permissions: read-all + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + micromamba-test: + name: "Micromamba tests (Ubuntu)" + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: System Information + run: | + lsb_release -a + uname -a + + - name: Install micromamba and run tests + run: | + . .ci/micromamba/init.sh -v + ${{ inputs.arguments }} diff --git a/.gitignore b/.gitignore index ecc1cf1f..0f6154bf 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,10 @@ __pycache__ # Ignore Python virtual environment venv +# Ignore MicroMamba artifacts +.ci/micromamba/bin/ +.ci/micromamba/micromamba/ + # Ignore FOSS project clone dirs /test/foss/*/test-proj/