Release_Build.ps1 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #來源TAG
  18. $source_tag="Docker_RC"
  19. $targetTagPrefix="Docker_v"
  20. #檢查remote是否有新commit未處理
  21. git fetch --tags -f
  22. $status = git status --porcelain -b
  23. if (($status -match "ahead") -or ($status -match "behind") -or ($status -match "gone") )
  24. {
  25. Write-Output "git branch not synced"
  26. exit
  27. }
  28. else {
  29. Write-Output "git branch is synced"
  30. }
  31. #podman acr登入
  32. Write-Host "ACR Login....."
  33. $token = az acr login --name $registryname --expose-token --output tsv --query accessToken
  34. $user = "00000000-0000-0000-0000-000000000000"
  35. podman login $fullregistryname -u $user -p $token
  36. $sourcetag_response = Read-Host "Do you want to do release tag with $source_tag ?(Y/N)"
  37. while($sourcetag_response -ne "Y")
  38. {
  39. $source_tag = Read-Host "Please type the source tag that you want to do newtag."
  40. $sourcetag_response = Read-Host "Do you want to do release tag with $source_tag ?(Y/N)"
  41. }
  42. $target_tag = Read-Host "Please type the release tag version (make sure that the same as tagname from azure devops)."
  43. $target_tag = $targetTagPrefix + $target_tag
  44. $targettag_response = Read-Host "Please confirm the release tag $target_tag (Y/N)."
  45. while($targettag_response -ne "Y")
  46. {
  47. $target_tag = Read-Host "Please type the release tag version (make sure that the same as tagname from azure devops)."
  48. $target_tag = $targetTagPrefix + $target_tag
  49. $targettag_response = Read-Host "Please confirm the release tag $target_tag (Y/N)."
  50. }
  51. $fulltag=$registryname+".azurecr.io/"+$imagerepositoryname+":"+$targettag
  52. $source_imagename = $imagerepositoryname+":"+$source_tag
  53. $target_imagename = $imagerepositoryname+":"+$target_tag
  54. $source_fulltag = $registryname+".azurecr.io/"+$imagerepositoryname+":"+$source_tag
  55. $target_fulltag = $registryname+".azurecr.io/"+$imagerepositoryname+":"+$target_tag
  56. $final_response = Read-Host "Final confirmation: Do you want to assign the new tag name "$target_imagename" to the existing tag with "$source_imagename"?(Y/N)"
  57. if($final_response -ne "Y")
  58. {
  59. write-host "Please restart the process."
  60. }
  61. else
  62. {
  63. #取得目前RC的message
  64. $rc_message = git tag -l --format='%(contents)' $source_tag
  65. if ($status -match "unknown revision or path not in the working tree")
  66. {
  67. Write-Host "source tag missing"
  68. exit
  69. }
  70. #暫存RC message
  71. $filePath = Join-Path -Path (Get-Location) -ChildPath "rc_message.txt"
  72. [System.IO.File]::WriteAllLines($filePath, $rc_message)
  73. #標註RC為新的tag
  74. git tag -a $target_tag -F "rc_message.txt" $source_tag
  75. #更新遠端tag
  76. git push --follow-tags
  77. #刪除暫存檔
  78. Remove-Item "rc_message.txt"
  79. podman pull $source_fulltag
  80. podman image tag $source_fulltag $target_fulltag
  81. podman push $target_fulltag
  82. #鎖定image
  83. az acr repository update --name $registryname --image $target_imagename --delete-enabled false --write-enabled false
  84. }