|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -#!/bin/bash |
4 | | - |
5 | 3 | POSITIONAL_ARGS=() |
6 | 4 |
|
7 | 5 | while [[ $# -gt 0 ]]; do |
|
34 | 32 |
|
35 | 33 | set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters |
36 | 34 |
|
37 | | -echo "file = ${file}" |
| 35 | +if [ -z "$file" ]; then |
| 36 | + echo "ERROR: Parameter file (-f|--file) not provided" |
| 37 | + exit 1; |
| 38 | +elif [ ! -f "$file" ]; then |
| 39 | + echo "ERROR: file ${file} not found" |
| 40 | + exit 1; |
| 41 | +fi |
| 42 | + |
| 43 | +if [ -n "$(cat $file | grep -i "<IsPackable>false</IsPackable>")" ]; then |
| 44 | + echo "Project is marked as NOT packable - skipping." |
| 45 | + exit 0; |
| 46 | +fi |
| 47 | + |
| 48 | +if [ -z "$propsFile" ]; then |
| 49 | + echo "ERROR: Parameter propsFile (-f|--file) not provided" |
| 50 | + exit 1; |
| 51 | +elif [ ! -f "$propsFile" ]; then |
| 52 | + echo "ERROR: propsFile ${file} not found" |
| 53 | + exit 1; |
| 54 | +fi |
| 55 | + |
| 56 | +if [ -z "$buildAndRevisionNumber" ]; then |
| 57 | + echo "ERROR: Parameter buildAndRevisionNumber (-b|--buildAndRevisionNumber) not provided" |
| 58 | + exit 1; |
| 59 | +fi |
| 60 | + |
| 61 | +propsVersionString=$(cat $propsFile | grep -i "<Version>"); |
| 62 | +regex="<Version>([0-9.]*)<\/Version>" |
| 63 | +if [[ $propsVersionString =~ $regex ]]; then |
| 64 | + propsVersion=${BASH_REMATCH[1]} |
| 65 | +else |
| 66 | + echo "ERROR: Version tag not found in propsFile" |
| 67 | + exit 1; |
| 68 | +fi |
| 69 | + |
| 70 | +if [ -z "$propsVersion" ]; then |
| 71 | + echo "ERROR: Version tag not found in propsFile" |
| 72 | + exit 1; |
| 73 | +elif [[ ! "$propsVersion" =~ ^0.* ]]; then |
| 74 | + echo "ERROR: Version expected to start with 0. Actual: ${propsVersion}" |
| 75 | + exit 1; |
| 76 | +fi |
| 77 | + |
| 78 | +fullVersionString="${propsVersion}.${buildAndRevisionNumber}-preview" |
| 79 | + |
| 80 | +if [[ ! "$fullVersionString" =~ ^0.* ]]; then |
| 81 | + echo "ERROR: Version expected to start with 0. Actual: ${fullVersionString}" |
| 82 | + exit 1; |
| 83 | +fi |
| 84 | + |
| 85 | +echo "==== Project: ${file} ===="; |
| 86 | +echo "propsFile = ${propsFile}" |
38 | 87 | echo "buildAndRevisionNumber = ${buildAndRevisionNumber}" |
| 88 | +echo "version prefix from propsFile = ${propsVersion}" |
| 89 | +echo "full version string: ${fullVersionString}" |
39 | 90 |
|
40 | | -echo "====${file}===="; |
41 | | -versionString=$(cat $file | grep -i "<Version>"); |
42 | | -if [ -n "$versionString" ]; then |
| 91 | +versionInProj=$(cat $file | grep -i "<Version>"); |
| 92 | +if [ -n "$versionInProj" ]; then |
| 93 | + # Version tag already exists in the csproj. Let's replace it. |
43 | 94 | echo "Updating version tag..." |
44 | | - content=$(cat $file | sed --expression="s/<Version>\([0-9]*.[0-9]*\)<\/Version>/<Version>\1.$buildAndRevisionNumber-preview<\/Version>/g"); |
| 95 | + content=$(cat $file | sed --expression="s/<Version>\([0-9]*.[0-9]*\)<\/Version>/<Version>$fullVersionString<\/Version>/g"); |
45 | 96 | else |
46 | | - if [ -n "$(cat $file | grep -i "<IsPackable>false</IsPackable>")" ]; then |
47 | | - echo "Project is marked as NOT packable - skipping." |
48 | | - continue; |
49 | | - fi |
| 97 | + # Version tag not found in the csproj. Let's add it. |
50 | 98 | echo "Project is packable - adding version tag..." |
51 | | - content=$(cat $file | sed --expression="s/<\/Project>/<PropertyGroup><Version>1.0.$buildAndRevisionNumber-preview<\/Version><\/PropertyGroup><\/Project>/g"); |
| 99 | + content=$(cat $file | sed --expression="s/<\/Project>/<PropertyGroup><Version>$fullVersionString<\/Version><\/PropertyGroup><\/Project>/g"); |
52 | 100 | fi |
53 | 101 |
|
54 | 102 | if [ $? -ne 0 ]; then exit 1; fi |
55 | 103 | echo "$content" && echo "$content" > $file; |
56 | 104 | if [ $? -ne 0 ]; then exit 1; fi |
| 105 | + |
| 106 | +echo "DONE"; |
| 107 | +echo ""; |
0 commit comments