-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsdk-release-base.sh
More file actions
executable file
Β·158 lines (127 loc) Β· 4.62 KB
/
sdk-release-base.sh
File metadata and controls
executable file
Β·158 lines (127 loc) Β· 4.62 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
# Base release script - sourced by staging and production scripts
# Usage: source ./sdk-release-base.sh
# Exit immediately on error
set -e
# Function to check if version already exists on npm
check_npm_version() {
local package_name=$1
local version=$2
# First check if package exists at all
if ! npm view "$package_name" version >/dev/null 2>&1; then
return 1 # Package doesn't exist, so version doesn't exist
fi
# Package exists, check specific version
if npm view "$package_name@$version" version >/dev/null 2>&1; then
return 0 # Version exists
else
return 1 # Version doesn't exist
fi
}
# Function to get next staging version using git tags
get_next_staging_version() {
local base_version=$1
# Find the highest staging version for this base version from git tags
local highest_staging=0
# Get all tags that match the staging pattern for this base version
local staging_tags=$(git tag -l "sdk-v${base_version}-staging.*" 2>/dev/null || echo "")
if [ -n "$staging_tags" ]; then
while IFS= read -r tag; do
# Extract version from tag (sdk-v0.0.2-staging.1 -> 0.0.2-staging.1)
local version=${tag#sdk-v}
if [[ $version =~ ^${base_version}-staging\.([0-9]+)$ ]]; then
local staging_num=${BASH_REMATCH[1]}
if [ $staging_num -gt $highest_staging ]; then
highest_staging=$staging_num
fi
fi
done <<< "$staging_tags"
fi
echo "${base_version}-staging.$((highest_staging + 1))"
}
# Function to check npm authentication
check_npm_auth() {
echo "π Checking npm authentication..."
if ! npm whoami >/dev/null 2>&1; then
echo "β You are not logged in to npm!"
echo "π‘ Please run: npm login"
echo "π‘ Or set NPM_TOKEN environment variable for CI/CD"
return 1
fi
echo "β
npm authentication verified"
return 0
}
# Function to create git tag and release
create_git_release() {
local version=$1
local release_notes=$2
local is_prerelease=$3
local tag_name="sdk-v$version"
echo "π·οΈ Creating git tag: $tag_name"
git tag -a "$tag_name" -m "SDK Release $version"
echo "π Pushing tag to remote..."
git push origin "$tag_name"
# Wait a moment for the tag to be available on GitHub
echo "β³ Waiting for tag to be available on GitHub..."
sleep 2
echo "π Creating GitHub release..."
local gh_cmd="gh release create \"$tag_name\" --title \"SDK Release $version\" --notes \"$release_notes\""
if [ "$is_prerelease" = "true" ]; then
gh_cmd="$gh_cmd --prerelease --latest=false"
fi
eval $gh_cmd
}
# Function to build SDK (without publishing)
build_sdk() {
local environment=$1
local package_name=$2
local version=$3
local site_url=$4
local supabase_url=$5
local supabase_anon_key=$6
echo "π§ Configuring package for $environment environment..."
echo "π Site URL: $site_url"
echo "ποΈ Supabase URL: $supabase_url"
# Update package.json with correct name and version in place
cd ts-sdk
jq --arg name "$package_name" --arg version "$version" \
'.name = $name | .version = $version' package.json > package.json.tmp && mv package.json.tmp package.json
# Install dependencies
echo "π Installing dependencies..."
npm install
# Build SDK with environment-specific variables
echo "ποΈ Building SDK for $environment..."
(
export NEXT_PUBLIC_SITE_URL="$site_url"
export NEXT_PUBLIC_SUPABASE_URL="$supabase_url"
export NEXT_PUBLIC_SUPABASE_ANON_KEY="$supabase_anon_key"
npm run build
)
cd ..
# Force add dist/ and node_modules/
# echo "β Adding ts-sdk/dist and ts-sdk/node_modules..."
# git add -f ts-sdk/dist
# git add -f ts-sdk/node_modules
# git add ts-sdk/package.json
# # Commit build
# echo "π¦ Committing $environment SDK build..."
# git commit -m "Build $environment SDK $version"
echo "β
$environment SDK $version built successfully!"
}
# Function to publish SDK to npm
publish_sdk() {
local package_name=$1
local version=$2
echo "π€ Publishing to npm..."
cd ts-sdk
npm publish --access public
cd ..
echo "β
Published $package_name@$version to npm!"
}
# Function to restore original package.json
restore_package_json() {
echo "π Restoring original package.json..."
cd ts-sdk
git checkout package.json package-lock.json
cd ..
}