-
Notifications
You must be signed in to change notification settings - Fork 268
Expand file tree
/
Copy pathcreate-github-release.sh
More file actions
executable file
·143 lines (112 loc) · 3.74 KB
/
create-github-release.sh
File metadata and controls
executable file
·143 lines (112 loc) · 3.74 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
# Copyright 2026 The Kubernetes Authors.
#
# 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.
# This script helps create GitHub releases from existing tags.
# Usage: ./tools/create-github-release.sh <tag> [draft]
set -euo pipefail
REPO="kubernetes/cloud-provider-gcp"
# Check if gh CLI is installed
if ! command -v gh &> /dev/null; then
echo "Error: gh CLI is not installed. Please install it first:"
echo " See: https://cli.github.com/"
exit 1
fi
# Check if authenticated
if ! gh auth status &> /dev/null; then
echo "Error: Not authenticated with GitHub. Please run 'gh auth login' first."
exit 1
fi
# Check arguments
if [ $# -lt 1 ]; then
echo "Usage: $0 <tag> [draft]"
echo ""
echo "Arguments:"
echo " tag - The git tag to create a release from (e.g., v35.0.8)"
echo " draft - Optional. If set to 'true', creates a draft release"
echo ""
echo "Examples:"
echo " $0 v35.0.8 # Create a published release for tag v35.0.8"
echo " $0 v35.0.8 true # Create a draft release for tag v35.0.8"
exit 1
fi
TAG="$1"
DRAFT="${2:-false}"
# Verify tag exists
if ! git rev-parse "$TAG" &> /dev/null; then
echo "Error: Tag '$TAG' does not exist locally."
echo "Please fetch tags first: git fetch --tags"
exit 1
fi
# Generate release notes
echo "Generating release notes for $TAG..."
# Get the previous tag for comparison
PREV_TAG=$(git tag -l 'v*' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | grep -B1 "^$TAG$" | head -1)
if [ -n "$PREV_TAG" ] && [ "$PREV_TAG" != "$TAG" ]; then
echo "Comparing with previous tag: $PREV_TAG"
CHANGES=$(git log "$PREV_TAG..$TAG" --pretty=format:"- %s" --no-merges 2>/dev/null || echo "No changes found")
else
echo "No previous tag found for comparison"
CHANGES=$(git log "$TAG" --pretty=format:"- %s" --no-merges -10 2>/dev/null || echo "No changes found")
fi
# Get tag message if annotated
TAG_MESSAGE=$(git tag -l --format='%(contents)' "$TAG" 2>/dev/null | head -5 || echo "")
# Create release notes
RELEASE_NOTES="## Release $TAG
"
if [ -n "$TAG_MESSAGE" ]; then
RELEASE_NOTES+="$TAG_MESSAGE
"
fi
RELEASE_NOTES+="### Changes
$CHANGES
### Artifacts
Release artifacts are available on the [releases page](https://github.com/$REPO/releases/tag/$TAG).
For container images, see the [container registry](https://console.cloud.google.com/gcr/images/k8s-staging-cloud-provider-gcp).
---
**Full Changelog**: https://github.com/$REPO/compare/${PREV_TAG:-$TAG}...$TAG
"
# Save release notes to temp file
NOTES_FILE=$(mktemp)
echo "$RELEASE_NOTES" > "$NOTES_FILE"
echo ""
echo "Release notes preview:"
echo "---"
cat "$NOTES_FILE"
echo "---"
echo ""
# Confirm before proceeding
read -p "Create release for $TAG? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborted."
rm "$NOTES_FILE"
exit 1
fi
# Create the release
echo "Creating release for $TAG..."
DRAFT_FLAG=""
if [ "$DRAFT" = "true" ]; then
DRAFT_FLAG="--draft"
echo "Creating as draft release..."
fi
gh release create "$TAG" \
--repo "$REPO" \
--title "Release $TAG" \
--notes-file "$NOTES_FILE" \
$DRAFT_FLAG
RELEASE_URL="https://github.com/$REPO/releases/tag/$TAG"
echo ""
echo "Release created successfully!"
echo "URL: $RELEASE_URL"
rm "$NOTES_FILE"