Skip to content

Commit

Permalink
Add -b for batch mode
Browse files Browse the repository at this point in the history
Since the CI has no terminal, all tests fail.
  • Loading branch information
rumpelsepp committed Dec 21, 2023
1 parent 6965a89 commit fb5c261
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
devShell.x86_64-linux = pkgs.mkShell {
buildInputs = with pkgs; [
bats
nodePackages_latest.bash-language-server
];
shellHook = ''
LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath [stdenv.cc.cc]}
Expand Down
15 changes: 9 additions & 6 deletions penrun
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ usage() {
echo " -C CMD Compression command for OUTPUT"
echo " -S SEC Sleep this time beetween jobs"
echo " -T TPL A command template for batch processing"
echo " -b Use batched mode for parallel processing. Commands are read from stdin."
echo " -c FILE Use this config file exclusively"
echo " -d DIR Use artifactsdir DIR"
echo " -e EXT File extension for OUTPUT"
Expand All @@ -295,6 +296,7 @@ dienocmd() {

main() {
local artifactsdir=""
local batch_mode=""
local forced_config=""
local jobs="1"
local run_until="0"
Expand All @@ -304,11 +306,12 @@ main() {
local template=""
local use_default_args="1"

while getopts "C:S:T:c:d:e:j:np:st:uh" arg; do
while getopts "C:S:T:bc:d:e:j:np:st:uh" arg; do
case "$arg" in
C) read -r -a PENRUN_COMPRESSION_COMMAND <<<"$OPTARG" ;;
S) sleep_time="$OPTARG" ;;
T) template="$OPTARG" ;;
b) batch_mode=1;;
c) forced_config="$OPTARG" ;;
d) artifactsdir="$OPTARG" ;;
e) PENRUN_OUTPUT_EXTENSION="$OPTARG" ;;
Expand All @@ -332,12 +335,12 @@ main() {
fi

local cmds
if [[ ! -t 0 ]]; then
if (( batch_mode )); then
mapfile -t cmds </dev/stdin

# Allow the config or spawned programs to detect
# wheather they are run in batched mode.
export PENRUN_BATCHED=1
export PENRUN_BATCH_MODE=1
else
if (($# < 1)); then
dienocmd
Expand Down Expand Up @@ -368,7 +371,7 @@ main() {
local cmd_arr
local fragment

if [[ -n "${PENRUN_BATCHED-}" ]]; then
if [[ -n "${PENRUN_BATCH_MODE-}" ]]; then
fragment="$cmd"
# shellcheck disable=SC2059
if [[ -n "$template" ]]; then
Expand Down Expand Up @@ -409,7 +412,7 @@ main() {
cur_jobs="$((cur_jobs - 1))"
log "Job terminated. Currently active jobs: $cur_jobs."
else
if [[ -n "${PENRUN_BATCHED-}" ]]; then
if [[ -n "${PENRUN_BATCH_MODE-}" ]]; then
log "Starting command '$cmd'."
fi

Expand All @@ -424,7 +427,7 @@ main() {

ret="$?"

if [[ -n "${PENRUN_BATCHED-}" ]]; then
if [[ -n "${PENRUN_BATCH_MODE-}" ]]; then
if ((run_until)) && ((ret != 0)); then
return "$((-EXIT_CODE_FAILED_FIRST))"
elif ((ret != 0)); then
Expand Down
4 changes: 2 additions & 2 deletions penrun.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ PENRUN_ARTIFACTS
This variable is set by penrun to the current artifactsdir.
Spawned programs can use this variable to locate the current artifactsdir to store further artifacts on their own.

PENRUN_BATCHED
This variable is set, when penrun processes commands in batched mode.
PENRUN_BATCH_MODE
This variable is set, when penrun processes commands in batch mode.

PENRUN_COMMAND
This variable includes the full command provided to penrun; excluding DEFAULT_ARGS.
Expand Down

0 comments on commit fb5c261

Please sign in to comment.