#!/usr/bin/env bash # A CI job's own temp folder on the Linux box, made after its checkout and # removed by its last step, which runs whether the job passed or failed. # # bash scripts/ci/job-tmp.sh open # after the checkout: TMPDIR for every later step # bash scripts/ci/job-tmp.sh close # from cleanup-job-workspace.sh (`if: always()`) # # WHY (coordinator, 22 Nov 2026). The box's disk stood at 94%: /tmp held about # 232,000 items (about 70 GB), 219,000 of them the runner's — test databases, # kotlin-daemon logs, cotton-media and shape-move databases, cst folders — # because every job wrote into the one shared /tmp and nothing took it away. # Now a job writes into /tmp/ci-job---XXXXXX, set as TMPDIR, TMP and # TEMP for its later steps through GITHUB_ENV, and its last step removes it. # What a killed job leaves is swept by ci-sweep.yml once it is three hours old. # # Linux only. A Mac job keeps its own temp folder: the Swift stub's cache under # it is reused from run to run (ui-stub-workspace.py), and the Macs' disk # policy measures that folder (scripts/lib/mac_disk_policy.py). set -euo pipefail prefix=ci-job- case "${1-}" in open) # WITHDRAWN (22 Nov 2026, rust-main 15232 and android 15230): a job's TMPDIR # reached an sccache server the job's rustc wrapper started on its own # (with no server listening, the first compile starts one, in this env), the # server outlived the job, and once this folder was removed every compile on # the box failed "Failed to create temp dir". Jobs share /tmp again; # ci-sweep.yml takes what they leave there once it is three hours old. echo "job-tmp: jobs share /tmp (swept every half hour by ci-sweep.yml)" # A server started while this script still gave jobs their own folder # still points at it: stopped here, the first compile starts a sound one. . "$(cd "$(dirname "${BASH_SOURCE[0]}")/../lib" && pwd)/sccache-alone.sh" sccache_heal_tmp exit 0 if [ "$(uname -s)" != Linux ]; then echo "job-tmp: $(uname -s) keeps its temp folder" exit 0 fi : "${GITHUB_ENV:?job-tmp: GITHUB_ENV is missing}" job="$(printf '%s' "${GITHUB_RUN_ID:-run}-${GITHUB_JOB:-job}" | tr -c 'A-Za-z0-9-' '-')" dir="$(mktemp -d "/tmp/${prefix}${job}-XXXXXX")" { echo "TMPDIR=$dir" echo "TMP=$dir" echo "TEMP=$dir" echo "CI_JOB_TMP=$dir" } >>"$GITHUB_ENV" echo "job-tmp: TMPDIR=$dir" ;; close) dir="${CI_JOB_TMP:-}" [ -n "$dir" ] || exit 0 # Only a folder `open` made: /tmp/ci-job-, one level under /tmp, ours, not a link. case "$dir" in /tmp/"$prefix"*/* | */../*) echo "job-tmp: refusing '$dir'" >&2; exit 2 ;; /tmp/"$prefix"?*) ;; *) echo "job-tmp: refusing '$dir'" >&2; exit 2 ;; esac if [ ! -d "$dir" ] || [ -L "$dir" ] || [ ! -O "$dir" ]; then echo "job-tmp: nothing to remove at $dir" exit 0 fi rm -rf -- "$dir" echo "job-tmp: removed $dir" ;; *) echo "usage: job-tmp.sh open|close" >&2 exit 2 ;; esac