Skip to content

Commit c390f63

Browse files
authored
Merge pull request #18878 from ivanvc/release-3.4-backport-18649
[3.4] release: use GitHub's gh to create GitHub release
2 parents 4d43129 + 2ab26de commit c390f63

File tree

3 files changed

+184
-9
lines changed

3 files changed

+184
-9
lines changed

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
Name-Email: [email protected]
2727
Expire-Date: 0
2828
EOF
29-
DRY_RUN=true ./scripts/release.sh --no-upload --no-docker-push --in-place 3.4.99
29+
DRY_RUN=true ./scripts/release.sh --no-upload --no-docker-push --no-gh-release --in-place 3.4.99
3030
- name: test-image
3131
run: |
3232
VERSION=3.4.99 ./scripts/test_images.sh

scripts/release.sh

Lines changed: 92 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ help() {
1515
echo "WARNING: This does not perform the 'Add API capabilities', 'Performance testing' "
1616
echo " or 'Documentation' steps. These steps must be performed manually BEFORE running this tool."
1717
echo ""
18-
echo "WARNING: This script does not sign releases, publish releases to github or sent announcement"
19-
echo " emails. These steps must be performed manually AFTER running this tool."
18+
echo "WARNING: This script does not send announcement emails. This step must be performed manually AFTER running this tool."
2019
echo ""
2120
echo " args:"
2221
echo " version: version of etcd to release, e.g. '3.2.18'"
2322
echo " flags:"
24-
echo " --no-upload: skip gs://etcd binary artifact uploads."
25-
echo " --no-docker-push: skip docker image pushes."
2623
echo " --in-place: build binaries using current branch."
24+
echo " --no-docker-push: skip docker image pushes."
25+
echo " --no-gh-release: skip creating the GitHub release using gh."
26+
echo " --no-upload: skip gs://etcd binary artifact uploads."
2727
echo ""
2828
}
2929

@@ -92,6 +92,21 @@ main() {
9292
exit 1
9393
fi
9494

95+
if [ "${NO_GH_RELEASE}" == 1 ]; then
96+
echo "Skipping gh verification, --no-gh-release is set"
97+
else
98+
# Check that gh is installed and logged in.
99+
echo "Check gh installation"
100+
if ! command -v gh >/dev/null; then
101+
log_error "Cannot find gh. Please follow the installation instructions at https://github.com/cli/cli#installation"
102+
exit 1
103+
fi
104+
if ! gh auth status &>/dev/null; then
105+
log_error "GitHub authentication failed for gh. Please run gh auth login."
106+
exit 1
107+
fi
108+
fi
109+
95110
# If the release tag does not already exist remotely, create it.
96111
log_callout "Create tag if not present"
97112
if [ "${remote_tag_exists}" -eq 0 ]; then
@@ -285,10 +300,74 @@ main() {
285300
exit 1
286301
fi
287302

288-
# TODO: signing process
289-
log_warning ""
290-
log_warning "WARNING: The release has not been signed and published to github. This must be done manually."
291-
log_warning ""
303+
if [ "${DRY_RUN}" == "true" ] || [ "${NO_GH_RELEASE}" == 1 ]; then
304+
log_warning ""
305+
log_warning "WARNING: Skipping creating GitHub release, --no-gh-release is set."
306+
log_warning "WARNING: If not running on DRY_MODE, please do the GitHub release manually."
307+
log_warning ""
308+
else
309+
local gh_repo
310+
local release_notes_temp_file
311+
local release_url
312+
local gh_release_args=()
313+
314+
# For the main branch (v3.6), we should mark the release as a prerelease.
315+
# The release-3.5 (v3.5) branch, should be marked as latest. And release-3.4 (v3.4)
316+
# should be left without any additional mark (therefore, it doesn't need a special argument).
317+
if [ "${BRANCH}" = "main" ]; then
318+
gh_release_args=(--prerelease)
319+
elif [ "${BRANCH}" = "release-3.5" ]; then
320+
gh_release_args=(--latest)
321+
fi
322+
323+
if [ "${REPOSITORY}" = "$(pwd)" ]; then
324+
gh_repo=$(git remote get-url origin)
325+
else
326+
gh_repo="${REPOSITORY}"
327+
fi
328+
329+
gh_repo=$(echo "${gh_repo}" | sed 's/^[^@]\+@//' | sed 's/https\?:\/\///' | sed 's/\.git$//' | tr ':' '/')
330+
log_callout "Creating GitHub release for ${RELEASE_VERSION} on ${gh_repo}"
331+
332+
release_notes_temp_file=$(mktemp)
333+
334+
local release_version=${RELEASE_VERSION#v} # Remove the v prefix from the release version (i.e., v3.6.1 -> 3.6.1)
335+
local release_version_major_minor=${release_version%.*} # Remove the patch from the version (i.e., 3.6)
336+
local release_version_major=${release_version_major_minor%.*} # Extract the major (i.e., 3)
337+
local release_version_minor=${release_version_major_minor/*./} # Extract the minor (i.e., 6)
338+
339+
# Disable sellcheck SC2016, the single quoted syntax for sed is intentional.
340+
# shellcheck disable=SC2016
341+
sed 's/${RELEASE_VERSION}/'"${RELEASE_VERSION}"'/g' ./scripts/release_notes.tpl.txt |
342+
sed 's/${RELEASE_VERSION_MAJOR_MINOR}/'"${release_version_major_minor}"'/g' |
343+
sed 's/${RELEASE_VERSION_MAJOR}/'"${release_version_major}"'/g' |
344+
sed 's/${RELEASE_VERSION_MINOR}/'"${release_version_minor}"'/g' > "${release_notes_temp_file}"
345+
346+
# This condition may seem redundant because of the previous check, but it's
347+
# necessary because release-3.4 doesn't have the maybe_run function.
348+
if [ "${DRY_RUN}" == "false" ]; then
349+
if ! gh --repo "${gh_repo}" release view "${RELEASE_VERSION}" &>/dev/null; then
350+
gh release create "${RELEASE_VERSION}" \
351+
--repo "${gh_repo}" \
352+
--draft \
353+
--title "${RELEASE_VERSION}" \
354+
--notes-file "${release_notes_temp_file}" \
355+
"${gh_release_args[@]}"
356+
fi
357+
358+
# Upload files one by one, as gh doesn't support passing globs as input.
359+
find ./release '(' -name '*.tar.gz' -o -name '*.zip' ')' -exec \
360+
gh --repo "${gh_repo}" release upload "${RELEASE_VERSION}" {} --clobber \;
361+
gh --repo "${gh_repo}" release upload "${RELEASE_VERSION}" ./release/SHA256SUMS --clobber
362+
363+
release_url=$(gh --repo "${gh_repo}" release view "${RELEASE_VERSION}" --json url --jq '.url')
364+
365+
log_warning ""
366+
log_warning "WARNING: The GitHub release for ${RELEASE_VERSION} has been created as a draft, please go to ${release_url} and release it."
367+
log_warning ""
368+
fi
369+
fi
370+
292371
log_success "Success."
293372
exit 0
294373
}
@@ -297,6 +376,7 @@ POSITIONAL=()
297376
NO_UPLOAD=0
298377
NO_DOCKER_PUSH=0
299378
IN_PLACE=0
379+
NO_GH_RELEASE=0
300380

301381
while test $# -gt 0; do
302382
case "$1" in
@@ -317,6 +397,10 @@ while test $# -gt 0; do
317397
NO_DOCKER_PUSH=1
318398
shift
319399
;;
400+
--no-gh-release)
401+
NO_GH_RELEASE=1
402+
shift
403+
;;
320404
*)
321405
POSITIONAL+=("$1") # save it in an array for later
322406
shift # past argument

scripts/release_notes.tpl.txt

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
Please check out [CHANGELOG](https://github.com/etcd-io/etcd/blob/main/CHANGELOG/CHANGELOG-${RELEASE_VERSION_MAJOR_MINOR}.md) for a full list of changes. And make sure to read [upgrade guide](https://etcd.io/docs/v${RELEASE_VERSION_MAJOR_MINOR}/upgrades/upgrade_${RELEASE_VERSION_MAJOR}_${RELEASE_VERSION_MINOR}/) before upgrading etcd (there may be breaking changes).
2+
3+
For installation guides, please check out [play.etcd.io](http://play.etcd.io) and [operating etcd](https://etcd.io/docs/v${RELEASE_VERSION_MAJOR_MINOR}/op-guide/). Latest support status for common architectures and operating systems can be found at [supported platforms](https://etcd.io/docs/v${RELEASE_VERSION_MAJOR_MINOR}/op-guide/supported-platform/).
4+
5+
###### Linux
6+
7+
```sh
8+
ETCD_VER=${RELEASE_VERSION}
9+
10+
# choose either URL
11+
GOOGLE_URL=https://storage.googleapis.com/etcd
12+
GITHUB_URL=https://github.com/etcd-io/etcd/releases/download
13+
DOWNLOAD_URL=${GOOGLE_URL}
14+
15+
rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
16+
rm -rf /tmp/etcd-download-test && mkdir -p /tmp/etcd-download-test
17+
18+
curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
19+
tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/etcd-download-test --strip-components=1
20+
rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
21+
22+
/tmp/etcd-download-test/etcd --version
23+
/tmp/etcd-download-test/etcdctl version
24+
/tmp/etcd-download-test/etcdutl version
25+
26+
# start a local etcd server
27+
/tmp/etcd-download-test/etcd
28+
29+
# write,read to etcd
30+
/tmp/etcd-download-test/etcdctl --endpoints=localhost:2379 put foo bar
31+
/tmp/etcd-download-test/etcdctl --endpoints=localhost:2379 get foo
32+
```
33+
34+
###### macOS (Darwin)
35+
36+
```sh
37+
ETCD_VER=${RELEASE_VERSION}
38+
39+
# choose either URL
40+
GOOGLE_URL=https://storage.googleapis.com/etcd
41+
GITHUB_URL=https://github.com/etcd-io/etcd/releases/download
42+
DOWNLOAD_URL=${GOOGLE_URL}
43+
44+
rm -f /tmp/etcd-${ETCD_VER}-darwin-amd64.zip
45+
rm -rf /tmp/etcd-download-test && mkdir -p /tmp/etcd-download-test
46+
47+
curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-darwin-amd64.zip -o /tmp/etcd-${ETCD_VER}-darwin-amd64.zip
48+
unzip /tmp/etcd-${ETCD_VER}-darwin-amd64.zip -d /tmp && rm -f /tmp/etcd-${ETCD_VER}-darwin-amd64.zip
49+
mv /tmp/etcd-${ETCD_VER}-darwin-amd64/* /tmp/etcd-download-test && rm -rf mv /tmp/etcd-${ETCD_VER}-darwin-amd64
50+
51+
/tmp/etcd-download-test/etcd --version
52+
/tmp/etcd-download-test/etcdctl version
53+
/tmp/etcd-download-test/etcdutl version
54+
```
55+
56+
###### Docker
57+
58+
etcd uses [`gcr.io/etcd-development/etcd`](https://gcr.io/etcd-development/etcd) as a primary container registry, and [`quay.io/coreos/etcd`](https://quay.io/coreos/etcd) as secondary.
59+
60+
```sh
61+
ETCD_VER=${RELEASE_VERSION}
62+
63+
rm -rf /tmp/etcd-data.tmp && mkdir -p /tmp/etcd-data.tmp && \
64+
docker rmi gcr.io/etcd-development/etcd:${ETCD_VER} || true && \
65+
docker run \
66+
-p 2379:2379 \
67+
-p 2380:2380 \
68+
--mount type=bind,source=/tmp/etcd-data.tmp,destination=/etcd-data \
69+
--name etcd-gcr-${ETCD_VER} \
70+
gcr.io/etcd-development/etcd:${ETCD_VER} \
71+
/usr/local/bin/etcd \
72+
--name s1 \
73+
--data-dir /etcd-data \
74+
--listen-client-urls http://0.0.0.0:2379 \
75+
--advertise-client-urls http://0.0.0.0:2379 \
76+
--listen-peer-urls http://0.0.0.0:2380 \
77+
--initial-advertise-peer-urls http://0.0.0.0:2380 \
78+
--initial-cluster s1=http://0.0.0.0:2380 \
79+
--initial-cluster-token tkn \
80+
--initial-cluster-state new \
81+
--log-level info \
82+
--logger zap \
83+
--log-outputs stderr
84+
85+
docker exec etcd-gcr-${ETCD_VER}/usr/local/bin/etcd --version
86+
docker exec etcd-gcr-${ETCD_VER}/usr/local/bin/etcdctl version
87+
docker exec etcd-gcr-${ETCD_VER}/usr/local/bin/etcdutl version
88+
docker exec etcd-gcr-${ETCD_VER}/usr/local/bin/etcdctl endpoint health
89+
docker exec etcd-gcr-${ETCD_VER}/usr/local/bin/etcdctl put foo bar
90+
docker exec etcd-gcr-${ETCD_VER}/usr/local/bin/etcdctl get foo
91+
```

0 commit comments

Comments
 (0)