mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
build.sh and the releases/ scripts wrote all over the machine: temporary files to /tmp and macOS's /var/folders, downloads and release zips to ~/Downloads or ~/Lataukset, Meteor to ~/.meteor, Node.js to /usr/local (sudo n) or ~/.nvm, the npm cache to ~/.npm, Volta to ~/.volta, the Sandstorm toolchain to ~/projects, and PATH lines into ~/.zshrc and ~/.bashrc. A sandboxed editor (Flatpak on Linux, sandbox-exec on macOS) can reach only the checkout, and a container's own /tmp is a few hundred megabytes. Everything is in .tools/ now, which git and Meteor ignore: - releases/tools-env.sh, sourced by build.sh and every script that writes files, sets TMPDIR/TMP/TEMP to .tools/tmp (also downloads and release zips), NVM_DIR, npm_config_cache, VOLTA_HOME and the meteor-spk directory to .tools/, METEOR_WAREHOUSE_DIR to .tools/.meteor once Meteor is installed there, and puts those tools first on PATH, so no shell rc file is edited. HOME is not moved: git needs ~/.gitconfig and ~/.ssh. A TMPDIR already inside a .tools/ is kept, so a test's own directory there stays its own; without a writable one it stops rather than fall back to /tmp. It never fails a caller running set -euo pipefail. - macOS's mktemp ignores TMPDIR when given no template, so every mktemp names one: mktemp "$TMPDIR/name.XXXXXX". Fixed /tmp files are in $TMPDIR. - build.sh installs Node.js on Linux into .tools/n (N_PREFIX, no sudo), nvm on macOS into .tools/nvm (PROFILE=/dev/null: no rc file edited), and Meteor with HOME=.tools for the installer only, into .tools/.meteor. build.sh is replaced, not edited in place, while it may be running. - Containers get this checkout's .tools/tmp as their /tmp: every db-conformance database (MariaDB's temporary tables were verified to land there, and MongoDB's socket) and the repack container, which empty it themselves before they are removed. install-node-for-arch.sh requires the mounted TMPDIR. - tests/run-node-suites.cjs gives every suite TMPDIR in .tools/tmp, and the tests that copied a script into a fixture copy tools-env.sh too; tests that pinned ~/.meteor, the rc file edits, sudo n or /tmp/manifest.json pin the .tools/ places now and say why. tests/toolsDirOnly.test.cjs runs tools-env.sh against a TMPDIR already set elsewhere and under set -euo pipefail, and fails on any script that makes a temporary file without naming .tools/tmp, writes to the home directory, or edits a shell rc file, or on a container whose /tmp is its own. Thanks to xet7 !
81 lines
3.4 KiB
Bash
Executable File
81 lines
3.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Attach already-built artifacts. A stalled transfer must not consume the job's
|
|
# entire lifetime (v11.85 amd64 snap); verify names AND sizes from the release.
|
|
#
|
|
# This is THE way a release workflow attaches a file to a GitHub Release. Every
|
|
# job that builds a release asset calls it as its own last step, the moment that
|
|
# asset is built and checked - not a later job that collects everything at the
|
|
# end. A release then fills up as its builds finish, and a run that is cancelled
|
|
# or dies half way still leaves every finished file on the release instead of
|
|
# none of them.
|
|
#
|
|
# It runs on the Linux, macOS and Windows (Git Bash) runners alike, so nothing
|
|
# here may assume GNU tools: macOS has no `timeout`, and on Windows the first
|
|
# `timeout` on PATH can be System32's "wait N seconds" command, which takes
|
|
# different arguments.
|
|
set -euo pipefail
|
|
. "$(dirname "${BASH_SOURCE[0]}")/tools-env.sh" # temporary files and downloads go to .tools/tmp
|
|
if [ "$#" -lt 3 ]; then
|
|
echo "Usage: $0 <repository> <tag> <artifact> [artifact ...]" >&2
|
|
exit 2
|
|
fi
|
|
repository=$1
|
|
tag=$2
|
|
shift 2
|
|
for artifact in "$@"; do
|
|
[ -s "$artifact" ] || { echo "Missing or empty artifact: $artifact" >&2; exit 1; }
|
|
done
|
|
repo_root=$(cd "$(dirname "$0")/.." && pwd)
|
|
export TMPDIR="${TMPDIR:-$repo_root/.tools/tmp}"
|
|
mkdir -p "$TMPDIR"
|
|
upload_tmp=$(mktemp -d "$TMPDIR/release-upload.XXXXXX")
|
|
trap 'rm -rf "$upload_tmp"' EXIT
|
|
|
|
# A bounded command where a GNU-compatible timeout exists (Linux: timeout,
|
|
# macOS with coreutils: gtimeout), and the plain command where none does. The
|
|
# probe RUNS it, so a `timeout` that is not GNU's is not mistaken for one.
|
|
bounded() {
|
|
local limit=$1 kill_after=$2
|
|
shift 2
|
|
local t
|
|
for t in timeout gtimeout; do
|
|
if command -v "$t" >/dev/null 2>&1 && "$t" --kill-after=1s 5s true >/dev/null 2>&1; then
|
|
"$t" --kill-after="$kill_after" "$limit" "$@"
|
|
return
|
|
fi
|
|
done
|
|
"$@"
|
|
}
|
|
|
|
for attempt in 1 2 3; do
|
|
echo "Attaching artifacts to $repository $tag (attempt $attempt/3)."
|
|
if bounded 10m 30s gh release upload --repo "$repository" "$tag" "$@" --clobber; then
|
|
if bounded 60s 10s gh release view --repo "$repository" "$tag" \
|
|
--json assets --jq '.assets[] | [.name, .size] | @tsv' > "$upload_tmp/assets.tsv"; then
|
|
verified=true
|
|
for artifact in "$@"; do
|
|
# tr: BSD wc pads the count with spaces.
|
|
size=$(wc -c < "$artifact" | tr -d ' ')
|
|
if ! awk -F '\t' -v name="$(basename "$artifact")" -v size="$size" \
|
|
'$1 == name && $2 == size { found=1 } END { exit !found }' "$upload_tmp/assets.tsv"; then
|
|
echo "::warning::$(basename "$artifact") is missing or has the wrong size in $tag."
|
|
verified=false
|
|
fi
|
|
done
|
|
if [ "$verified" = true ]; then
|
|
for artifact in "$@"; do
|
|
echo "OK: $(basename "$artifact") is attached to $tag ($(( $(wc -c < "$artifact" | tr -d ' ') / 1024 / 1024 )) MiB)."
|
|
done
|
|
echo "OK: all artifacts attached to $tag with matching sizes."
|
|
exit 0
|
|
fi
|
|
fi
|
|
fi
|
|
if [ "$attempt" -lt 3 ]; then
|
|
echo "::warning::Release attachment did not complete and verify; retrying in $((attempt * 10))s."
|
|
sleep $((attempt * 10))
|
|
fi
|
|
done
|
|
echo "::error::Could not attach and verify artifacts in $repository $tag after three bounded attempts. The release must exist, and GITHUB_TOKEN must be allowed to write releases here (permissions: contents: write). The local build artifacts remain available." >&2
|
|
exit 1
|