cki_prepare.sh
The cki_prepare.sh
script handles environment preparation for CKI shell scripts.
It is automatically sourced and executed by cki_lint.sh
and cki_test.sh
, but
can also be run standalone for manual preparation.
Usage
Standalone execution
cki_prepare.sh <extras>
Automatic execution
The script is automatically sourced and executed by cki_lint.sh
and cki_test.sh
:
cki_lint.sh [args...]
cki_test.sh [args...]
Environment Variables
Core Control Variables
CKI_SKIP_PREPARE
Type: Boolean (true/false)
Default: false
Description: Skip the entire preparation phase if set to true
.
CKI_SKIP_PREPARE=true cki_lint.sh # Will skip all preparation steps
cki_lib_pip_url
Type: Git URL
Default: Unset
Description: Override the cki-lib package with a custom version from a Git repository.
# Use a specific branch/commit
export cki_lib_pip_url="git+https://gitlab.com/cki-project/cki-lib.git@my-feature-branch"
cki_lint.sh
# Use a different repository
export cki_lib_pip_url="git+https://github.com/user/cki-lib-fork.git@main"
cki_test.sh
Automatic Version Management in CI/MR Jobs
When running in GitLab CI/CD merge request jobs, the script automatically checks
if the installed cki-lib version matches the latest production commit.
If not, it sets cki_lib_pip_url
to update to the latest version.
This occurs when:
CI_MERGE_REQUEST_PROJECT_ID
environment variable is setcki_lib_pip_url
is not already set- Project uses cki-lib (setup.cfg contains reference to the cki-lib git URL)
Package Override Variables
Any environment variable ending in _pip_url
that contains a Git URL will be treated
as a package override. The function will:
- Extract the package name from the URL
- Uninstall the existing package
- Install the override version
Pattern: {package_name}_pip_url
# Override multiple packages
export cki_tools_pip_url="git+https://gitlab.com/cki-project/cki-tools.git@dev"
export my_package_pip_url="git+https://github.com/user/my-package.git@feature"
./cki_lint.sh
Workflow
The cki_prepare.sh
script follows this workflow:
- Skip Check: Return early if
CKI_SKIP_PREPARE=true
- Pip Setup: Configure pip installation with appropriate flags
- Version Check: In CI/MR jobs, if
cki_lib_pip_url
is not already set and the installed version doesn’t match theproduction
tag, pointcki_lib_pip_url
to it - Override Handling: If
cki_lib_pip_url
is set andSKIP_CKI_LIB_OVERRIDE
is not set:- Uninstall current cki-lib
- Install override version with specified extras
- Additional Overrides: Process any other
*_pip_url
variables
Integration
The script is designed to be both:
- Executable: Can be run standalone for manual preparation
- Sourceable: Can be sourced by other scripts without executing main logic
If executed directly, it will automatically run the preparation logic
from the cki_prepare_main
function, otherwise, you can source it
and execute each part of the preparation logic manually.