ci-source-build.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env bash
  2. #
  3. # This script is meant for testing source build by imitating some of the input parameters and conditions.
  4. #
  5. set -euo pipefail
  6. scriptroot="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  7. reporoot="$(dirname "$(dirname "$scriptroot")")"
  8. #
  9. # This commented out section is used for servicing branches
  10. #
  11. # For local development, make a backup copy of this file first
  12. # if [ ! -f "$reporoot/global.bak.json" ]; then
  13. # mv "$reporoot/global.json" "$reporoot/global.bak.json"
  14. # fi
  15. # Detect the current version of .NET Core installed
  16. # export SDK_VERSION=$(dotnet --version)
  17. # echo "The ambient version of .NET Core SDK version = $SDK_VERSION"
  18. # Update the global.json file to match the current .NET environment
  19. # cat "$reporoot/global.bak.json" | \
  20. # jq '.sdk.version=env.SDK_VERSION' | \
  21. # jq '.tools.dotnet=env.SDK_VERSION' | \
  22. # jq 'del(.tools.runtimes)' \
  23. # > "$reporoot/global.json"
  24. # Restore the original global.json file
  25. #trap "{
  26. # mv "$reporoot/global.bak.json" "$reporoot/global.json"
  27. #}" EXIT
  28. runtime_source_feed=''
  29. runtime_source_feed_key=''
  30. other_args=()
  31. #
  32. # Functions
  33. #
  34. __usage() {
  35. echo "Usage: $(basename "${BASH_SOURCE[0]}") [options] [[--] <Arguments>...]
  36. Arguments:
  37. <Arguments>... Arguments passed to the command. Variable number of arguments allowed.
  38. --runtime-source-feed Additional feed that can be used when downloading .NET runtimes and SDKs
  39. --runtime-source-feed-key Key for feed that can be used when downloading .NET runtimes and SDKs
  40. Description:
  41. This script is meant for testing source build by imitating some of the input parameters and conditions.
  42. "
  43. if [[ "${1:-}" != '--no-exit' ]]; then
  44. exit 2
  45. fi
  46. }
  47. __error() {
  48. echo -e "${RED}error: $*${RESET}" 1>&2
  49. }
  50. #
  51. # main
  52. #
  53. while [[ $# -gt 0 ]]; do
  54. opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
  55. case "$opt" in
  56. -\?|-h|-help)
  57. __usage --no-exit
  58. exit 0
  59. ;;
  60. -dotnet-runtime-source-feed|-dotnetruntimesourcefeed|-runtime_source_feed|-runtimesourcefeed)
  61. shift
  62. [ -z "${1:-}" ] && __error "Missing value for parameter --runtime-source-feed" && __usage
  63. runtime_source_feed="${1:-}"
  64. ;;
  65. -dotnet-runtime-source-feed-key|-dotnetruntimesourcefeedkey|-runtime_source_feed_key|-runtimesourcefeedkey)
  66. shift
  67. [ -z "${1:-}" ] && __error "Missing value for parameter --runtime-source-feed-key" && __usage
  68. runtime_source_feed_key="${1:-}"
  69. ;;
  70. *)
  71. other_args[${#other_args[*]}]="$1"
  72. ;;
  73. esac
  74. shift
  75. done
  76. # Set up additional runtime args
  77. runtime_feed_args=()
  78. if [ ! -z "$runtime_source_feed$runtime_source_feed_key" ]; then
  79. runtime_feed_args[${#runtime_feed_args[*]}]="-runtimesourcefeed"
  80. runtime_feed_args[${#runtime_feed_args[*]}]="$runtime_source_feed"
  81. runtime_feed_args[${#runtime_feed_args[*]}]="-runtimesourcefeedKey"
  82. runtime_feed_args[${#runtime_feed_args[*]}]="$runtime_source_feed_key"
  83. runtimeFeedArg="/p:DotNetRuntimeSourceFeed=$runtime_source_feed"
  84. runtimeFeedKeyArg="/p:DotNetRuntimeSourceFeedKey=$runtime_source_feed_key"
  85. runtime_feed_args[${#runtime_feed_args[*]}]=$runtimeFeedArg
  86. runtime_feed_args[${#runtime_feed_args[*]}]=$runtimeFeedKeyArg
  87. fi
  88. # Build repo tasks
  89. "$reporoot/eng/common/build.sh" --restore --build --ci --configuration Release /p:ProjectToBuild=$reporoot/eng/tools/RepoTasks/RepoTasks.csproj ${runtime_feed_args[@]+"${runtime_feed_args[@]}"}
  90. export DotNetBuildFromSource='true'
  91. # Build projects
  92. "$reporoot/eng/common/build.sh" --restore --build --ci --pack ${other_args[@]+"${other_args[@]}"} ${runtime_feed_args[@]+"${runtime_feed_args[@]}"}