release.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env bash
  2. # shellcheck disable=SC1091
  3. set -e
  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. . ./utils.sh
  18. replace "s|MS_TAG_SHORT|$( echo "${MS_TAG//./_}" | cut -d'_' -f 1,2 )|" release_notes.txt
  19. replace "s|MS_TAG|${MS_TAG}|" release_notes.txt
  20. replace "s|RELEASE_VERSION|${RELEASE_VERSION}|" release_notes.txt
  21. gh release create "${RELEASE_VERSION}" --repo "${ASSETS_REPOSITORY}" --title "${RELEASE_VERSION}" --generate-notes --notes-start-tag RELEASE_NOTES --notes-file release_notes.txt
  22. fi
  23. fi
  24. cd assets
  25. set +e
  26. for FILE in *; do
  27. if [[ -f "${FILE}" ]] && [[ "${FILE}" != *.sha1 ]] && [[ "${FILE}" != *.sha256 ]]; then
  28. echo "::group::Uploading '${FILE}' at $( date "+%T" )"
  29. gh release upload --repo "${ASSETS_REPOSITORY}" "${RELEASE_VERSION}" "${FILE}" "${FILE}.sha1" "${FILE}.sha256"
  30. EXIT_STATUS=$?
  31. echo "exit: ${EXIT_STATUS}"
  32. if (( "${EXIT_STATUS}" )); then
  33. for (( i=0; i<10; i++ )); do
  34. github-release delete --owner "${REPOSITORY_OWNER}" --repo "${REPOSITORY_NAME}" --tag "${RELEASE_VERSION}" "${FILE}" "${FILE}.sha1" "${FILE}.sha256"
  35. sleep $(( 15 * (i + 1)))
  36. echo "RE-Uploading '${FILE}' at $( date "+%T" )"
  37. gh release upload --repo "${ASSETS_REPOSITORY}" "${RELEASE_VERSION}" "${FILE}" "${FILE}.sha1" "${FILE}.sha256"
  38. EXIT_STATUS=$?
  39. echo "exit: ${EXIT_STATUS}"
  40. if ! (( "${EXIT_STATUS}" )); then
  41. break
  42. fi
  43. done
  44. echo "exit: ${EXIT_STATUS}"
  45. if (( "${EXIT_STATUS}" )); then
  46. echo "'${FILE}' hasn't been uploaded!"
  47. github-release delete --owner "${REPOSITORY_OWNER}" --repo "${REPOSITORY_NAME}" --tag "${RELEASE_VERSION}" "${FILE}" "${FILE}.sha1" "${FILE}.sha256"
  48. exit 1
  49. fi
  50. fi
  51. echo "::endgroup::"
  52. fi
  53. done
  54. cd ..