release.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env bash
  2. # shellcheck disable=SC1091
  3. set -ex
  4. if [[ -z "${GH_TOKEN}" ]] && [[ -z "${GITHUB_TOKEN}" ]] && [[ -z "${GH_ENTERPRISE_TOKEN}" ]] && [[ -z "${GITHUB_ENTERPRISE_TOKEN}" ]]; then
  5. echo "Will not release because no GITHUB_TOKEN defined"
  6. exit
  7. fi
  8. REPOSITORY_OWNER="${ASSETS_REPOSITORY/\/*/}"
  9. REPOSITORY_NAME="${ASSETS_REPOSITORY/*\//}"
  10. npm install -g github-release-cli
  11. if [[ $( gh release view "${RELEASE_VERSION}" --repo "${ASSETS_REPOSITORY}" 2>&1 ) =~ "release not found" ]]; then
  12. echo "Creating release '${RELEASE_VERSION}'"
  13. . ./utils.sh
  14. APP_NAME_LC="$( echo "${APP_NAME}" | awk '{print tolower($0)}' )"
  15. VERSION="${RELEASE_VERSION%-insider}"
  16. if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
  17. NOTES="update vscode to [${MS_COMMIT}](https://github.com/microsoft/vscode/tree/${MS_COMMIT})"
  18. replace "s|@@APP_NAME@@|${APP_NAME}|g" release_notes.md
  19. replace "s|@@APP_NAME_LC@@|${APP_NAME_LC}|g" release_notes.md
  20. replace "s|@@APP_NAME_QUALITY@@|${APP_NAME}-Insiders|g" release_notes.md
  21. replace "s|@@ASSETS_REPOSITORY@@|${ASSETS_REPOSITORY}|g" release_notes.md
  22. replace "s|@@BINARY_NAME@@|${BINARY_NAME}|g" release_notes.md
  23. replace "s|@@MS_TAG@@|${MS_COMMIT}|g" release_notes.md
  24. replace "s|@@MS_URL@@|https://github.com/microsoft/vscode/tree/${MS_COMMIT}|g" release_notes.md
  25. replace "s|@@QUALITY@@|-insider|g" release_notes.md
  26. replace "s|@@RELEASE_NOTES@@||g" release_notes.md
  27. replace "s|@@VERSION@@|${VERSION}|g" release_notes.md
  28. gh release create "${RELEASE_VERSION}" --repo "${ASSETS_REPOSITORY}" --title "${RELEASE_VERSION}" --notes-file release_notes.md
  29. else
  30. gh release create "${RELEASE_VERSION}" --repo "${ASSETS_REPOSITORY}" --title "${RELEASE_VERSION}" --generate-notes
  31. RELEASE_NOTES=$( gh release view "${RELEASE_VERSION}" --repo "${ASSETS_REPOSITORY}" --json "body" --jq ".body" )
  32. replace "s|@@APP_NAME@@|${APP_NAME}|g" release_notes.md
  33. replace "s|@@APP_NAME_LC@@|${APP_NAME_LC}|g" release_notes.md
  34. replace "s|@@APP_NAME_QUALITY@@|${APP_NAME}|g" release_notes.md
  35. replace "s|@@ASSETS_REPOSITORY@@|${ASSETS_REPOSITORY}|g" release_notes.md
  36. replace "s|@@BINARY_NAME@@|${BINARY_NAME}|g" release_notes.md
  37. replace "s|@@MS_TAG@@|${MS_TAG}|g" release_notes.md
  38. replace "s|@@MS_URL@@|https://code.visualstudio.com/updates/v$( echo "${MS_TAG//./_}" | cut -d'_' -f 1,2 )|g" release_notes.md
  39. replace "s|@@QUALITY@@||g" release_notes.md
  40. replace "s|@@RELEASE_NOTES@@|${RELEASE_NOTES//$'\n'/\\n}|g" release_notes.md
  41. replace "s|@@VERSION@@|${VERSION}|g" release_notes.md
  42. gh release edit "${RELEASE_VERSION}" --repo "${ASSETS_REPOSITORY}" --notes-file release_notes.md
  43. fi
  44. fi
  45. cd assets
  46. set +e
  47. for FILE in *; do
  48. if [[ -f "${FILE}" ]] && [[ "${FILE}" != *.sha1 ]] && [[ "${FILE}" != *.sha256 ]]; then
  49. echo "::group::Uploading '${FILE}' at $( date "+%T" )"
  50. gh release upload --repo "${ASSETS_REPOSITORY}" "${RELEASE_VERSION}" "${FILE}" "${FILE}.sha1" "${FILE}.sha256"
  51. EXIT_STATUS=$?
  52. echo "exit: ${EXIT_STATUS}"
  53. if (( "${EXIT_STATUS}" )); then
  54. for (( i=0; i<10; i++ )); do
  55. github-release delete --owner "${REPOSITORY_OWNER}" --repo "${REPOSITORY_NAME}" --tag "${RELEASE_VERSION}" "${FILE}" "${FILE}.sha1" "${FILE}.sha256"
  56. sleep $(( 15 * (i + 1)))
  57. echo "RE-Uploading '${FILE}' at $( date "+%T" )"
  58. gh release upload --repo "${ASSETS_REPOSITORY}" "${RELEASE_VERSION}" "${FILE}" "${FILE}.sha1" "${FILE}.sha256"
  59. EXIT_STATUS=$?
  60. echo "exit: ${EXIT_STATUS}"
  61. if ! (( "${EXIT_STATUS}" )); then
  62. break
  63. fi
  64. done
  65. echo "exit: ${EXIT_STATUS}"
  66. if (( "${EXIT_STATUS}" )); then
  67. echo "'${FILE}' hasn't been uploaded!"
  68. github-release delete --owner "${REPOSITORY_OWNER}" --repo "${REPOSITORY_NAME}" --tag "${RELEASE_VERSION}" "${FILE}" "${FILE}.sha1" "${FILE}.sha256"
  69. exit 1
  70. fi
  71. fi
  72. echo "::endgroup::"
  73. fi
  74. done
  75. cd ..