#!/bin/bash set -euo pipefail cd "$(dirname "$0")/../.." unset BASH_ENV # shellcheck source=Scripts/product.env source Scripts/product.env work=$(mktemp -d "${TMPDIR:-/tmp}/launch-tests.XXXXXX") trap 'rm -rf "$work"' EXIT mkdir -p "$work/bin" "$work/home" "$work/project/Scripts" export LAUNCH_TEST_LOG="$work/tools.log" for tool in gh git security xcrun cloudflared ssh swiftc; do # shellcheck disable=SC2016 printf '%s\n' '#!/bin/bash' 'printf "%s\n" "$0 $*" >> "$LAUNCH_TEST_LOG"' 'exit 99' > "$work/bin/$tool" chmod +x "$work/bin/$tool" done count=0 check() { if ! "$@"; then printf 'Launch test failed: %s\n' "$*" >&2; exit 1; fi count=$((count + 1)) } fails() { if "$@" > "$work/failure.log" 2>&1; then return 1; fi; } plan() { env PATH="$work/bin:$PATH" HOME="$work/home" bash Scripts/launch.sh "$@"; } plan --dry-run > "$work/plan" check grep -Fq "$PRODUCT_NAME ($PRODUCT_CLI, $PRODUCT_BUNDLE_ID)" "$work/plan" check grep -Fq "$PRODUCT_KNOT_URL" "$work/plan" check grep -Fq "$PRODUCT_GITHUB_REPO" "$work/plan" check grep -Fq "$PRODUCT_SITE_REPO/$PRODUCT_SITE_FEED" "$work/plan" for name in DEVELOPER_ID_P12 DEVELOPER_ID_PASSWORD DEVELOPER_ID_IDENTITY ASC_PRIVATE_KEY ASC_KEY_ID ASC_ISSUER_ID APPLE_TEAM_ID MIRROR_TOKEN SPARKLE_PRIVATE_KEY SPARKLE_PUBLIC_KEY; do check grep -Fq "$name" "$work/plan" done check grep -Fq 'Keychain' "$work/plan" check grep -Fq 'cloudflared tunnel route dns' "$work/plan" check grep -Fq 'No commands, secrets, files, or remotes changed' "$work/plan" check grep -Fq 'every 15 minutes or by manual dispatch (not pushes)' "$work/plan" check grep -Fq "mirrors only $PRODUCT_DEFAULT_BRANCH and eligible v tags" "$work/plan" check grep -Fq 'fresh Keychain helper' "$work/plan" check grep -Fq 'GitHub environment mirror' "$work/plan" check grep -Fq 'Contents and Workflows read/write' "$work/plan" check grep -Fq 'BLOCK release tag push and manual release dispatch' "$work/plan" check grep -Fq 'workflow_dispatch on main' "$work/plan" check grep -Fq "displayTitle 'Release v$PRODUCT_FIRST_VERSION'" "$work/plan" check grep -Fq 'docs/releasing-setup.md' "$work/plan" check grep -Fq 'Exit 3 means required' "$work/plan" check grep -Fq 'New GitHub tag pushes, including mirrored tags, trigger the default-branch dispatcher' "$work/plan" check grep -Fq 'no secret-bearing tangled workflows' "$work/plan" plan --dry-run --version 2.3.4 --site-repo '/tmp/site with spaces' --site-feed 'dist/appcast.xml' > "$work/custom" check grep -Fq 'v2.3.4' "$work/custom" check grep -Fq '/tmp/site with spaces/dist/appcast.xml' "$work/custom" check plan --help > "$work/help" check grep -Fq 'Usage:' "$work/help" for version in v1.0 '' '1;touch sentinel' 1.2.3.4 -1 1.x 1 1.2 1.2.3-beta 1.2.3+build.42 $'1.2.3\n'; do check fails plan --dry-run --version "$version" done check fails plan --unknown check fails plan --version check fails plan --replace-secret check fails plan --dry-run --replace-secret UNKNOWN check fails plan --dry-run --replace-secret SPARKLE_PRIVATE_KEY check plan --dry-run --replace-secret DEVELOPER_ID_PASSWORD > "$work/replace-plan" check grep -Fq 'Replacement requested: DEVELOPER_ID_PASSWORD' "$work/replace-plan" check fails plan --dry-run --site-feed ../appcast.xml check fails plan --dry-run --site-feed /appcast.xml check fails plan "$work/product.env" mv "$work/product.env" "$work/project/Scripts/product.env" env PATH="$work/bin:$PATH" HOME="$work/home" bash "$work/project/Scripts/launch.sh" --dry-run > "$work/renamed" check grep -Fq 'Crate (crt, org.example.crate)' "$work/renamed" check grep -Fq 'example/crate' "$work/renamed" check grep -Fq 'git@knot.example.org:example.org/crate' "$work/renamed" check test ! -e "$LAUNCH_TEST_LOG" swiftc -swift-version 6 -warnings-as-errors Scripts/launch-keychain.swift -o "$work/keychain" check fails "$work/keychain" check fails "$work/keychain" get check fails "$work/keychain" ensure-update check fails "$work/keychain" put unused unused "$work/key-error" 2>&1 && exit 1 check grep -Fq 'base64 Ed25519 seed' "$work/key-error" source Scripts/script-root-test.sh check script_root_test InteractiveLaunchTests check swift test --package-path Scripts/tests/LaunchTests -Xswiftc -warnings-as-errors printf 'Launch shell checks passed: %s\n' "$count"