-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·138 lines (119 loc) · 4.78 KB
/
release.sh
File metadata and controls
executable file
·138 lines (119 loc) · 4.78 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
#!/bin/bash
set -e
# Configuration - Version comes from version.py
VERSION_FILE="reddacted/version.py"
GITHUB_USER="taylorwilsdon"
REPO="reddacted"
UPDATE_DEPS_ONLY=false
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--update-deps-only) UPDATE_DEPS_ONLY=true ;;
*) echo "Unknown parameter: $1"; exit 1 ;;
esac
shift
done
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Extract version from version.py file
VERSION=$(grep -o '__version__ = "[^"]*"' "$VERSION_FILE" | cut -d'"' -f2)
echo -e "${YELLOW}Starting release process for reddacted v${VERSION}${NC}"
# 1. Check for required tools
if ! command -v jq &> /dev/null; then
echo -e "${YELLOW}jq not found. Please install it to update dependencies.${NC}"
echo -e "${YELLOW}On macOS: brew install jq${NC}"
exit 1
fi
if [ "$UPDATE_DEPS_ONLY" = false ]; then
# 2. Ensure we're on the main branch
git checkout main
# Skip git pull if no upstream is configured
git rev-parse --abbrev-ref @{upstream} >/dev/null 2>&1 && git pull || echo "No upstream branch configured, skipping pull"
# 3. Clean build artifacts
echo -e "${YELLOW}Cleaning previous build artifacts...${NC}"
rm -rf dist/ build/ *.egg-info/
# 4. Build the package with UV (both sdist and wheel)
echo -e "${YELLOW}Building package with UV...${NC}"
uv build --sdist --wheel || {
echo -e "${YELLOW}Failed to build package${NC}"
exit 1
}
# 5. Create and push git tag
echo -e "${YELLOW}Creating and pushing git tag v${VERSION}...${NC}"
# Improved tag handling - check both local and remote tags
LOCAL_TAG_EXISTS=$(git tag -l "v${VERSION}")
REMOTE_TAG_EXISTS=$(git ls-remote --tags origin "refs/tags/v${VERSION}" | wc -l)
if [ -n "$LOCAL_TAG_EXISTS" ]; then
echo -e "${YELLOW}Local tag v${VERSION} already exists${NC}"
else
git tag -a "v${VERSION}" -m "Release v${VERSION}"
echo -e "${YELLOW}Created local tag v${VERSION}${NC}"
fi
# Only push if tag doesn't exist on remote
if [ "$REMOTE_TAG_EXISTS" -eq 0 ]; then
echo -e "${YELLOW}Pushing tag to remote...${NC}"
git push origin "v${VERSION}" || echo "Failed to push tag, continuing anyway"
else
echo -e "${YELLOW}Remote tag v${VERSION} already exists, skipping push${NC}"
fi
# 6. Create GitHub release
echo -e "${YELLOW}Creating GitHub release...${NC}"
# Check if gh command is available
if ! command -v gh &> /dev/null; then
echo -e "${YELLOW}GitHub CLI not found. Please install it to create releases.${NC}"
echo -e "${YELLOW}Skipping GitHub release creation.${NC}"
else
# Check if release already exists
if gh release view "v${VERSION}" &>/dev/null; then
echo -e "${YELLOW}Release v${VERSION} already exists, skipping creation${NC}"
else
gh release create "v${VERSION}" \
--title "reddacted v${VERSION}" \
--notes "Release v${VERSION}" \
./dist/*
fi
fi
# 7. Download the tarball to calculate SHA
echo -e "${YELLOW}Downloading tarball to calculate SHA...${NC}"
TARBALL_PATH="/tmp/${REPO}-${VERSION}.tar.gz"
if curl -sL --fail "https://github.com/${GITHUB_USER}/${REPO}/archive/refs/tags/v${VERSION}.tar.gz" -o "${TARBALL_PATH}"; then
SHA=$(shasum -a 256 "${TARBALL_PATH}" | cut -d ' ' -f 1)
# Generate new Homebrew formula
echo -e "${YELLOW}Generating new Homebrew formula...${NC}"
if ! python3 scripts/homebrew_formula_generator.py "${VERSION}"; then
echo -e "${YELLOW}Failed to generate Homebrew formula${NC}"
exit 1
fi
else
echo -e "${YELLOW}Failed to download tarball, skipping SHA calculation and Homebrew formula update${NC}"
fi
# 8. Publish to PyPI if desired
read -p "Do you want to publish to PyPI? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo -e "${YELLOW}Publishing to PyPI...${NC}"
if ! uv publish; then
echo -e "${YELLOW}Failed to publish to PyPI${NC}"
exit 1
fi
fi
fi
# Ensure scripts directory exists and formula generator is executable
if [ ! -d "scripts" ]; then
echo -e "${YELLOW}Creating scripts directory...${NC}"
mkdir -p scripts
fi
if [ ! -x "scripts/homebrew_formula_generator.py" ]; then
echo -e "${YELLOW}Making formula generator executable...${NC}"
chmod +x scripts/homebrew_formula_generator.py
fi
# 10. Instructions for Homebrew tap
echo -e "${GREEN}Release v${VERSION} completed!${NC}"
echo -e "${GREEN}To publish to Homebrew:${NC}"
echo -e "1. Create a tap repository: github.com/${GITHUB_USER}/homebrew-tap"
echo -e "2. Copy homebrew/reddacted.rb to your tap repository"
echo -e "3. Users can then install with: brew install ${GITHUB_USER}/tap/reddacted"
echo -e "${GREEN}Done!${NC}"