Skip to content

Commit 4b3f15d

Browse files
author
Chris Maunder
committed
Fixes for loading env vars from .env / checks for .NET
1 parent 9f3ccc8 commit 4b3f15d

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

devops/build/create_packages.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,21 @@ while [[ $# -gt 0 ]]; do
114114
done
115115

116116
# Load vars in .env. This may update things like dotNetTarget
117-
cat "${rootDirPath}/.env" | xargs
117+
if [ -f ${rootDirPath}/.env ]; then
118+
# Export each line from the .env file
119+
while IFS='=' read -r key value; do
120+
# Ignore lines starting with `#` (comments) and empty lines
121+
if [[ ! "$key" =~ ^# ]] && [[ -n "$key" ]]; then
122+
# Trim any surrounding whitespace
123+
key=$(echo $key | xargs)
124+
value=$(echo $value | xargs)
125+
export "$key=$value"
126+
fi
127+
done < ${rootDirPath}/.env
128+
else
129+
echo "${rootDirPath}/.env file not found"
130+
# exit 1
131+
fi
118132

119133
# Standard output may be used as a return value in the functions. Expose stream
120134
# 3 so we can do 'echo "Hello, World!" >&3' within these functions for debugging

src/scripts/utils.sh

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,17 @@ function getDotNetVersion() {
589589
do
590590
if [[ ${line} == *'Microsoft.NETCore.App '* ]]; then
591591
dotnet_version=$(echo "$line}" | cut -d ' ' -f 2)
592+
# echo "GET: Found .NET runtime $dotnet_version" >&3
593+
592594
current_comparison=$(versionCompare $dotnet_version $highestDotNetVersion)
595+
# echo "GET: current compare ${comparison}, new compare ${current_comparison}" >&3
593596

594-
if (( $current_comparison > $comparison )); then
597+
if (( $current_comparison >= $comparison )); then
595598
highestDotNetVersion="$dotnet_version"
596599
comparison=$current_comparison
600+
# echo "GET: Found new highest .NET runtime $highestDotNetVersion" >&3
601+
# else
602+
# echo "GET: Found $dotnet_version runtime, which is not higher than $highestDotNetVersion" >&3
597603
fi
598604
fi
599605
done <<< "$(dotnet --list-runtimes)"
@@ -629,7 +635,7 @@ function setupDotNet () {
629635

630636
write "Checking for .NET ${requestedNetVersion}..."
631637

632-
currentDotNetVersion="(None)"
638+
highestDotNetVersion="(None)"
633639
comparison=-1
634640
haveRequested=false
635641

@@ -645,13 +651,18 @@ function setupDotNet () {
645651
dotnet_version=$(echo "$line}" | cut -d ' ' -f 1)
646652
dotnet_major_version=$(echo "$dotnet_version}" | cut -d '.' -f 1)
647653

654+
# echo "SET: Found .NET SDK $dotnet_version" >&3
655+
648656
# Let's only compare major versions
649657
# current_comparison=$(versionCompare $dotnet_version $requestedNetVersion)
650658
current_comparison=$(versionCompare $dotnet_major_version $requestedNetMajorVersion)
651659

652660
if (( $current_comparison >= $comparison )); then
653-
currentDotNetVersion="$dotnet_version"
661+
highestDotNetVersion="$dotnet_version"
654662
comparison=$current_comparison
663+
# echo "SET: Found new highest .NET SDK $highestDotNetVersion" >&3
664+
# else
665+
# echo "SET: Found $dotnet_version SDK, which is not higher than $requestedNetMajorVersion" >&3
655666
fi
656667

657668
# We found the one we're after
@@ -675,14 +686,20 @@ function setupDotNet () {
675686

676687
dotnet_version=$(echo "$line}" | cut -d ' ' -f 2)
677688
dotnet_major_version=$(echo "$dotnet_version}" | cut -d '.' -f 1)
689+
# echo "SET: Found .NET runtime $dotnet_version" >&3
678690

679691
# Let's only compare major versions
680692
# current_comparison=$(versionCompare $dotnet_version $requestedNetVersion)
681693
current_comparison=$(versionCompare $dotnet_major_version $requestedNetMajorVersion)
694+
# echo "SET: current compare ${comparison}, new compare ${current_comparison}" >&3
682695

683696
if (( $current_comparison >= $comparison )); then
684-
currentDotNetVersion="$dotnet_version"
697+
highestDotNetVersion="$dotnet_version"
685698
comparison=$current_comparison
699+
700+
# echo "SET: Found new highest .NET runtime $highestDotNetVersion" >&3
701+
# else
702+
# echo "SET: Found $dotnet_version runtime, which is not higher than $requestedNetMajorVersion" >&3
686703
fi
687704

688705
# We found the one we're after
@@ -696,18 +713,18 @@ function setupDotNet () {
696713

697714
mustInstall="false"
698715
if [ "$haveRequested" == true ]; then
699-
writeLine "All good. .NET ${requestedType} is ${currentDotNetVersion}" $color_success
716+
writeLine "All good. .NET ${requestedType} is ${highestDotNetVersion}" $color_success
700717
elif (( $comparison == 0 )); then
701-
writeLine "All good. .NET ${requestedType} is ${currentDotNetVersion}" $color_success
718+
writeLine "All good. .NET ${requestedType} is ${highestDotNetVersion}" $color_success
702719
elif (( $comparison == -1 )); then
703-
writeLine "Upgrading: .NET ${requestedType} is ${currentDotNetVersion}. Upgrading to ${requestedNetVersion}" $color_warn
720+
writeLine "Upgrading: .NET ${requestedType} is ${highestDotNetVersion}. Upgrading to ${requestedNetVersion}" $color_warn
704721
mustInstall=true
705-
else # (( $comparison == 1 )), meaning currentDotNetVersion > requestedNetVersion
722+
else # (( $comparison == 1 )), meaning highestDotNetVersion > requestedNetVersion
706723
if [ "$requestedType" = "sdk" ]; then
707724
writeLine "Installing .NET ${requestedType} ${requestedNetVersion}" $color_warn
708725
mustInstall=true
709726
else
710-
writeLine "All good. .NET ${requestedType} is ${currentDotNetVersion}" $color_success
727+
writeLine "All good. .NET ${requestedType} is ${highestDotNetVersion}" $color_success
711728
fi
712729
fi
713730

@@ -722,8 +739,7 @@ function setupDotNet () {
722739
dotnet_path="/opt/dotnet"
723740
elif [ "$os" = "linux" ]; then
724741
dotnet_path="/usr/lib/dotnet/"
725-
else
726-
# dotnet_path="/usr/lib/dotnet/"
742+
else # macOS x64
727743
# dotnet_path="~/.dotnet/"
728744
dotnet_path="/usr/local/share/dotnet/"
729745
fi

src/setup.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,21 @@ installScriptsDirPath="${rootDirPath}/devops/install"
316316
utilsScript="${utilsScriptsDirPath}/utils.sh"
317317

318318
# Load vars in .env. This may update things like dotNetTarget
319-
cat "${rootDirPath}/.env" | xargs
320-
quit 0
319+
if [ -f ${rootDirPath}/.env ]; then
320+
# Export each line from the .env file
321+
while IFS='=' read -r key value; do
322+
# Ignore lines starting with `#` (comments) and empty lines
323+
if [[ ! "$key" =~ ^# ]] && [[ -n "$key" ]]; then
324+
# Trim any surrounding whitespace
325+
key=$(echo $key | xargs)
326+
value=$(echo $value | xargs)
327+
export "$key=$value"
328+
fi
329+
done < ${rootDirPath}/.env
330+
else
331+
echo "${rootDirPath}/.env file not found"
332+
# exit 1
333+
fi
321334

322335
# Check if we're in a SSH session. If so it means we need to avoid anything GUI
323336
inSSH=false

0 commit comments

Comments
 (0)