forked from mantidproject/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a conda-wrapper for the pre-commit script
pre-commit recently required Python 3.7+ so can no longer run on stock CentoOS 7
- Loading branch information
1 parent
44c5bcf
commit 05a04f0
Showing
3 changed files
with
52 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash -ex | ||
|
||
# This script will set up a conda environment before running the pre-commit shell script. | ||
# | ||
# Script usage: | ||
# conda-pre-commit <path-to-workspace> <job-type> | ||
# | ||
# Example command to run a PR build on ubuntu: | ||
# conda-pre-commit pull_requests-cppcheck ${WORKSPACE} | ||
# | ||
# Expected args: | ||
# 1. WORKSPACE: path to the workspace/source code that this should run inside, Windows Caveat: Only use / for | ||
# this argument do not use \\ or \ in the path. | ||
# 2. GIT_COMMIT_SHA: SHA of the commit to compare with the base when checking diffs | ||
# 2. JOB_TYPE: An optional job type. If it contains 'pull_requests', then pre-commit only runs in he diff | ||
|
||
# Check arguments passed are 2, and aren't optional flags. | ||
if [[ $# -lt 2 ]]; then | ||
echo "Usage: conda-pre-commit <path-to-workspace> <job-name>" | ||
exit 1 | ||
fi | ||
|
||
# SCRIPT_DIR discovery from https://stackoverflow.com/a/9107028 by https://stackoverflow.com/users/1184238/andrew-norrie | ||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
SOURCE_DIR=$1 | ||
GIT_SHA=$2 | ||
JOB_TYPE=$3 | ||
|
||
EXPECTED_MAMBAFORGE_PATH=$SOURCE_DIR/mambaforge # Install into the WORKSPACE_DIR | ||
EXPECTED_CONDA_PATH=$EXPECTED_MAMBAFORGE_PATH/bin/mamba | ||
CONDA_ENV_NAME="pre-commit" | ||
CLEAN_BUILD=false | ||
|
||
# Setup Mambaforge | ||
$SCRIPT_DIR/download-and-install-mambaforge $EXPECTED_MAMBAFORGE_PATH $EXPECTED_CONDA_PATH $CLEAN_BUILD | ||
source $EXPECTED_MAMBAFORGE_PATH/etc/profile.d/conda.sh | ||
source $EXPECTED_MAMBAFORGE_PATH/etc/profile.d/mamba.sh | ||
mamba create -n $CONDA_ENV_NAME pre-commit | ||
mamba activate $CONDA_ENV_NAME | ||
|
||
# Run the script that handles the actual building | ||
$SCRIPT_DIR/pre-commit ${SOURCE_DIR} ${GIT_SHA} ${JOB_TYPE} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters