#!/usr/bin/env bash # A workflow's final step releases only its checkout. Shared caches live outside it. set -euo pipefail root="${GITHUB_WORKSPACE:?cleanup-job-workspace: GITHUB_WORKSPACE is missing}" here="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" . "$here/scripts/lib/owned-root.sh" refuse_wide_root "the job checkout" "$root" root="$(cd "$root" && pwd -P)" [ "$root" = "$here" ] || { echo "cleanup-job-workspace: refusing another checkout" >&2; exit 2; } [ -d "$root/.git" ] || { echo "cleanup-job-workspace: not a job checkout" >&2; exit 2; } # The job's own temp folder first (scripts/ci/job-tmp.sh): it is outside the checkout. bash "$here/scripts/ci/job-tmp.sh" close || echo "cleanup-job-workspace: the job's temp folder was not removed" # Do not remove the runner's cwd itself: its post-job actions still use it. # find visits symlinks as entries, never follows them into shared caches. find "$root" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} + echo "job workspace released: $root"