release.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 --repo "${ASSETS_REPOSITORY}" "${RELEASE_VERSION}" 2>&1 ) =~ "release not found" ]]; then
  12. echo "Creating release '${RELEASE_VERSION}'"
  13. if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
  14. NOTES="update vscode to [${MS_COMMIT}](https://github.com/microsoft/vscode/tree/${MS_COMMIT})"
  15. gh release create "${RELEASE_VERSION}" --repo "${ASSETS_REPOSITORY}" --title "${RELEASE_VERSION}" --notes "${NOTES}"
  16. else
  17. gh release create "${RELEASE_VERSION}" --repo "${ASSETS_REPOSITORY}" --title "${RELEASE_VERSION}" --generate-notes
  18. . ./utils.sh
  19. RELEASE_NOTES=$( gh release view "${RELEASE_VERSION}" --json "body" --jq ".body" )
  20. replace "s|MS_TAG_SHORT|$( echo "${MS_TAG//./_}" | cut -d'_' -f 1,2 )|" release_notes.txt
  21. replace "s|MS_TAG|${MS_TAG}|" release_notes.txt
  22. replace "s|RELEASE_VERSION|${RELEASE_VERSION}|g" release_notes.txt
  23. replace "s|RELEASE_NOTES|${RELEASE_NOTES//$'\n'/\\n}|" release_notes.txt
  24. gh release edit "${RELEASE_VERSION}" --notes-file release_notes.txt
  25. fi
  26. fi
  27. cd assets
  28. set +e
  29. for FILE in *; do
  30. if [[ -f "${FILE}" ]] && [[ "${FILE}" != *.sha1 ]] && [[ "${FILE}" != *.sha256 ]]; then
  31. echo "::group::Uploading '${FILE}' at $( date "+%T" )"
  32. gh release upload --repo "${ASSETS_REPOSITORY}" "${RELEASE_VERSION}" "${FILE}" "${FILE}.sha1" "${FILE}.sha256"
  33. EXIT_STATUS=$?
  34. echo "exit: ${EXIT_STATUS}"
  35. if (( "${EXIT_STATUS}" )); then
  36. for (( i=0; i<10; i++ )); do
  37. github-release delete --owner "${REPOSITORY_OWNER}" --repo "${REPOSITORY_NAME}" --tag "${RELEASE_VERSION}" "${FILE}" "${FILE}.sha1" "${FILE}.sha256"
  38. sleep $(( 15 * (i + 1)))
  39. echo "RE-Uploading '${FILE}' at $( date "+%T" )"
  40. gh release upload --repo "${ASSETS_REPOSITORY}" "${RELEASE_VERSION}" "${FILE}" "${FILE}.sha1" "${FILE}.sha256"
  41. EXIT_STATUS=$?
  42. echo "exit: ${EXIT_STATUS}"
  43. if ! (( "${EXIT_STATUS}" )); then
  44. break
  45. fi
  46. done
  47. echo "exit: ${EXIT_STATUS}"
  48. if (( "${EXIT_STATUS}" )); then
  49. echo "'${FILE}' hasn't been uploaded!"
  50. github-release delete --owner "${REPOSITORY_OWNER}" --repo "${REPOSITORY_NAME}" --tag "${RELEASE_VERSION}" "${FILE}" "${FILE}.sha1" "${FILE}.sha256"
  51. exit 1
  52. fi
  53. fi
  54. echo "::endgroup::"
  55. fi
  56. done
  57. cd ..