Prerelease_Build.ps1 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # 設定 ASCII 藝術字的內容
  2. $asciiArt = @"
  3. _____ _____ ______ _____ ______ _ ______ _____ ______
  4. | __ \| __ \| ____| __ \| ____| | | ____| /\ / ____| ____|
  5. | |__) | |__) | |__ | |__) | |__ | | | |__ / \ | (___ | |__
  6. | ___/| _ /| __| | _ /| __| | | | __| / /\ \ \___ \| __|
  7. | | | | \ \| |____| | \ \| |____| |____| |____ / ____ \ ____) | |____
  8. |_| |_| \_\______|_| \_\______|______|______/_/ \_\_____/|______|
  9. "@
  10. # 顯示 ASCII 藝術字
  11. Write-Host $asciiArt
  12. #第一次建立專案請先設定ACR Name
  13. $registryname="evdevcontainerregistry"
  14. $fullregistryname="evdevcontainerregistry.azurecr.io"
  15. #第一次建立專案請先設定專案名稱
  16. $imagerepositoryname="server"
  17. #target tag can be {projectname}_RC or RC on pre-release stage
  18. $default_dev_prefix = "Docker_test_"
  19. $target_tag="Docker_RC"
  20. #檢查是否有尚未commit的更新
  21. $status = git status --porcelain
  22. if (-not $status) {
  23. Write-Output "All changes committed"
  24. } else {
  25. Write-Output "There are uncommitted changes"
  26. exit
  27. }
  28. #檢查remote是否有新commit未處理
  29. git fetch --tags -f
  30. $status = git status --porcelain -b
  31. if (($status -match "ahead") -or ($status -match "behind") -or ($status -match "gone") )
  32. {
  33. Write-Output "git branch not synced"
  34. exit
  35. }
  36. else {
  37. Write-Output "git branch is synced"
  38. }
  39. #podman acr登入
  40. Write-Host "ACR Login....."
  41. $token = az acr login --name $registryname --expose-token --output tsv --query accessToken
  42. $user = "00000000-0000-0000-0000-000000000000"
  43. podman login $fullregistryname -u $user -p $token
  44. $source_tag = Read-Host "Please type the source tag that you want to do RC."
  45. #預設跟Dev_build一樣
  46. if (-not $source_tag) {
  47. $username = az account show --query user.name
  48. $username = $username.TrimStart("""").Split('@')[0]
  49. $source_tag=$default_dev_prefix+$username
  50. }
  51. $sourcetag_response = Read-Host "Do you want to do the RC tag with $source_tag ?(Y/N)"
  52. while($sourcetag_response -eq "N")
  53. {
  54. $source_tag = Read-Host "Please type the source tag that you want to do RC."
  55. #預設跟Dev_build一樣
  56. if (-not $source_tag) {
  57. $source_tag=$default_dev_prefix+$username
  58. }
  59. $sourcetag_response = Read-Host "Do you want to do the RC tag with $source_tag ?(Y/N)"
  60. }
  61. $fulltag=$registryname+".azurecr.io/"+$imagerepositoryname+":"+$targettag
  62. $source_imagename = $imagerepositoryname+":"+$source_tag
  63. $target_imagename = $imagerepositoryname+":"+$target_tag
  64. $source_fulltag = $registryname+".azurecr.io/"+$imagerepositoryname+":"+$source_tag
  65. $target_fulltag = $registryname+".azurecr.io/"+$imagerepositoryname+":"+$target_tag
  66. $final_response = Read-Host "Final confirmation: Do you want to assign the RC tag name "$target_imagename" to the existing tag with "$source_imagename"?(Y/N)"
  67. if($final_response -eq "N")
  68. {
  69. write-host "Please restart the process."
  70. }
  71. else
  72. {
  73. #取得目前RC的message
  74. $rc_message = git tag -l --format='%(contents)' $target_tag
  75. if (!$rc_message)
  76. {
  77. $rc_message = ""
  78. }
  79. #暫存RC message
  80. $filePath = Join-Path -Path (Get-Location) -ChildPath "rc_message.txt"
  81. [System.IO.File]::WriteAllLines($filePath, $rc_message)
  82. #刪除遠端git的RC tag
  83. git push --delete origin $target_tag
  84. #刪除本地端git的RC tag
  85. git tag --delete $target_tag
  86. #標註目前commit為RC
  87. git tag -a $target_tag -F "rc_message.txt" --edit
  88. #更新遠端tag
  89. git push --follow-tags
  90. #刪除暫存檔
  91. Remove-Item "rc_message.txt"
  92. #解除image鎖定
  93. az acr repository update --name $registryname --image $target_imagename --delete-enabled true --write-enabled true
  94. podman pull $source_fulltag
  95. podman image tag $source_fulltag $target_fulltag
  96. podman push $target_fulltag
  97. #鎖定image
  98. az acr repository update --name $registryname --image $target_imagename --delete-enabled false --write-enabled false
  99. }