62 lines
3.6 KiB
Bash
62 lines
3.6 KiB
Bash
#!/bin/bash
|
|
# genereaza.sh: cum s-au facut fixturile NuGet (2026-09-29): un proiect mic, restaurat de .NET SDK INSUSI cu lockfile-ul pornit, FARA
|
|
# retea: nuget.config sterge toate sursele si pune ca sursa unica memoria locala de pachete (~/.nuget/packages, asezarea ei e a unui
|
|
# dosar-sursa ierarhic), iar pachetele se extrag intr-un dosar temporar (memoria locala nu e modificata). Deci packages.lock.json e
|
|
# scris de NuGet, nu de noi. Doua proiecte: `lib` (net8.0 si net10.0, Newtonsoft.Json si BouncyCastle.Cryptography) si `lib.tests`
|
|
# (net8.0, xunit, cu referinta de proiect catre lib: intrari de tip Project si multe tranzitive).
|
|
# bash genereaza.sh [dotnet] rescrie lib/packages.lock.json si lib.tests/packages.lock.json
|
|
set -eu
|
|
AICI="$(cd "$(dirname "$0")" && pwd)"
|
|
DOTNET="${1:-$HOME/.dotnet/dotnet.exe}"
|
|
SURSA="$HOME/.nuget/packages"
|
|
[ -d "$SURSA" ] || { echo "NEMASURAT: nu exista memoria locala de pachete $SURSA"; exit 2; }
|
|
T="$(mktemp -d)"; trap 'rm -rf "$T"' EXIT
|
|
cat > "$T/nuget.config" <<EOF
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
<configuration>
|
|
<packageSources><clear /><add key="local" value="$(cygpath -w "$SURSA" 2>/dev/null || echo "$SURSA")" /></packageSources>
|
|
<config><add key="globalPackagesFolder" value="$(cygpath -w "$T/pk" 2>/dev/null || echo "$T/pk")" /></config>
|
|
</configuration>
|
|
EOF
|
|
mkdir -p "$T/lib" "$T/lib.tests"
|
|
cat > "$T/lib/lib.csproj" <<'EOF'
|
|
<Project Sdk="Microsoft.NET.Sdk">
|
|
<PropertyGroup>
|
|
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
|
|
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
|
<NuGetAudit>false</NuGetAudit>
|
|
</PropertyGroup>
|
|
<ItemGroup>
|
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
|
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.2" />
|
|
</ItemGroup>
|
|
</Project>
|
|
EOF
|
|
cat > "$T/lib.tests/lib.tests.csproj" <<'EOF'
|
|
<Project Sdk="Microsoft.NET.Sdk">
|
|
<PropertyGroup>
|
|
<TargetFramework>net8.0</TargetFramework>
|
|
<IsPackable>false</IsPackable>
|
|
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
|
<NuGetAudit>false</NuGetAudit>
|
|
</PropertyGroup>
|
|
<ItemGroup>
|
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
|
<PackageReference Include="xunit" Version="2.5.3" />
|
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
|
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
|
</ItemGroup>
|
|
<ItemGroup><ProjectReference Include="../lib/lib.csproj" /></ItemGroup>
|
|
</Project>
|
|
EOF
|
|
export DOTNET_CLI_TELEMETRY_OPTOUT=1 DOTNET_NOLOGO=1 DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 DOTNET_CLI_WORKLOAD_UPDATE_NOTIFY_DISABLE=1
|
|
( cd "$T/lib.tests" && "$DOTNET" restore --configfile "$(cygpath -w "$T/nuget.config" 2>/dev/null || echo "$T/nuget.config")" < /dev/null )
|
|
mkdir -p "$AICI/lib" "$AICI/lib.tests"
|
|
# fisierele de proiect se pastreaza langa lockfile (numele proiectului e radacina SBOM-ului), fara nicio schimbare
|
|
cp "$T/lib/lib.csproj" "$T/lib/packages.lock.json" "$AICI/lib/"
|
|
cp "$T/lib.tests/lib.tests.csproj" "$T/lib.tests/packages.lock.json" "$AICI/lib.tests/"
|
|
# NuGet scrie contentHash-ul sau (SHA-512 peste continutul pachetului, fara semnatura de depozit) si in .nupkg.metadata: il copiem
|
|
# pentru controlul "hash-ul din lockfile e al lui NuGet pentru acel pachet" (nu e SHA-512 al fisierului .nupkg semnat)
|
|
( cd "$T/pk" && for m in */*/.nupkg.metadata; do printf '%s %s\n' "$(dirname "$m")" "$(grep -o '"contentHash": *"[^"]*"' "$m" | cut -d'"' -f4)"; done ) | sort > "$AICI/nupkg-metadata-contenthash.txt"
|
|
echo "scris: lib/packages.lock.json, lib.tests/packages.lock.json, nupkg-metadata-contenthash.txt ($(wc -l < "$AICI/nupkg-metadata-contenthash.txt") pachete)"
|