Skip to content

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

Merged
brunoborges merged 2 commits into
mainfrom
brunoborges-extract-check-dir-helper
Jul 15, 2026
Merged

Extract repeated directory-check assertions into check-dir.sh helper#1127
brunoborges merged 2 commits into
mainfrom
brunoborges-extract-check-dir-helper

Conversation

@brunoborges

@brunoborges brunoborges commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

What

e2e-cache.yml repeated the same inline shell block many times to assert that a cache directory exists (and then ls it), plus several inverse checks (the gradle2/maven2/sbt2 cache-miss jobs) asserting a directory does not exist.

This PR deduplicates that logic into a single helper script.

Rebased onto main after #1124 merged, which consolidated e2e-cache-dependency-path.yml into e2e-cache.yml and added maven/sbt cache-dependency-path coverage. The extraction is now applied across all 25 checks in the consolidated workflow; the standalone dependency-path file no longer exists.

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.
  • e2e-cache.yml now calls 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

  • e2e-cache.yml parses 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.

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 thread .github/workflows/e2e-cache.yml
Comment thread .github/workflows/e2e-cache.yml
Comment thread __tests__/check-dir.sh
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>
@brunoborges
brunoborges force-pushed the brunoborges-extract-check-dir-helper branch from d1b0ad1 to 0040423 Compare July 15, 2026 14:50
…ditionals

- check-dir.sh: with set -u, invoking without a <dir> argument failed with an
  opaque "parameter not set" error. Add an explicit argc check that prints a
  usage message and exits 2 (distinct from the assertion failure code 1).
- e2e-cache.yml: the sbt-save and sbt-restore jobs run on an ubuntu-22.04
  matrix entry, but their coursier-cache steps were guarded by
  'if: matrix.os == "ubuntu-latest"', so those checks never executed on
  Ubuntu. Align the conditionals with the matrix (ubuntu-22.04), matching the
  newer sbt1/sbt2 jobs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@brunoborges
brunoborges merged commit 4b0728b into main Jul 15, 2026
440 checks passed
@brunoborges
brunoborges deleted the brunoborges-extract-check-dir-helper branch July 15, 2026 15:14
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