Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .ci/micromamba/README.md
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 14 additions & 0 deletions .ci/micromamba/dev.yaml
Original file line number Diff line number Diff line change
@@ -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
105 changes: 105 additions & 0 deletions .ci/micromamba/init.sh
Original file line number Diff line number Diff line change
@@ -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"
20 changes: 20 additions & 0 deletions .ci/micromamba/uninstall.sh
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions .github/workflows/micromamba.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down