-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 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,74 @@ | ||
#!/bin/bash | ||
|
||
############################################################################### | ||
# common.sh | ||
# Shared bash functions between many different actions. | ||
# | ||
# Assumptions | ||
# - The env variable LDMX_DOCKER_TAG has the image we should be using | ||
# - The label for the gold plots is in | ||
# .github/actions/validate/gold_label | ||
# - ldmx-sw has been checked out using actions/checkout@v2 | ||
# OR the build package was unpacked to mimic this effect | ||
# (this assumption basically means that GITHUB_WORKSPACE points to ldmx-sw) | ||
# | ||
# Usage | ||
# GitHub defines GITHUB_ACTION_PATH to be the full path to the diretory | ||
# for the action that is being run. This means, since this file is one | ||
# below that directory, we can source it like so | ||
# source ${GITHUB_ACTION_PATH}/../common.sh | ||
# https://docs.github.com/en/actions/reference/environment-variables | ||
############################################################################### | ||
|
||
# Print the gold label | ||
ldmx_gold_label() { | ||
cat ${LDMX_GOLD_LABEL_FILE} | ||
} | ||
|
||
# container running command | ||
# - Assume LDMX_DOCKER_TAG is the image we run in | ||
# - Full command needs to be provided | ||
# - Runs inside the present working directory | ||
ldmx() { | ||
docker run \ | ||
-i -v ${LDMX_BASE}:${LDMX_BASE} -e LDMX_BASE \ | ||
-e LDMX_NUM_EVENTS -e LDMX_RUN_NUMBER \ | ||
-u $(id -u $USER):$(id -g $USER) \ | ||
${LDMX_DOCKER_TAG} $(pwd) $@ | ||
return $? | ||
} | ||
|
||
# GitHub workflow command to set an output key,val pair | ||
set_output() { | ||
local _key="$1" | ||
local _val="$2" | ||
echo "${_key} = ${_val}" | ||
echo "${_key}=${_val}" >> $GITHUB_OUTPUT | ||
} | ||
|
||
# GitHub workflow command to start an group of output messages | ||
start_group() { | ||
echo "::group::$@" | ||
} | ||
|
||
# GitHub workflow command to end previously started group | ||
end_group() { | ||
echo "::endgroup::" | ||
} | ||
|
||
# GitHub workflow command to flag message as an error | ||
error() { | ||
echo "::error::$@" | ||
} | ||
|
||
warn() { | ||
echo "::warning::$@" | ||
} | ||
|
||
start_group Deduce Common Environment Variables | ||
export LDMX_GOLD_LABEL_FILE=${GITHUB_WORKSPACE}/.github/actions/validate/gold_label | ||
export LDMX_BASE=$(cd ${GITHUB_WORKSPACE}/../ && pwd) | ||
echo "LDMX_GOLD_LABEL_FILE=${LDMX_GOLD_LABEL_FILE}" | ||
echo "LDMX_BASE=${LDMX_BASE}" | ||
end_group | ||
|