Skip to content

Commit

Permalink
Optimize the NuGet script
Browse files Browse the repository at this point in the history
  • Loading branch information
chopin-fan committed Jan 12, 2025
1 parent bad7da7 commit 3649790
Showing 1 changed file with 41 additions and 16 deletions.
57 changes: 41 additions & 16 deletions scripts/deploy_nuget.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,57 @@ set -ev

TAG=$1
NUGET_API_KEY=$2
VERSION=`echo ${TAG} | cut -b 2-`
VERSION=$(echo ${TAG} | cut -b 2-)

src_path=src
contract_path=contract
build_output=/tmp/aelf-build
# Define paths and directories
src_path="src"
contract_path="contract"
build_output="/tmp/aelf-build"

# Clean up the temporary build directory if it exists
if [[ -d ${build_output} ]]; then
rm -rf ${build_output}
fi

# Restore project dependencies
dotnet restore AElf.All.sln

for path in ${src_path} ${contract_path} ;
do
# ---- Phase 1: Build all projects ----
echo "=== Starting build phase ==="
for path in ${src_path} ${contract_path}; do
cd ${path}
echo '---- build '${path}

for name in `ls -lh | grep ^d | grep AElf | grep -v Tests | awk '{print $NF}'`;
do
if [[ -f ${name}/${name}.csproj ]] && [[ 1 -eq $(grep -c "GeneratePackageOnBuild" ${name}/${name}.csproj) ]];then
echo ${name}/${name}.csproj
dotnet build ${name}/${name}.csproj /clp:ErrorsOnly --configuration Release -P:Version=${VERSION} -P:Authors=AElf -o ${build_output}
echo "---- Building projects in path: ${path} ----"
for name in $(ls -lh | grep ^d | grep AElf | grep -v Tests | awk '{print $NF}'); do
# Check if the project has a .csproj file and if it is configured to generate NuGet packages
if [[ -f ${name}/${name}.csproj ]] && [[ $(grep -c "GeneratePackageOnBuild" ${name}/${name}.csproj) -eq 1 ]]; then
echo "Building project: ${name}/${name}.csproj"
dotnet build ${name}/${name}.csproj --configuration Release \
-P:Version=${VERSION} -P:Authors=AElf -o ${build_output} /clp:ErrorsOnly
fi
done
cd ../
done

echo `ls ${build_output}/${name}.${VERSION}.nupkg`
dotnet nuget push ${build_output}/${name}.${VERSION}.nupkg -k ${NUGET_API_KEY} -s https://api.nuget.org/v3/index.json --skip-duplicate
# ---- Phase 2: Push NuGet packages ----
echo "=== Starting push phase ==="
for path in ${src_path} ${contract_path}; do
cd ${path}
echo "---- Pushing NuGet packages in path: ${path} ----"
for name in $(ls -lh | grep ^d | grep AElf | grep -v Tests | awk '{print $NF}'); do
# Check if the .nupkg file exists and push it to NuGet if it does
if [[ -f ${name}/${name}.csproj ]] && [[ $(grep -c "GeneratePackageOnBuild" ${name}/${name}.csproj) -eq 1 ]]; then
PACKAGE_PATH="${build_output}/${name}.${VERSION}.nupkg"
if [[ -f ${PACKAGE_PATH} ]]; then
echo "Pushing package: ${PACKAGE_PATH}"
dotnet nuget push ${PACKAGE_PATH} -k ${NUGET_API_KEY} \
-s https://api.nuget.org/v3/index.json --skip-duplicate
else
echo "Error: Package not found at ${PACKAGE_PATH}"
exit 1
fi
fi
done
cd ../
done
done

echo "=== All tasks completed successfully! ==="

0 comments on commit 3649790

Please sign in to comment.