release.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. API_BASE="https://api.github.com"
  5. UPLOAD_BASE="https://uploads.github.com"
  6. # TODO, rename this to alphapapa/solarized-everything-css
  7. OWNER="alphapapa"
  8. # REPO="solarized-everything-css"
  9. REPO="solarized-everything-css"
  10. REPO_BASE="${OWNER}/${REPO}"
  11. TARGET_ZIP_NAME="solarized-everything.zip"
  12. # USAGE:
  13. # ./release.sh [tag-name] [tag-message]
  14. #
  15. # To upload releases, please put a github token in the GH_TOKEN env var, or run with
  16. # GH_TOKEN="<TOKEN>" ./release.sh hello "my message"
  17. #
  18. # For a unofficial release: ./release.sh
  19. #
  20. # Dependencies: curl, jq, and git
  21. # Check depdencies
  22. if ! command -v curl >/dev/null 2>&1 \
  23. || ! command -v jq >/dev/null 2>&1 \
  24. || ! command -v git >/dev/null 2>&1; then
  25. echo "Please install curl, jq, and git to continue" >&2
  26. exit 1
  27. fi
  28. GIT_COMMIT="$(git rev-parse HEAD)"
  29. echo "Running make..."
  30. echo
  31. make
  32. mkdir -p dist
  33. echo "zipping files..."
  34. zip "dist/$TARGET_ZIP_NAME" -r css/
  35. if [ -z "${GH_TOKEN:-}" ]; then
  36. echo "No GH_TOKEN provided, exiting"
  37. exit 2
  38. fi
  39. # Check if we have tag info
  40. if [ -z "${1:-}" ]; then
  41. echo
  42. echo "Please provide a tag for this release" 2>&1
  43. exit 1
  44. elif [ -z "${2:-}" ]; then
  45. echo
  46. echo "Please provide a tag message this release" 2>&1
  47. exit 1
  48. else
  49. TAG="$1"
  50. MESSAGE="$2"
  51. fi
  52. echo "Creating release..."
  53. echo
  54. RELEASE_OBJECT="$(curl -X POST "$API_BASE/repos/$REPO_BASE/releases" \
  55. -H "Authorization: token $GH_TOKEN" \
  56. -d "{
  57. \"tag_name\": \"$TAG\",
  58. \"target_commitish\": \"$GIT_COMMIT\",
  59. \"name\": \"$TAG\",
  60. \"body\": \"$MESSAGE\",
  61. \"draft\": true,
  62. \"prerelease\": false
  63. }")"
  64. RELEASE_ID="$(echo "$RELEASE_OBJECT" | jq -r '.id')"
  65. echo "Uploading release assets..."
  66. curl -X POST "$UPLOAD_BASE/repos/$REPO_BASE/releases/$RELEASE_ID/assets?name=$TARGET_ZIP_NAME" \
  67. -H "Authorization: token $GH_TOKEN" \
  68. -H "Content-Type: application/zip" \
  69. --data-binary "@dist/${TARGET_ZIP_NAME}" >/dev/null
  70. echo
  71. echo "Release created successfuly!"
  72. echo "Please verify and publish the draft."