Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bash version of updateAssemblyInfo script #2211

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions updateAssemblyInfo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
set -euo pipefail

scriptroot=$(cd -P "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)

packageType=${1:-preview}

date=$(date '+%y%m%d%H%M%S')
# Formats the date by replacing the 4-digit year with a 2-digit value and then subtract 19
dateTimeStamp=$(echo $((10#${date:0:2}-19)))${date:2}

commitSha=$(git rev-parse HEAD)

assemblyVersion=$(sed -n 's/.*<assemblyVersion>\([^<]*\)<.*/\1/p' $PWD/buildConfiguration.xml)
assemblyFileVersion="$assemblyVersion.${dateTimeStamp::-6}" # Trim minutes/seconds
assemblyInformationalVersion="$assemblyVersion.$dateTimeStamp.$commitSha"

echo "assemblyVersion: $assemblyVersion"
echo "assemblyFileVersion: $assemblyFileVersion"
echo "assemblyInformationalVersion: $assemblyInformationalVersion"

nugetSuffix=$(sed -n 's/.*<nugetSuffix>\([^<]*\)<.*/\1/p' $PWD/buildConfiguration.xml)
if [ "$packageType" = "release" ]
then
versionSuffix=""
else
versionSuffix="$nugetSuffix-$dateTimeStamp"
fi

echo "nugetSuffix: $nugetSuffix"

versionPath="$PWD/build/version.props"
version=$(cat $versionPath)
version=$(echo "$version" | sed "s|<VersionPrefix>.*</VersionPrefix>|<VersionPrefix>$assemblyVersion</VersionPrefix>|")
version=$(echo "$version" | sed "s|<VersionSuffix>.*</VersionSuffix>|<VersionSuffix>$versionSuffix</VersionSuffix>|")
echo "$version" > $versionPath

projects=$(sed -n '/<src>/,/<\/src>/p' $PWD/buildConfiguration.xml | sed -n 's/.*name="\([^"]*\)".*/\1/p')

for project in $projects; do
name="$project"
assemblyInfoPath="$PWD/src/$name/Properties/AssemblyInfo.cs"
echo "assemblyInfoPath: $assemblyInfoPath"

assemblyInfo=$(cat $assemblyInfoPath)
assemblyInfo=$(echo "$assemblyInfo" | sed "s|AssemblyVersion.*|AssemblyVersion(\"$assemblyVersion\")]|")
assemblyInfo=$(echo "$assemblyInfo" | sed "s|AssemblyFileVersion.*|AssemblyFileVersion(\"$assemblyFileVersion\")]|")
assemblyInfo=$(echo "$assemblyInfo" | sed "s|AssemblyInformationalVersion.*|AssemblyInformationalVersion(\"$assemblyInformationalVersion\")]|")
echo "$assemblyInfo" > $assemblyInfoPath
done