refactor: use tee instead to print and pipe output

This commit is contained in:
2025-09-24 08:57:18 -05:00
parent bc72fd7ef9
commit 6b40037e41

View File

@@ -50,15 +50,15 @@ runs:
mkdir -p ./_plugin_checkout_/
cd ./_plugin_checkout_/
echo "Cloning repository: ${{ inputs.BEC_PLUGIN_REPO_URL }}" >> $LOG_FILE 2>&1
echo "Using branch: ${{ inputs.BEC_PLUGIN_REPO_BRANCH }}" >> $LOG_FILE 2>&1
echo "Cloning repository: ${{ inputs.BEC_PLUGIN_REPO_URL }}" | tee -a "$LOG_FILE"
echo "Using branch: ${{ inputs.BEC_PLUGIN_REPO_BRANCH }}" | tee -a "$LOG_FILE"
# Clone the repository with fallback for branch
if git clone --depth 1 --branch "${{ inputs.BEC_PLUGIN_REPO_BRANCH }}" "${{ inputs.BEC_PLUGIN_REPO_URL }}" >> $LOG_FILE 2>&1; then
echo "Successfully cloned with branch ${{ inputs.BEC_PLUGIN_REPO_BRANCH }}" >> $LOG_FILE 2>&1
if git clone --depth 1 --branch "${{ inputs.BEC_PLUGIN_REPO_BRANCH }}" "${{ inputs.BEC_PLUGIN_REPO_URL }}" | tee -a "$LOG_FILE"; then
echo "Successfully cloned with branch ${{ inputs.BEC_PLUGIN_REPO_BRANCH }}" | tee -a "$LOG_FILE"
else
echo "Failed to clone with branch ${{ inputs.BEC_PLUGIN_REPO_BRANCH }}, trying without specific branch" >> $LOG_FILE 2>&1
git clone --depth 1 "${{ inputs.BEC_PLUGIN_REPO_URL }}" >> $LOG_FILE 2>&1
echo "Failed to clone with branch ${{ inputs.BEC_PLUGIN_REPO_BRANCH }}, trying without specific branch" | tee -a "$LOG_FILE"
git clone --depth 1 "${{ inputs.BEC_PLUGIN_REPO_URL }}" | tee -a "$LOG_FILE"
fi
cd ../
@@ -82,19 +82,19 @@ runs:
OUTPUT_DIR="$PWD/outputs" # absolute path
LOG_FILE="${OUTPUT_DIR}/checkout_bec_core.log"
echo "Cloning BEC Core repository" >> $LOG_FILE 2>&1
echo "Using branch: ${{ inputs.BEC_CORE_BRANCH }}" >> $LOG_FILE 2>&1
echo "Cloning BEC Core repository" | tee -a "$LOG_FILE"
echo "Using branch: ${{ inputs.BEC_CORE_BRANCH }}" | tee -a "$LOG_FILE"
# Create a temporary directory for the plugin repository
mkdir -p ./_bec_checkout_/
cd ./_bec_checkout_/
# Clone the repository with fallback for branch
if git clone --depth 1 --branch "${{ inputs.BEC_CORE_BRANCH }}" https://github.com/bec-project/bec.git >> $LOG_FILE 2>&1; then
echo "Successfully cloned with branch ${{ inputs.BEC_CORE_BRANCH }}" >> $LOG_FILE 2>&1
if git clone --depth 1 --branch "${{ inputs.BEC_CORE_BRANCH }}" https://github.com/bec-project/bec.git | tee -a "$LOG_FILE"; then
echo "Successfully cloned with branch ${{ inputs.BEC_CORE_BRANCH }}" | tee -a "$LOG_FILE"
else
echo "Failed to clone with branch ${{ inputs.BEC_CORE_BRANCH }}, trying without specific branch" >> $LOG_FILE 2>&1
git clone --depth 1 https://github.com/bec-project/bec.git >> $LOG_FILE 2>&1
echo "Failed to clone with branch ${{ inputs.BEC_CORE_BRANCH }}, trying without specific branch" | tee -a "$LOG_FILE"
git clone --depth 1 https://github.com/bec-project/bec.git | tee -a "$LOG_FILE"
fi
echo "Exit Code: 0" >> $LOG_FILE
@@ -118,15 +118,15 @@ runs:
mkdir -p ./_ophyd_devices_checkout_/
cd ./_ophyd_devices_checkout_/
echo "Cloning Ophyd Devices repository" >> $LOG_FILE 2>&1
echo "Using branch: ${{ inputs.OPHYD_DEVICES_BRANCH }}" >> $LOG_FILE 2>&1
echo "Cloning Ophyd Devices repository" | tee -a "$LOG_FILE"
echo "Using branch: ${{ inputs.OPHYD_DEVICES_BRANCH }}" | tee -a "$LOG_FILE"
# Clone the repository with fallback for branch
if git clone --depth 1 --branch "${{ inputs.OPHYD_DEVICES_BRANCH }}" https://github.com/bec-project/ophyd_devices.git >> $LOG_FILE 2>&1; then
echo "Successfully cloned with branch ${{ inputs.OPHYD_DEVICES_BRANCH }}" >> $LOG_FILE 2>&1
if git clone --depth 1 --branch "${{ inputs.OPHYD_DEVICES_BRANCH }}" https://github.com/bec-project/ophyd_devices.git | tee -a "$LOG_FILE"; then
echo "Successfully cloned with branch ${{ inputs.OPHYD_DEVICES_BRANCH }}" | tee -a "$LOG_FILE"
else
echo "Failed to clone with branch ${{ inputs.OPHYD_DEVICES_BRANCH }}, trying without specific branch" >> $LOG_FILE 2>&1
git clone --depth 1 https://github.com/bec-project/ophyd_devices.git >> $LOG_FILE 2>&1
echo "Failed to clone with branch ${{ inputs.OPHYD_DEVICES_BRANCH }}, trying without specific branch" | tee -a "$LOG_FILE"
git clone --depth 1 https://github.com/bec-project/ophyd_devices.git | tee -a "$LOG_FILE"
fi
echo "Exit Code: 0" >> $LOG_FILE
@@ -152,15 +152,15 @@ runs:
cd ./_bec_widgets_checkout_/
echo "Cloning BEC Widgets repository" >> $LOG_FILE 2>&1
echo "Using branch: ${{ inputs.BEC_WIDGETS_BRANCH }}" >> $LOG_FILE 2>&1
echo "Cloning BEC Widgets repository" | tee -a "$LOG_FILE"
echo "Using branch: ${{ inputs.BEC_WIDGETS_BRANCH }}" | tee -a "$LOG_FILE"
# Clone the repository with fallback for branch
if git clone --depth 1 --branch "${{ inputs.BEC_WIDGETS_BRANCH }}" https://github.com/bec-project/bec_widgets.git >> $LOG_FILE 2>&1; then
echo "Successfully cloned with branch ${{ inputs.BEC_WIDGETS_BRANCH }}" >> $LOG_FILE 2>&1
if git clone --depth 1 --branch "${{ inputs.BEC_WIDGETS_BRANCH }}" https://github.com/bec-project/bec_widgets.git | tee -a "$LOG_FILE"; then
echo "Successfully cloned with branch ${{ inputs.BEC_WIDGETS_BRANCH }}" | tee -a "$LOG_FILE"
else
echo "Failed to clone with branch ${{ inputs.BEC_WIDGETS_BRANCH }}, trying without specific branch" >> $LOG_FILE 2>&1
git clone --depth 1 https://github.com/bec-project/bec_widgets.git >> $LOG_FILE 2>&1
echo "Failed to clone with branch ${{ inputs.BEC_WIDGETS_BRANCH }}, trying without specific branch" | tee -a "$LOG_FILE"
git clone --depth 1 https://github.com/bec-project/bec_widgets.git | tee -a "$LOG_FILE"
fi
echo "Exit Code: 0" >> $LOG_FILE
@@ -180,9 +180,9 @@ runs:
OUTPUT_DIR="$PWD/outputs" # absolute path
LOG_FILE="${OUTPUT_DIR}/install_apt_packages.log"
echo "Installing additional APT packages: ${{ inputs.APT_PACKAGES }}" >> $LOG_FILE 2>&1
sudo apt-get update >> $LOG_FILE 2>&1
sudo apt-get install -y ${{ inputs.APT_PACKAGES }} >> $LOG_FILE 2>&1
echo "Installing additional APT packages: ${{ inputs.APT_PACKAGES }}" | tee -a "$LOG_FILE"
sudo apt-get update | tee -a "$LOG_FILE"
sudo apt-get install -y ${{ inputs.APT_PACKAGES }} | tee -a "$LOG_FILE"
echo "Exit Code: 0" >> $LOG_FILE
echo "Completed APT package installation"
@@ -203,22 +203,22 @@ runs:
OUTPUT_DIR="$PWD/outputs" # absolute path
LOG_FILE="${OUTPUT_DIR}/install_python_dependencies.log"
echo "Installing Python dependencies" >> $LOG_FILE 2>&1
echo "Using Python version: $(python --version)" >> $LOG_FILE 2>&1
echo "Installing Python dependencies" | tee -a "$LOG_FILE"
echo "Using Python version: $(python --version)" | tee -a "$LOG_FILE"
python -m pip install --upgrade pip >> $LOG_FILE 2>&1
python -m pip install --upgrade pip | tee -a "$LOG_FILE"
# Install Core dependencies
pip install uv >> $LOG_FILE 2>&1
uv pip install --system -e ./_bec_checkout_/bec/bec_lib/[dev] >> $LOG_FILE 2>&1
uv pip install --system -e ./_bec_checkout_/bec/bec_ipython_client >> $LOG_FILE 2>&1
uv pip install --system -e ./_bec_checkout_/bec/bec_server[dev] >> $LOG_FILE 2>&1
uv pip install --system -e ./_bec_widgets_checkout_/bec_widgets[dev,pyside6] >> $LOG_FILE 2>&1
uv pip install --system -e ./_ophyd_devices_checkout_/ophyd_devices[dev] >> $LOG_FILE 2>&1
pip install uv | tee -a "$LOG_FILE"
uv pip install --system -e ./_bec_checkout_/bec/bec_lib/[dev] | tee -a "$LOG_FILE"
uv pip install --system -e ./_bec_checkout_/bec/bec_ipython_client | tee -a "$LOG_FILE"
uv pip install --system -e ./_bec_checkout_/bec/bec_server[dev] | tee -a "$LOG_FILE"
uv pip install --system -e ./_bec_widgets_checkout_/bec_widgets[dev,pyside6] | tee -a "$LOG_FILE"
uv pip install --system -e ./_ophyd_devices_checkout_/ophyd_devices[dev] | tee -a "$LOG_FILE"
# plugin repo name was stored earlier
source $GITHUB_ENV
pip install -e "./_plugin_checkout_/${PLUGIN_REPO_NAME}[dev]" >> $LOG_FILE 2>&1
pip install -e "./_plugin_checkout_/${PLUGIN_REPO_NAME}[dev]" | tee -a "$LOG_FILE"
echo "Exit Code: 0" >> $LOG_FILE
echo "Completed Python dependencies installation"
@@ -234,16 +234,16 @@ runs:
OUTPUT_DIR="$PWD/outputs" # absolute path
LOG_FILE="${OUTPUT_DIR}/pytest_plugin.log"
echo "Running pytest for plugin repository" >> $LOG_FILE 2>&1
echo "Running pytest for plugin repository" | tee -a "$LOG_FILE"
source $GITHUB_ENV
cd "./_plugin_checkout_/${PLUGIN_REPO_NAME}"
# run pytest and capture its exit code
pytest --random-order --cov=. --cov-config=./pyproject.toml \
--cov-branch --cov-report=xml --no-cov-on-fail ./tests/ \
>> "$LOG_FILE" 2>&1 || rc=$?
rc=${rc:-0}
2>&1 | tee -a "$LOG_FILE"
rc=${PIPESTATUS[0]} # exit code of pytest in a pipe
if [ "$rc" -eq 0 ] || [ "$rc" -eq 5 ]; then
echo "Exit Code: 0" >> $LOG_FILE
else