Skip to content

Extract repeated directory-check assertions into check-dir.sh helper#1127

Open
brunoborges wants to merge 1 commit into
mainfrom
brunoborges-extract-check-dir-helper
Open

Extract repeated directory-check assertions into check-dir.sh helper#1127
brunoborges wants to merge 1 commit into
mainfrom
brunoborges-extract-check-dir-helper

Conversation

@brunoborges

Copy link
Copy Markdown
Contributor

What

The e2e-cache.yml and e2e-cache-dependency-path.yml workflows repeated the same inline shell block many times to assert that a cache directory exists (and then ls it), plus one inverse check (in gradle2-restore) asserting that ~/.gradle/caches does not exist.

This PR deduplicates that logic into a single helper script.

Changes

  • New __tests__/check-dir.sh (POSIX sh, marked executable):
    • check-dir.sh <dir> [present|absent], default mode present.
    • present: fail with ::error::The <dir> directory does not exist unexpectedly + exit 1 when the directory is missing; otherwise ls it.
    • absent: fail with ::error::The <dir> directory exists unexpectedly + exit 1 when the directory exists.
  • Both cache workflows now call the helper instead of inline if [ ! -d ... ] blocks, keeping the exact same directories and present/absent semantics. Steps that only did check-and-ls collapse to a single line.
  • Paths are passed already-expanded via $HOME (e.g. bash __tests__/check-dir.sh "$HOME/.gradle/caches") to avoid tilde-expansion pitfalls. The sbt jobs use a working-directory override, so they reference the script via $GITHUB_WORKSPACE.
  • All if: OS conditionals are preserved (Coursier: ~/Library/Caches/Coursier on macOS, ~/AppData/Local/Coursier/Cache on Windows, ~/.cache/coursier on Ubuntu). The mvn/gradle/sbt build steps are unchanged.

Validation

  • Both workflow YAML files parse via python3 + yaml.safe_load.
  • bash -n __tests__/check-dir.sh passes.
  • Functional smoke test confirms present/absent pass and fail (exit 1) as expected.

The e2e-cache.yml and e2e-cache-dependency-path.yml workflows repeated the
same inline shell block many times to assert a cache directory exists (and
list it), plus one inverse check that a directory does NOT exist.

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. Per-OS Coursier conditionals and all build steps
are left unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 15, 2026 02:22
@brunoborges brunoborges requested a review from a team as a code owner July 15, 2026 02:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR deduplicates repeated “assert cache directory present/absent” shell logic in the cache E2E GitHub Actions workflows by introducing a shared __tests__/check-dir.sh helper and updating the workflows to call it.

Changes:

  • Added __tests__/check-dir.sh to validate a directory is present (and ls it) or absent (and fail if it exists).
  • Updated .github/workflows/e2e-cache.yml to replace repeated inline if [ -d ... ] assertions with calls to the helper.
  • Updated .github/workflows/e2e-cache-dependency-path.yml to use the helper for the same directory assertions, including the one “absent” check.
Show a summary per file
File Description
.github/workflows/e2e-cache.yml Replaces repeated inline directory checks with calls to __tests__/check-dir.sh across gradle/maven/sbt jobs.
.github/workflows/e2e-cache-dependency-path.yml Switches gradle cache dependency-path assertions to use the shared directory-check helper.
tests/check-dir.sh New reusable script implementing present/absent directory assertions for workflow reuse.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Low

Comment on lines 146 to +148
- name: Check files to cache on ubuntu-latest
if: matrix.os == 'ubuntu-latest'
run: |
if [ ! -d ~/.cache/coursier ]; then
echo "::error::The ~/.cache/coursier directory does not exist unexpectedly"
exit 1
fi
run: bash "$GITHUB_WORKSPACE/__tests__/check-dir.sh" "$HOME/.cache/coursier"
Comment on lines 179 to +181
- name: Confirm that ~/.cache/coursier directory has been made
if: matrix.os == 'ubuntu-latest'
run: |
if [ ! -d ~/.cache/coursier ]; then
echo "::error::The ~/.cache/coursier directory does not exist unexpectedly"
exit 1
fi
ls ~/.cache/coursier
run: bash "$GITHUB_WORKSPACE/__tests__/check-dir.sh" "$HOME/.cache/coursier"
Comment thread __tests__/check-dir.sh
Comment on lines +11 to +14
set -eu

dir=$1
mode=${2:-present}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants