-
Notifications
You must be signed in to change notification settings - Fork 255
/
release.sh
executable file
·59 lines (46 loc) · 1.55 KB
/
release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Fetch the token
TOKEN=$(git config --get github.token)
# Check if GitHub token exists
if [ -z "$TOKEN" ]; then
echo "GitHub token not found in your git config. Please generate a new token at https://github.com/settings/tokens"
exit 1
fi
# Make sure that the token is valid (a 200 is good enough, not checking scopes)
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $TOKEN" https://api.github.com)
if [ "$RESPONSE" != "200" ]; then
echo "Invalid GitHub token. Please generate a new token at https://github.com/settings/tokens"
exit 1
fi
# If we made it here, the token is valid
echo -e "GitHub Token is valid. Success!\n "
# Get the latest tag
TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
# Release to upload
FILE="./build/distributions/adb-idea-$TAG.zip"
# Check if the file exists
if [ ! -f "$FILE" ]; then
echo "$FILE does not exist."
exit 1
else
# Get file creation date
echo "This file will be uploaded:"
ls -la "$FILE"
echo ""
fi
# Show the tag to the user
echo -e "Latest tag is: \033[0;32m$TAG\033[0m"
read -p "Is this the correct tag? (yes/no): " answer
if [[ "$answer" != "yes" && "$answer" != "y" ]]; then
echo "Time to fix the tag."
exit 1
fi
# Upload the release using the ghr tool
ghr_output=$(ghr ${TAG} ${FILE} 2>&1)
if [[ $? -ne 0 ]]; then
echo -e "\033[0;31mUpload failed with error: $ghr_output\033[0m"
exit 1
else
echo -e "\n\033[0;32mRelease uploaded successfully!\033[0m"
echo -e "\033[0;32mhttps://github.com/pbreault/adb-idea/releases/tag/${TAG}\033[0m"
fi