forked from firebase/genkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpromote_cli_gcs.sh
More file actions
executable file
·229 lines (202 loc) · 6.01 KB
/
promote_cli_gcs.sh
File metadata and controls
executable file
·229 lines (202 loc) · 6.01 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/bash
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
set -e
set -x
# Script to promote CLI binaries from GitHub artifacts to GCS
# Usage: promote_cli_gcs.sh [options]
#
# Options:
# --github-run-id=ID GitHub Actions run ID to download artifacts from
# --github-tag=TAG GitHub release tag to download artifacts from
# --channel=CHANNEL Target channel (prod/next)
# --version=VERSION Version string for GCS paths
# --bucket=BUCKET GCS bucket name (default: genkit-cli-binaries)
# --dry-run Show what would be done without doing it
# Default values
GITHUB_RUN_ID=""
GITHUB_TAG=""
CHANNEL="next"
VERSION=""
BUCKET="genkit-assets-cli"
DRY_RUN=false
# Parse command line arguments
for arg in "$@"; do
case $arg in
--github-run-id=*)
GITHUB_RUN_ID="${arg#*=}"
shift
;;
--github-tag=*)
GITHUB_TAG="${arg#*=}"
shift
;;
--channel=*)
CHANNEL="${arg#*=}"
shift
;;
--version=*)
VERSION="${arg#*=}"
shift
;;
--bucket=*)
BUCKET="${arg#*=}"
shift
;;
--dry-run)
DRY_RUN=true
shift
;;
*)
echo "Unknown option: $arg"
exit 1
;;
esac
done
# Validate inputs
if [[ -z "$GITHUB_RUN_ID" && -z "$GITHUB_TAG" ]]; then
echo "Error: Either --github-run-id or --github-tag must be specified"
exit 1
fi
if [[ -z "$VERSION" ]]; then
echo "Error: --version must be specified"
exit 1
fi
if [[ "$CHANNEL" != "prod" && "$CHANNEL" != "next" ]]; then
echo "Error: --channel must be either 'prod' or 'next'"
exit 1
fi
# Platform list matching build-cli-binaries.yml
PLATFORMS=(
"linux-x64"
"linux-arm64"
"darwin-x64"
"darwin-arm64"
"win32-x64"
)
echo "=== CLI Binary Promotion to GCS ==="
echo "Channel: $CHANNEL"
echo "Version: $VERSION"
echo "Bucket: $BUCKET"
echo "Dry run: $DRY_RUN"
echo ""
# Create temporary directory for downloads
TMP_DIR=$(mktemp -d)
trap "rm -rf $TMP_DIR" EXIT
# Validate that TMP_DIR exists and is writable
if [[ -z "$TMP_DIR" || ! -d "$TMP_DIR" || ! -w "$TMP_DIR" ]]; then
echo "Error: Failed to create a writable temporary directory."
exit 1
fi
cd "$TMP_DIR"
# Download artifacts from GitHub
if [[ -n "$GITHUB_RUN_ID" ]]; then
echo "Downloading artifacts from GitHub run ID: $GITHUB_RUN_ID"
# Check if gh CLI is available
if ! command -v gh &> /dev/null; then
echo "Error: GitHub CLI (gh) is not installed"
echo "Please install it from: https://cli.github.com/"
exit 1
fi
# Download all artifacts for the run
for platform in "${PLATFORMS[@]}"; do
echo "Downloading artifact: genkit-$platform"
if [[ "$DRY_RUN" == "false" ]]; then
# Use gh CLI to download the artifact
if gh run download "$GITHUB_RUN_ID" -n "genkit-$platform" -R firebase/genkit; then
continue
# The artifact is downloaded as a directory, move the binary to the current directory
# if [[ -f "genkit-$platform" ]]; then
# mv "genkit-$platform" .
# elif [[ -f "genkit-$platform.exe" ]]; then
# mv "genkit-$platform.exe" .
# fi
else
echo "Error: Failed to download genkit-$platform"
exit 1
fi
else
echo "[DRY RUN] Would download: genkit-$platform"
fi
done
elif [[ -n "$GITHUB_TAG" ]]; then
echo "Downloading artifacts from GitHub release tag: $GITHUB_TAG"
# Download release assets
for platform in "${PLATFORMS[@]}"; do
# Determine file extension
if [[ "$platform" == "win32-x64" ]]; then
ext=".exe"
else
ext=""
fi
echo "Downloading release asset: genkit-$platform$ext"
if [[ "$DRY_RUN" == "false" ]]; then
gh release download "$GITHUB_TAG" -p "genkit-$platform$ext" -R firebase/genkit || {
echo "Error: Failed to download genkit-$platform$ext"
exit 1
}
else
echo "[DRY RUN] Would download: genkit-$platform$ext"
fi
done
fi
# Upload to GCS
echo ""
echo "Uploading binaries to GCS..."
for platform in "${PLATFORMS[@]}"; do
# Determine file extension and names
if [[ "$platform" == "win32-x64" ]]; then
ext=".exe"
binary_name="genkit.exe"
latest_name="latest.exe"
else
ext=""
binary_name="genkit"
latest_name="latest"
fi
source_file="genkit-$platform$ext"
# Check if file exists
if [[ ! -f "$source_file" ]]; then
echo "Error: $source_file not found, skipping..."
exit 1
fi
versioned_path="gs://$BUCKET/$CHANNEL/$platform/v$VERSION/$binary_name"
# Check if versioned file already exists.
if [[ "$DRY_RUN" == "false" ]]; then
if gcloud storage objects list --stat --fetch-encrypted-object-hashes "$versioned_path" >/dev/null 2>&1; then
echo "Version $VERSION for $platform already exists in GCS, skipping upload."
continue
fi
fi
# Upload versioned binary
echo "Uploading $source_file to $versioned_path"
if [[ "$DRY_RUN" == "false" ]]; then
gcloud storage cp --cache-control="public, max-age=3600" "$source_file" "$versioned_path"
else
echo "[DRY RUN] Would upload to: $versioned_path"
fi
# Upload/copy as latest
latest_path="gs://$BUCKET/$CHANNEL/$platform/$latest_name"
echo "Copying to $latest_path"
if [[ "$DRY_RUN" == "false" ]]; then
gcloud storage cp --cache-control="public, max-age=300" "$source_file" "$latest_path"
else
echo "[DRY RUN] Would copy to: $latest_path (overwriting)"
fi
echo ""
done
echo "=== Promotion complete ==="
echo "Run update_cli_metadata.sh to update the metadata files."