#!/bin/bash set -euo pipefail cd "$(dirname "$0")/../.." unset BASH_ENV source Scripts/product.env source Scripts/version.sh root=$PWD if [[ -z ${PARCEL_DEV_BINARY:-} ]]; then PARCEL_DEV_BINARY=$(Scripts/parcel-dev.sh --path) fi PARCEL_DEV_BINARY=$(realpath "$PARCEL_DEV_BINARY") export PARCEL_DEV_BINARY original_path=$PATH work=$(mktemp -d "${TMPDIR:-/tmp}/$PRODUCT_CASK-safety.XXXXXX") trap 'rm -rf "$work"' EXIT count=0 check() { if ! "$@"; then printf 'Packaging safety test failed: %s\n' "$*" >&2; exit 1; fi count=$((count + 1)) } fails() { if "$@" > "$work/failure.log" 2>&1; then printf 'Expected failure: %s\n' "$*" >&2; return 1; fi } for version in 0.1.0 12.34.56 1.2.3-beta 1.2.3-beta.2 1.2.3+build.42 1.2.3-rc.1+build-42; do check validate_version "$version" done for version in '' 1 1.2 1.2.3.4 letters '1.2.3 bad' $'1.2.3\n1.2.3' $'1.2.3\n' $'1.2.3\r' $'1.2.3\t' $'1.2.3\033' '1.2.3-' '1.2.3+' '1.2.3-β' '1.2.3+../bad'; do check fails validate_version "$version" check fails env PARCEL_VERSION="$version" PARCEL_SIGN_IDENTITY=- Scripts/bundle.sh check fails env PARCEL_VERSION="$version" Scripts/release.sh --dry-run check fails Scripts/launch.sh --dry-run --version "$version" check fails env GITHUB_ACTIONS=true GITHUB_EVENT_NAME=push GITHUB_REF_TYPE=tag \ GITHUB_REPOSITORY="$PRODUCT_GITHUB_REPO" GITHUB_REF_NAME="v$version" \ GITHUB_REF="refs/tags/v$version" GITHUB_RUN_NUMBER=1 Scripts/ci-release.sh preflight done check /bin/bash Scripts/version.sh version 1.2.3-beta.1+build.42 check /bin/bash Scripts/version.sh release 1.2.3 42 check /bin/bash Scripts/version.sh build 42 check fails /bin/bash Scripts/version.sh unknown check fails /bin/bash Scripts/version.sh release 1.2.3 check fails /bin/bash Scripts/version.sh version $'1.2.3\n' for version in 0.1.0 12.34.56; do check validate_ordered_version "$version" check /bin/bash Scripts/version.sh ordered-version "$version" done for version in '' 1 1.2 1.2.3.4 1.2.3-beta 1.2.3+build.42 $'1.2.3\n'; do check fails validate_ordered_version "$version" check fails /bin/bash Scripts/version.sh ordered-version "$version" done check fails validate_ordered_version check fails validate_ordered_version 1.2.3 extra for number in 1 42; do check validate_positive_build_number "$number" check /bin/bash Scripts/version.sh positive-build "$number" done for number in '' 0 001 1.2 $'42\n'; do check fails validate_positive_build_number "$number" check fails /bin/bash Scripts/version.sh positive-build "$number" done check fails validate_positive_build_number check fails validate_positive_build_number 42 extra for number in 0 1 42 001; do check validate_build_number "$number"; done for number in '' 1.2 letters '1 2' $'1\n2' $'1\n' $'1\r' $'1\t'; do check fails validate_build_number "$number" check fails env PARCEL_BUILD_NUMBER="$number" PARCEL_SIGN_IDENTITY=- Scripts/bundle.sh check fails env PARCEL_BUILD_NUMBER="$number" Scripts/release.sh --dry-run done mkdir -p "$work/project/Scripts" "$work/project/build/$PRODUCT_NAME.app/Contents/Frameworks/Sample.framework/Versions/B" "$work/allowed" "$work/bin" cp Scripts/product.env Scripts/packaging-paths.sh Scripts/parcel-dev.sh "$work/project/Scripts/" app="$work/project/build/$PRODUCT_NAME.app" ditto Sources/ParcelUI/Resources/AppIcons "$app/Contents/Resources/Parcel_ParcelUI.bundle/Contents/Resources" framework="$app/Contents/Frameworks/Sample.framework" printf 'framework\n' > "$framework/Versions/B/Sample" ln -s B "$framework/Versions/Current" ln -s Versions/Current/Sample "$framework/Sample" check Scripts/bundle-preflight.sh "$app" ln -s "$framework/Versions/B/Sample" "$app/Contents/absolute" ln -s ../../../outside "$app/Contents/escaping" mkfifo "$app/Contents/pipe" Scripts/parcel-dev.sh packaging-socket-fixture "$work/s" "$app/Contents/socket" check fails Scripts/bundle-preflight.sh "$app" for path in absolute escaping pipe socket; do check grep -Fq "Contents/$path" "$work/failure.log"; done check grep -Fq 'absolute symlink' "$work/failure.log" check grep -Fq 'symlink escapes' "$work/failure.log" rm "$app/Contents/absolute" "$app/Contents/escaping" "$app/Contents/pipe" "$app/Contents/socket" ln -s missing "$app/Contents/dangling" check fails Scripts/bundle-preflight.sh "$app" rm "$app/Contents/dangling" ln -s cycle-link "$app/Contents/cycle-link" check fails Scripts/bundle-preflight.sh "$app" rm "$app/Contents/cycle-link" check Scripts/bundle-preflight.sh "$app" check fails Scripts/bundle-preflight.sh cd "$work/project" source Scripts/packaging-paths.sh check test "$(packaging_app_path "$app")" = "$(realpath "$app")" mkdir build/Wrong.app check fails packaging_app_path build/Wrong.app check fails "$root/Scripts/dmg.sh" "$PWD/build/Wrong.app" "$TMPDIR/wrong-name.dmg" check fails "$root/Scripts/check-bundle.sh" "$PWD/build/Wrong.app" ln -s Wrong.app build/Alias.app check fails packaging_app_path build/Alias.app TMPDIR=$(realpath "$work/allowed") export TMPDIR check test "$(packaging_output_path build/new/deep/image.dmg)" = "$(realpath .)/build/new/deep/image.dmg" check test "$(packaging_output_path "$TMPDIR/image.dmg")" = "$TMPDIR/image.dmg" check fails packaging_output_path "$work/outside/image.dmg" check test ! -e "$work/outside" ln -s "$work" build/outside check fails packaging_output_path build/outside/image.dmg check fails packaging_output_path build/outside/missing/image.dmg printf 'existing\n' > build/existing.dmg check fails packaging_output_path build/existing.dmg ln -s "$work/missing" build/dangling.dmg check fails packaging_output_path build/dangling.dmg mv build actual-build ln -s actual-build build check fails packaging_build_directory check fails packaging_app_path "$app" check fails packaging_output_path "$TMPDIR/image.dmg" rm build mv actual-build build mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources/bin" printf 'app\n' > "$app/Contents/MacOS/$PRODUCT_NAME" printf 'cli\n' > "$app/Contents/Resources/bin/$PRODUCT_CLI" cat > "$work/bin/xcrun" <<'STUB' #!/bin/bash [[ $* == --show-sdk-version ]] || exit 1 printf '26.2\n' STUB cat > "$work/bin/otool" <<'STUB' #!/bin/bash set -euo pipefail [[ $1 == -l && -f $2 ]] for architecture in arm64 x86_64; do printf '%s (architecture %s):\nLoad command 0\n cmd LC_BUILD_VERSION\n cmdsize 32\n platform 1\n minos %s\n sdk %s\n ntools 1\n' "$2" "$architecture" "${TEST_MINOS:-15.0}" "${TEST_SDK:-26.2}" done STUB chmod +x "$work/bin/"* export PATH="$work/bin:$PATH" check "$root/Scripts/parcel-dev.sh" check-binaries "$app" "$PRODUCT_NAME" "$PWD" check fails env TEST_MINOS=14.0 "$root/Scripts/parcel-dev.sh" check-binaries "$app" "$PRODUCT_NAME" "$PWD" check fails env TEST_SDK=15.0 "$root/Scripts/parcel-dev.sh" check-binaries "$app" "$PRODUCT_NAME" "$PWD" for binary in "$app/Contents/MacOS/$PRODUCT_NAME" "$app/Contents/Resources/bin/$PRODUCT_CLI"; do printf 'diagnostic %s/Sources/example.swift\n' "$PWD" >> "$binary" check fails "$root/Scripts/parcel-dev.sh" check-binaries "$app" "$PRODUCT_NAME" "$PWD" check grep -Fq "${binary#"$app/"}" "$work/failure.log" printf 'binary\n' > "$binary" done printf 'int main(void) { return 0; }\n' > "$PWD/source.c" check /usr/bin/clang -g -mmacosx-version-min=15.0 -Wl,-rpath,"$PWD/build/frameworks" \ -Wl,-rpath,@executable_path/../Frameworks "$PWD/source.c" -o "$app/Contents/MacOS/$PRODUCT_NAME" check fails env PATH="$original_path" "$root/Scripts/parcel-dev.sh" check-binaries "$app" "$PRODUCT_NAME" "$PWD" mv "$app/Contents/MacOS/$PRODUCT_NAME.dSYM" "$work/diagnostics.dSYM" check env PATH="$original_path" "$root/Scripts/parcel-dev.sh" strip-binary-paths "$app/Contents/MacOS/$PRODUCT_NAME" "$PWD" check env PATH="$original_path" "$root/Scripts/parcel-dev.sh" check-binaries "$app" "$PRODUCT_NAME" "$PWD" /usr/bin/otool -l "$app/Contents/MacOS/$PRODUCT_NAME" > "$work/loader-paths.log" check grep -Fq '@executable_path/../Frameworks' "$work/loader-paths.log" check fails grep -Fq "$PWD" "$work/loader-paths.log" mkdir -p "$work/staged" "$work/published-parent" printf 'first\n' > "$work/staged/marker" check "$root/Scripts/parcel-dev.sh" install-bundle "$work/staged" "$work/published-parent/$PRODUCT_NAME.app" check test ! -e "$work/staged" mkdir "$work/staged" printf 'second\n' > "$work/staged/marker" check "$root/Scripts/parcel-dev.sh" install-bundle "$work/staged" "$work/published-parent/$PRODUCT_NAME.app" check grep -q second "$work/published-parent/$PRODUCT_NAME.app/marker" check grep -q first "$work/staged/marker" ln -s "$work/published-parent/$PRODUCT_NAME.app" "$work/link.app" check fails "$root/Scripts/parcel-dev.sh" install-bundle "$work/staged" "$work/link.app" check test -L "$work/link.app" printf 'Packaging safety checks passed: %s\n' "$count"