🔒 Repository is read-only – file editing is disabled.

PaganLinux/pagan-web-v2/test_phases.sh main

69 linii Raw ← Powrót
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
#!/usr/bin/env bash
# Test: fazy BUILD/PACKAGE w build.sh – CD do /tmp/src przed fazą PACKAGE
set -euo pipefail

if [[ -e /tmp/src || -e /tmp/destdir || -e /tmp/build.sh ]]; then
    echo "❌ /tmp/src, /tmp/destdir lub /tmp/build.sh już istnieją – przerwij test ręcznie"
    exit 1
fi
trap 'rm -rf /tmp/src /tmp/destdir /tmp/build.sh' EXIT

T="$(mktemp -d)"
trap 'rm -rf "$T" /tmp/src /tmp/destdir /tmp/build.sh' EXIT
mkdir -p /tmp/src/zstd-1.5.6

cat > "$T/recipe.yaml" <<'YAML'
pkgname: zstd
pkgver: '1.5.6'
build: |2-
    cd "zstd-${pkgver}"
    pwd
package: |2-
    cd "zstd-${pkgver}"
    pwd
YAML

# Ten sam generator co w pagbuild (faza PACKAGE po cd /tmp/src)
RECIPE_FILE="$T/recipe.yaml"
BUILD_SCRIPT="$T/build.sh"
python3 - "$RECIPE_FILE" "$BUILD_SCRIPT" <<'PY'
import yaml, sys
recipe, out = sys.argv[1], sys.argv[2]
with open(recipe) as f:
    data = yaml.safe_load(f)
build_phase = data.get('build', '')
package_phase = data.get('package', '')
script = f'''#!/bin/bash
set -eo pipefail
export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/tools/bin
export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/share/pkgconfig
export LANG=C.UTF-8
export HOME=/root
export PKGDIR=/tmp/destdir
export DESTDIR=/tmp/destdir
export pkgver={repr(data.get('pkgver', ''))}
export pkgname={repr(data.get('pkgname', ''))}
export pkgrel={repr(data.get('pkgrel', 1))}

cd /tmp/src

echo '═══ FAZA BUILD ═══'
{build_phase}

echo '═══ FAZA PACKAGE ═══'
cd /tmp/src
{package_phase}

echo '═══ GOTOWE ═══'
'''
open(out, 'w').write(script)
PY
chmod +x "$T/build.sh"
cp "$T/build.sh" /tmp/build.sh

OUT=$(cd / && bash /tmp/build.sh)
echo "$OUT"
echo "---"
BUILD_PWD=$(echo "$OUT" | sed -n '/FAZA BUILD/,/FAZA PACKAGE/p' | grep -c '^/tmp/src/zstd-1.5.6$')
PACK_PWD=$(echo "$OUT" | sed -n '/FAZA PACKAGE/,/GOTOWE/p' | grep -c '^/tmp/src/zstd-1.5.6$')
[[ "$BUILD_PWD" == "1" && "$PACK_PWD" == "1" ]] && echo "✅ PASS: obie fazy weszły do zstd-1.5.6" || { echo "❌ FAIL: BUILD=$BUILD_PWD PACKAGE=$PACK_PWD"; exit 1; }