-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmake-relase.sh
More file actions
executable file
·140 lines (115 loc) · 4.48 KB
/
Copy pathmake-relase.sh
File metadata and controls
executable file
·140 lines (115 loc) · 4.48 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
# --- Configuration ---
# Path to the APK file to be attached to the release
APK_PATH="./app/build/outputs/apk/release/app-release.apk"
# GitHub repository in the format OWNER/REPO (usually inferred by gh)
# REPO_URL="aario/snotepad" # uncomment and set if gh can't detect it automatically
# --- Set Bash options for robustness ---
# Exit immediately if a command exits with a non-zero status.
set -e
# Treat unset variables as an error when substituting.
set -u
# Pipe commands return the exit status of the last command in the pipe
set -o pipefail
# --- Pre-checks ---
echo "--- Running Pre-checks ---"
# 1. Check if inside a Git repository
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
echo "ERROR: This script must be run from within a Git repository."
exit 1
fi
echo "✓ Git repository detected."
# 2. Check if the GitHub CLI (gh) is installed
if ! command -v gh &> /dev/null; then
echo "ERROR: GitHub CLI (gh) not found. Please install it (https://cli.github.com/) and authenticate (gh auth login)."
exit 1
fi
echo "✓ GitHub CLI (gh) found."
# 3. Check if gh is authenticated
if ! gh auth status > /dev/null 2>&1; then
echo "ERROR: Not authenticated with GitHub CLI. Please run 'gh auth login'."
exit 1
fi
echo "✓ GitHub CLI is authenticated."
# 4. Check if the APK file exists
if [ ! -f "$APK_PATH" ]; then
echo "ERROR: APK file not found at '$APK_PATH'. Please build the release APK first."
exit 1
fi
echo "✓ APK file found at '$APK_PATH'."
echo "--- Pre-checks completed successfully ---"
echo
# Find the latest tag in the history
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
echo "Last tag found: $LATEST_TAG"
# --- Get Tag Name ---
read -p "Enter the tag name for the new release (e.g., v1.0.0): " TAG_NAME
if [ -z "$TAG_NAME" ]; then
echo "ERROR: Tag name cannot be empty."
exit 1
fi
# Check if the tag already exists locally or remotely
if git rev-parse "$TAG_NAME" >/dev/null 2>&1 || git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME$"; then
echo "ERROR: Tag '$TAG_NAME' already exists locally or remotely."
exit 1
fi
echo "Using tag name: $TAG_NAME"
echo
# --- Generate Release Notes ---
echo "--- Generating Release Notes ---"
RELEASE_NOTES=""
if [ -z "$LATEST_TAG" ]; then
echo "No previous tags found. Generating notes from all commits."
# If no tags exist, get all commit messages
RELEASE_NOTES=$(git log --pretty=format:"* %s (%h)")
else
echo "Generating notes from commits since tag '$LATEST_TAG'."
# Get commit messages since the last tag
RELEASE_NOTES=$(git log "${LATEST_TAG}"..HEAD --pretty=format:"* %s (%h)")
fi
if [ -z "$RELEASE_NOTES" ]; then
echo "Warning: No new commits found since the last tag (or no commits found at all)."
RELEASE_NOTES="No changes detected."
exit 1
fi
echo "--- Release Notes Generated ---"
echo "$RELEASE_NOTES"
echo "------------------------------"
echo
# --- Create and Push Git Tag ---
echo "--- Tagging and Pushing ---"
echo "Creating local tag '$TAG_NAME'..."
# Create a lightweight tag pointing to the latest commit
git tag "$TAG_NAME"
echo "Pushing tag '$TAG_NAME' to remote 'origin'..."
# Push the tag to the remote repository
git push origin "$TAG_NAME"
echo "✓ Tag '$TAG_NAME' pushed successfully."
echo
# --- Create GitHub Release ---
echo "--- Creating GitHub Release ---"
echo "Creating release '$TAG_NAME' on GitHub..."
# Use gh release create command
# It automatically uses the tag name for the release title
# -t specifies the title (using tag name again for clarity)
# -n specifies the notes
# The last argument is the file to attach
gh release create "$TAG_NAME" \
--title "$TAG_NAME" \
--notes "$RELEASE_NOTES" \
"$APK_PATH"
# Check the exit status of the gh command
if [ $? -eq 0 ]; then
echo "✓ GitHub release '$TAG_NAME' created successfully!"
echo "You can view it at: https://github.com/$(gh repo view --json nameWithOwner -q .nameWithOwner)/releases/tag/$TAG_NAME"
else
echo "ERROR: Failed to create GitHub release."
# Attempt to clean up the pushed tag if release creation failed
echo "Attempting to delete remote tag '$TAG_NAME'..."
git push --delete origin "$TAG_NAME" || echo "Warning: Failed to delete remote tag '$TAG_NAME'. Manual cleanup might be required."
echo "Attempting to delete local tag '$TAG_NAME'..."
git tag -d "$TAG_NAME" || echo "Warning: Failed to delete local tag '$TAG_NAME'. Manual cleanup might be required."
exit 1
fi
echo "--- Script Finished ---"
exit 0