forked from maximhq/bifrost
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease-cli.sh
More file actions
executable file
·143 lines (116 loc) · 3.88 KB
/
Copy pathrelease-cli.sh
File metadata and controls
executable file
·143 lines (116 loc) · 3.88 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
#!/usr/bin/env bash
set -euo pipefail
# Release bifrost CLI component
# Usage: ./release-cli.sh <version>
# Get the absolute path of the script directory
if command -v readlink >/dev/null 2>&1 && readlink -f "$0" >/dev/null 2>&1; then
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
else
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
fi
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd -P)"
# Validate input argument
if [ "${1:-}" = "" ]; then
echo "Usage: $0 <version>" >&2
exit 1
fi
VERSION="$1"
TAG_NAME="cli/v${VERSION}"
echo "🚀 Releasing bifrost CLI v$VERSION..."
# Validate CLI build
echo "🔨 Validating CLI build..."
COMMIT="${GITHUB_SHA:-$(git rev-parse HEAD 2>/dev/null || echo 'unknown')}"
(cd "$REPO_ROOT/cli" && go build -ldflags "-X main.version=v${VERSION} -X main.commit=${COMMIT}" ./...)
echo "✅ CLI build validation successful"
# Build CLI executables
echo "🔨 Building executables..."
bash "$SCRIPT_DIR/build-cli-executables.sh" "$VERSION"
# --- Preflight checks (no side effects) ---
# Capturing changelog
CHANGELOG_BODY=$(cat "$REPO_ROOT/cli/changelog.md")
# Skip comments from changelog
CHANGELOG_BODY=$(printf '%s\n' "$CHANGELOG_BODY" | sed '/<!--/,/-->/d')
# If changelog is empty, return error
if [ -z "$CHANGELOG_BODY" ]; then
echo "❌ Changelog is empty"
exit 1
fi
echo "📝 New changelog: $CHANGELOG_BODY"
# Finding previous tag
echo "🔍 Finding previous tag..."
TAG_COUNT=$(git tag -l "cli/v*" | wc -l | tr -d ' ')
if [[ "$TAG_COUNT" -eq 0 ]]; then
PREV_TAG=""
else
PREV_TAG=$(git tag -l "cli/v*" | sort -V | tail -1)
if [[ "$PREV_TAG" == "$TAG_NAME" ]]; then
PREV_TAG=$(git tag -l "cli/v*" | sort -V | tail -2 | head -1)
[[ "$PREV_TAG" == "$TAG_NAME" ]] && PREV_TAG=""
fi
fi
echo "🔍 Previous tag: $PREV_TAG"
# Get message of the tag and compare changelogs
if [[ -n "$PREV_TAG" ]]; then
echo "🔍 Getting previous tag message..."
PREV_CHANGELOG=$(git tag -l --format='%(contents:body)' "$PREV_TAG")
echo "📝 Previous changelog body: $PREV_CHANGELOG"
# Checking if tag message is the same as the changelog
if [[ "$PREV_CHANGELOG" == "$CHANGELOG_BODY" ]]; then
echo "❌ Changelog is the same as the previous changelog"
exit 1
fi
else
echo "ℹ️ No previous CLI tag found. Skipping changelog comparison."
fi
# Verify GitHub token before any publish steps
if [ -z "${GH_TOKEN:-}" ] && [ -z "${GITHUB_TOKEN:-}" ]; then
echo "Error: GH_TOKEN or GITHUB_TOKEN is not set. Please export one to authenticate the GitHub CLI."
exit 1
fi
# --- Publish steps (all checks passed) ---
# Configure and upload to R2
echo "📤 Uploading binaries..."
bash "$SCRIPT_DIR/configure-r2.sh"
bash "$SCRIPT_DIR/upload-cli-to-r2.sh" "$TAG_NAME"
# Create and push tag
if git rev-parse -q --verify "refs/tags/$TAG_NAME" >/dev/null; then
echo "ℹ️ Tag $TAG_NAME already exists. Reusing it."
else
echo "🏷️ Creating tag: $TAG_NAME"
git tag "$TAG_NAME" -m "Release CLI v$VERSION" -m "$CHANGELOG_BODY"
git push origin "$TAG_NAME"
fi
# Create GitHub release
TITLE="Bifrost CLI v$VERSION"
# Mark prereleases when version contains a hyphen
PRERELEASE_FLAG=""
if [[ "$VERSION" == *-* ]]; then
PRERELEASE_FLAG="--prerelease"
fi
BODY="## Bifrost CLI Release v$VERSION
$CHANGELOG_BODY
### Installation
#### Binary Download
\`\`\`bash
npx @maximhq/bifrost --cli-version v$VERSION
\`\`\`
---
_This release was automatically created._"
if gh release view "$TAG_NAME" >/dev/null 2>&1; then
echo "ℹ️ GitHub release $TAG_NAME already exists. Skipping."
else
echo "🎉 Creating GitHub release for $TITLE..."
gh release create "$TAG_NAME" \
--title "$TITLE" \
--notes "$BODY" \
${PRERELEASE_FLAG}
fi
echo "✅ Bifrost CLI released successfully"
# Print summary
echo ""
echo "📋 Release Summary:"
echo " 🏷️ Tag: $TAG_NAME"
echo " 🎉 GitHub release: Created"
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "success=true" >> "$GITHUB_OUTPUT"
fi