mirror of
https://github.com/actions/setup-java.git
synced 2026-07-29 09:05:56 +00:00
The e2e-cache.yml workflow repeated the same inline shell block many times to assert a cache directory exists (and list it), plus inverse checks that a directory does NOT exist (the gradle2/maven2/sbt2 cache-miss jobs). Add `__tests__/check-dir.sh` (POSIX sh, executable) with a `check-dir.sh <dir> [present|absent]` interface and replace every inline check with a call to it, passing already-expanded $HOME paths to avoid tilde-expansion pitfalls. The sbt jobs override working-directory, so they call the helper via $GITHUB_WORKSPACE. Per-OS Coursier conditionals and all build steps are left unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
35 lines
796 B
Bash
Executable File
35 lines
796 B
Bash
Executable File
#!/bin/sh
|
|
# Assert whether a directory exists, for use in the e2e cache workflows.
|
|
#
|
|
# Usage: check-dir.sh <dir> [present|absent]
|
|
#
|
|
# present (default): fail if <dir> does NOT exist, otherwise list its contents.
|
|
# absent: fail if <dir> DOES exist.
|
|
#
|
|
# Call with already-expanded paths (e.g. "$HOME/.gradle/caches") to avoid
|
|
# tilde-expansion pitfalls.
|
|
set -eu
|
|
|
|
dir=$1
|
|
mode=${2:-present}
|
|
|
|
case "$mode" in
|
|
present)
|
|
if [ ! -d "$dir" ]; then
|
|
echo "::error::The $dir directory does not exist unexpectedly"
|
|
exit 1
|
|
fi
|
|
ls "$dir"
|
|
;;
|
|
absent)
|
|
if [ -d "$dir" ]; then
|
|
echo "::error::The $dir directory exists unexpectedly"
|
|
exit 1
|
|
fi
|
|
;;
|
|
*)
|
|
echo "::error::Unknown mode '$mode' (expected 'present' or 'absent')"
|
|
exit 1
|
|
;;
|
|
esac
|