-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdeploy-ci-version.sh
More file actions
executable file
·73 lines (57 loc) · 2.63 KB
/
deploy-ci-version.sh
File metadata and controls
executable file
·73 lines (57 loc) · 2.63 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
#!/bin/bash
# Copyright 2025 Adobe. All rights reserved.
# This file is licensed to you 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 REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
set -e
ENVIRONMENT="ci"
# Prepare version and capture version
echo "Preparing version for environment: $ENVIRONMENT"
VERSION=$(node prepare-deploy.js)
if [ -z "$VERSION" ]; then
echo "Error: Failed to get version from prepare-deploy.js"
exit 1
fi
# Get current git branch name
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ -z "$BRANCH" ]; then
echo "Error: Failed to get git branch name"
exit 1
fi
echo "Creating version: $VERSION from branch: $BRANCH"
# Deploy with branch tag and version message and capture output
# wrangler deploy -e "$ENVIRONMENT" -c wrangler-versioned.toml --message "v$VERSION" --tag "$BRANCH"
OUTPUT=$(wrangler versions upload -e "$ENVIRONMENT" -c wrangler-versioned.toml --message "$ENVIRONMENT: v$VERSION - branch: $BRANCH" --tag "$BRANCH" 2>&1)
# Display the output
echo "$OUTPUT"
# Parse the deployment information
WORKER_VERSION_ID=$(echo "$OUTPUT" | grep "Worker Version ID:" | sed 's/.*Worker Version ID: //')
WORKER_PREVIEW_URL=$(echo "$OUTPUT" | grep "Version Preview URL:" | sed 's/.*Version Preview URL: //')
# Write to a file that can be sourced (for local use)
cat > .deployment-env << EOF
export WORKER_VERSION_ID="$WORKER_VERSION_ID"
export WORKER_PREVIEW_URL="$WORKER_PREVIEW_URL"
export WORKER_PREVIEW_BRANCH="$BRANCH"
EOF
# If running in GitHub Actions, also write to GITHUB_ENV
if [ -n "$GITHUB_ENV" ]; then
echo "WORKER_VERSION_ID=$WORKER_VERSION_ID" >> "$GITHUB_ENV"
echo "WORKER_PREVIEW_URL=$WORKER_PREVIEW_URL" >> "$GITHUB_ENV"
echo "WORKER_PREVIEW_BRANCH=$BRANCH" >> "$GITHUB_ENV"
echo "Variables exported to GitHub Actions environment"
fi
# Deploy the version
wrangler versions deploy -y -e ci --version-id "$WORKER_VERSION_ID"
echo ""
echo "Version deployment complete!"
echo "----------------------------------------"
echo "Deployment information: (copy inside a .deployment-env file to run locally)"
echo "export WORKER_VERSION_ID=$WORKER_VERSION_ID"
echo "export WORKER_PREVIEW_URL=$WORKER_PREVIEW_URL"
echo "export WORKER_PREVIEW_BRANCH=$BRANCH"
echo "----------------------------------------"