-
Notifications
You must be signed in to change notification settings - Fork 268
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·144 lines (124 loc) · 5.18 KB
/
release.sh
File metadata and controls
executable file
·144 lines (124 loc) · 5.18 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
141
142
143
144
#!/bin/bash
set -e
VERSION=$1
# Check if tag already exists
if git rev-parse "v${VERSION}" >/dev/null 2>&1; then
echo "Error: Tag v${VERSION} already exists!"
echo "Please remove the tag running 'git tag -d v${VERSION}' and try again."
exit 1
fi
# Check if branch already exists
if git show-ref --verify --quiet "refs/heads/release/v${VERSION}" || \
git show-ref --verify --quiet "refs/remotes/origin/release/v${VERSION}"; then
echo "Error: Branch release/v${VERSION} already exists locally or remotely!"
echo "Please remove the branch running 'git branch -D release/v${VERSION}' and try again."
exit 1
fi
# Verify version format
if ! echo "$VERSION" | grep -E "^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+(\.[0-9]+)?)?$" > /dev/null; then
echo "Version must be in format X.Y.Z or X.Y.Z-SUFFIX[.N] (e.g., 1.2.3 or 1.2.3-beta.0)"
exit 1
fi
# Cross-platform sed command (macOS and Linux)
do_sed() {
local file=$1
local pattern=$2
if [[ "$(uname)" == "Darwin" ]]; then
sed -i '.bak' "$pattern" "$file"
rm "${file}.bak"
else
sed -i "$pattern" "$file"
fi
}
# Update CHANGELOG.md - replace "## Unreleased" with version and date
CURRENT_DATE=$(date +%Y-%m-%d)
do_sed "CHANGELOG.md" "s/## Unreleased/## [${VERSION}] - ${CURRENT_DATE}/"
# Update workspace version
do_sed "Cargo.toml" "s/^version = \".*\"/version = \"${VERSION}\"/"
# List of crates that require explicit version dependencies for publishing
CRATES=("common" "crypto" "serde" "class-hash" "consensus")
# Update versions in crate Cargo.toml files
for crate in "${CRATES[@]}"; do
file="crates/${crate}/Cargo.toml"
echo "Updating dependencies for $file..."
do_sed "$file" "s/pathfinder-common = { version = \"[^\"]*\"/pathfinder-common = { version = \"${VERSION}\"/"
do_sed "$file" "s/pathfinder-crypto = { version = \"[^\"]*\"/pathfinder-crypto = { version = \"${VERSION}\"/"
do_sed "$file" "s/pathfinder-serde = { version = \"[^\"]*\"/pathfinder-serde = { version = \"${VERSION}\"/"
done
# Update Cargo.lock and verify everything still builds
cargo check --workspace --all-targets
cargo check --workspace --all-targets --all-features
# The `load-test` crate is excluded from the workspace but has a dependency on `pathfinder-common`.
pushd crates/load-test
cargo check
popd
# Create and checkout new release branch
git checkout -b release/v${VERSION}
# Create git commit
git add Cargo.toml Cargo.lock **/Cargo.toml **/Cargo.lock CHANGELOG.md
git commit -m "chore: bump version to ${VERSION}"
# Quick recap of what was done
echo -e "\nChanges made:"
echo "- Updated workspace version to ${VERSION}"
echo "- Updated CHANGELOG.md with version ${VERSION} and date ${CURRENT_DATE}"
echo "- Updated dependency versions in public crates:"
for crate in "${CRATES[@]}"; do
echo " - crates/${crate}/Cargo.toml"
done
# Confirmation before pushing
echo -e "\nPush these changes to \`release/v${VERSION}\`? (Y/n)"
read -r answer
if [[ "$answer" == "n" ]] || [[ "$answer" == "N" ]]; then
echo "Aborting push. Changes are committed locally."
exit 1
fi
# Push changes
git push --set-upstream origin release/v${VERSION}
# Try to create PR automatically if gh CLI is available
if command -v gh &> /dev/null; then
echo -e "\nCreating PR automatically with gh CLI..."
if PR_URL=$(gh pr create --title "chore: bump version to ${VERSION}" --body "Automated release PR for version ${VERSION}" --base main --head release/v${VERSION} 2>/dev/null); then
echo "PR created: $PR_URL"
echo -e "\nPlease review and merge the PR, then come back here and press Enter to continue..."
else
echo "Failed to create PR with gh CLI. Falling back to manual instructions..."
echo -e "\n"
echo "=========================================="
echo "Next steps:"
echo "1. Create a PR for branch 'release/v${VERSION}'"
echo "2. Review and merge the PR to 'main'"
echo "3. Come back here and press Enter to continue"
echo "=========================================="
echo -e "\nPress Enter once the PR has been merged to continue..."
fi
else
echo -e "\n"
echo "=========================================="
echo "Next steps:"
echo "1. Create a PR for branch 'release/v${VERSION}'"
echo "2. Review and merge the PR to 'main'"
echo "3. Come back here and press Enter to continue"
echo "=========================================="
echo -e "\nPress Enter once the PR has been merged to continue..."
fi
read -r
# Switch to main and pull latest
git checkout main
git pull origin main
# Confirmation before creating tag
echo -e "\nReady to create and push tag 'v${VERSION}'"
echo "This will trigger the Release and Docker workflows."
echo -e "\nCreate and push tag 'v${VERSION}'? (Y/n)"
read -r answer
if [[ "$answer" == "n" ]] || [[ "$answer" == "N" ]]; then
echo "Aborting tag creation."
exit 1
fi
# Create and push tag
echo "Creating and pushing tag v${VERSION}..."
git tag -a v${VERSION} -m "Pathfinder v${VERSION}"
git push origin v${VERSION}
# Done
echo -e "\n✅ Tag 'v${VERSION}' has been pushed!"
echo "The Release and Docker workflows should now be triggered."
echo "You can monitor their progress in the GitHub Actions tab."