Skip to content

Commit 3649790

Browse files
committed
Optimize the NuGet script
1 parent bad7da7 commit 3649790

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

scripts/deploy_nuget.sh

+41-16
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,57 @@ set -ev
33

44
TAG=$1
55
NUGET_API_KEY=$2
6-
VERSION=`echo ${TAG} | cut -b 2-`
6+
VERSION=$(echo ${TAG} | cut -b 2-)
77

8-
src_path=src
9-
contract_path=contract
10-
build_output=/tmp/aelf-build
8+
# Define paths and directories
9+
src_path="src"
10+
contract_path="contract"
11+
build_output="/tmp/aelf-build"
1112

13+
# Clean up the temporary build directory if it exists
1214
if [[ -d ${build_output} ]]; then
1315
rm -rf ${build_output}
1416
fi
1517

18+
# Restore project dependencies
1619
dotnet restore AElf.All.sln
1720

18-
for path in ${src_path} ${contract_path} ;
19-
do
21+
# ---- Phase 1: Build all projects ----
22+
echo "=== Starting build phase ==="
23+
for path in ${src_path} ${contract_path}; do
2024
cd ${path}
21-
echo '---- build '${path}
22-
23-
for name in `ls -lh | grep ^d | grep AElf | grep -v Tests | awk '{print $NF}'`;
24-
do
25-
if [[ -f ${name}/${name}.csproj ]] && [[ 1 -eq $(grep -c "GeneratePackageOnBuild" ${name}/${name}.csproj) ]];then
26-
echo ${name}/${name}.csproj
27-
dotnet build ${name}/${name}.csproj /clp:ErrorsOnly --configuration Release -P:Version=${VERSION} -P:Authors=AElf -o ${build_output}
25+
echo "---- Building projects in path: ${path} ----"
26+
for name in $(ls -lh | grep ^d | grep AElf | grep -v Tests | awk '{print $NF}'); do
27+
# Check if the project has a .csproj file and if it is configured to generate NuGet packages
28+
if [[ -f ${name}/${name}.csproj ]] && [[ $(grep -c "GeneratePackageOnBuild" ${name}/${name}.csproj) -eq 1 ]]; then
29+
echo "Building project: ${name}/${name}.csproj"
30+
dotnet build ${name}/${name}.csproj --configuration Release \
31+
-P:Version=${VERSION} -P:Authors=AElf -o ${build_output} /clp:ErrorsOnly
32+
fi
33+
done
34+
cd ../
35+
done
2836

29-
echo `ls ${build_output}/${name}.${VERSION}.nupkg`
30-
dotnet nuget push ${build_output}/${name}.${VERSION}.nupkg -k ${NUGET_API_KEY} -s https://api.nuget.org/v3/index.json --skip-duplicate
37+
# ---- Phase 2: Push NuGet packages ----
38+
echo "=== Starting push phase ==="
39+
for path in ${src_path} ${contract_path}; do
40+
cd ${path}
41+
echo "---- Pushing NuGet packages in path: ${path} ----"
42+
for name in $(ls -lh | grep ^d | grep AElf | grep -v Tests | awk '{print $NF}'); do
43+
# Check if the .nupkg file exists and push it to NuGet if it does
44+
if [[ -f ${name}/${name}.csproj ]] && [[ $(grep -c "GeneratePackageOnBuild" ${name}/${name}.csproj) -eq 1 ]]; then
45+
PACKAGE_PATH="${build_output}/${name}.${VERSION}.nupkg"
46+
if [[ -f ${PACKAGE_PATH} ]]; then
47+
echo "Pushing package: ${PACKAGE_PATH}"
48+
dotnet nuget push ${PACKAGE_PATH} -k ${NUGET_API_KEY} \
49+
-s https://api.nuget.org/v3/index.json --skip-duplicate
50+
else
51+
echo "Error: Package not found at ${PACKAGE_PATH}"
52+
exit 1
53+
fi
3154
fi
3255
done
3356
cd ../
34-
done
57+
done
58+
59+
echo "=== All tasks completed successfully! ==="

0 commit comments

Comments
 (0)