-
Notifications
You must be signed in to change notification settings - Fork 4
/
deploy.sh
123 lines (109 loc) · 3.16 KB
/
deploy.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
REPO="PENEKhun/baekjoon-java-starter"
RELEASE_NAME="Release"
RELEASE_DESCRIPTION="This is the release description."
BUILD_DIR="build/libs"
BOJ_STARTER_GIT_TOKEN=$BOJ_STARTER_GIT_TOKEN
check_github_token() {
if [ -z "$BOJ_STARTER_GIT_TOKEN" ]; then
echo "Error: BOJ_STARTER_GIT_TOKEN is not set. Please set the BOJ_STARTER_GIT_TOKEN environment variable."
exit 1
fi
}
check_jq_installed() {
if ! command -v jq &> /dev/null; then
echo "jq could not be found. Please install jq to continue."
exit 1
fi
}
create_git_tag() {
git tag -a $VERSION -m "Release version $VERSION"
git push origin $VERSION
if [ $? -ne 0 ]; then
echo "Failed to create and push the tag."
exit 1
fi
}
get_latest_version() {
GITHUB_API_URL="https://api.github.com/repos/$REPO/releases/latest"
LATEST_VERSION=$(curl -s -H "Authorization: token $BOJ_STARTER_GIT_TOKEN" $GITHUB_API_URL | jq -r ".tag_name")
if [ "$LATEST_VERSION" == "null" ] || [ -z "$LATEST_VERSION" ]; then
echo "Failed to fetch the latest release version."
exit 1
fi
echo "Latest release version: $LATEST_VERSION"
}
get_version() {
read -p "Enter the version (e.g., 1.0.0-alpha): " VERSION
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+-[a-zA-Z]+$ ]]; then
echo "Invalid version format. Please use the format: numbers.numbers.numbers-letters (e.g., 0.0.3-alpha)"
exit 1
fi
}
build_project() {
./gradlew clean build -PdeployMode -PprojVersion=$VERSION
if [ $? -ne 0 ]; then
echo "Build failed."
exit 1
fi
}
find_jar_file() {
FILE_PATH=$(ls -t $BUILD_DIR/*.jar | head -n 1)
if [ ! -f "$FILE_PATH" ]; then
echo "JAR file not found."
exit 1
fi
}
create_release() {
GITHUB_API_URL="https://api.github.com/repos/$REPO/releases"
# VERSION에 PRERELEASE가 포함되면 prerelease로 설정
if [[ "$VERSION" =~ PRERELEASE ]]; then
PRERELEASE=true
else
PRERELEASE=false
fi
RELEASE_RESPONSE=$(curl -s -X POST $GITHUB_API_URL \
-H "Authorization: token $BOJ_STARTER_GIT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"tag_name": "'"$VERSION"'",
"name": "'"$RELEASE_NAME $VERSION"'",
"body": "'"$RELEASE_DESCRIPTION"'",
"draft": false,
"prerelease": '"$PRERELEASE"'
}')
RELEASE_ID=$(echo "$RELEASE_RESPONSE" | jq -r '.id')
if [ "$RELEASE_ID" == "null" ]; then
echo "Failed to create a release."
echo "Response: $RELEASE_RESPONSE"
exit 1
fi
UPLOAD_URL=$(echo "$RELEASE_RESPONSE" | jq -r '.upload_url' | sed -e "s/{?name,label}//")
}
upload_file() {
FILE_NAME=$(basename "$FILE_PATH")
UPLOAD_RESPONSE=$(curl -s -X POST "$UPLOAD_URL?name=$FILE_NAME" \
-H "Authorization: token $BOJ_STARTER_GIT_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$FILE_PATH")
if echo "$UPLOAD_RESPONSE" | jq -e '.id' > /dev/null; then
echo "File uploaded successfully."
else
echo "Failed to upload the file."
echo "Response: $UPLOAD_RESPONSE"
exit 1
fi
echo "Release created and file uploaded successfully."
}
main() {
check_github_token
check_jq_installed
get_latest_version
get_version
create_git_tag
build_project
find_jar_file
create_release
upload_file
}
main