Skip to content

Commit bc924bc

Browse files
authored
chore: fix integ-test run-from-dist for NuGet packages (#5176)
Set local source in a NuGet.Config file instead of hijacking a very specific sub-command of `dotnet`, which will yield much more stable operations (all `dotnet` commands that may incur a `restore` operation will be able to use the "correct" source(s)).
1 parent 29d450d commit bc924bc

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

packages/aws-cdk/test/integ/run-against-dist.bash

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,43 @@ function prepare_java_packages() {
155155

156156
function prepare_nuget_packages() {
157157
# For NuGet, we wrap the "dotnet" CLI command to use local packages.
158-
log "Hijacking 'dotnet build' command..."
158+
log "Writing new NuGet configuration..."
159159

160-
ORIGINAL_DOTNET=$(type -p dotnet) || { echo "No 'dotnet' found" >&2; exit 1; }
161-
export ORIGINAL_DOTNET
162-
export NUGET_SOURCE=$dist_root/dotnet
160+
local NUGET_SOURCE=$dist_root/dotnet
163161

164162
if [ ! -d "$NUGET_SOURCE" ]; then
165163
echo "NuGet packages missing at $NUGET_SOURCE" >&2
166164
exit 1
167165
fi
166+
167+
mkdir -p $HOME/.nuget/NuGet
168+
if [ -f $HOME/.nuget/NuGet/NuGet.Config ]; then
169+
echo "⚠️ Saving previous NuGet.Config to $HOME/.nuget/NuGet/NuGet.Config.bak"
170+
mv $HOME/.nuget/NuGet/NuGet.Config $HOME/.nuget/NuGet/NuGet.Config.bak
171+
fi
172+
173+
trap clean_up_nuget_config EXIT
174+
175+
cat > $HOME/.nuget/NuGet/NuGet.Config <<EOF
176+
<?xml version="1.0" encoding="utf-8"?>
177+
<configuration>
178+
<packageSources>
179+
<add key="Locally Distributed Packages" value="${NUGET_SOURCE}" />
180+
<add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
181+
</packageSources>
182+
</configuration>
183+
EOF
184+
}
185+
186+
function clean_up_nuget_config() {
187+
log "Restoring NuGet configuration"
188+
if [ -f $HOME/.nuget/NuGet/NuGet.Config.bak ]; then
189+
log "-> Restoring $HOME/.nuget/NuGet/NuGet.Config from $HOME/.nuget/NuGet/NuGet.Config.bak"
190+
mv -f $HOME/.nuget/NuGet/NuGet.Config.bak $HOME/.nuget/NuGet/NuGet.Config
191+
else
192+
log "-> Removing $HOME/.nuget/NuGet/NuGet.Config"
193+
rm -f $HOME/.nuget/NuGet/NuGet.Config
194+
fi
168195
}
169196

170197
# pip_install REQUIREMENTS_FILE

packages/aws-cdk/test/integ/run-wrappers/dist/dotnet

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)