scripts: Integrate ./scripts/release with new code for tagging modules.

Changes:
  - signing tags.
  - allows to override BRANCH and REPOSITORY using env variables.

Tested by a release in my private fork:
  BRANCH="20201126-ptabor-release" REPOSITORY="git@github.com:ptabor/etcd.git" ./scripts/release 3.5.0-alpha.20
This commit is contained in:
Piotr Tabor
2020-11-27 11:11:09 +01:00
parent c95d9434f1
commit 577c898fee
12 changed files with 308 additions and 168 deletions

View File

@@ -2,97 +2,104 @@
set -e
source ./scripts/test_lib.sh
VER=$1
PROJ="etcd"
REPOSITORY="${REPOSITORY:-https://github.com/etcd-io/etcd}"
if [ -z "$1" ]; then
echo "Usage: ${0} VERSION" >> /dev/stderr
exit 255
echo "Usage: ${0} VERSION" >> /dev/stderr
exit 255
fi
set -u
function setup_env {
local proj=${1}
local ver=${2}
local ver=${1}
local proj=${2}
if [ ! -d "${proj}" ]; then
git clone https://github.com/etcd-io/"${proj}"
fi
if [ ! -d "${proj}" ]; then
run git clone "${REPOSITORY}"
fi
pushd "${proj}" >/dev/null
git checkout master
git fetch --all
git reset --hard origin/master
git checkout "${ver}"
popd >/dev/null
pushd "${proj}" >/dev/null
run git checkout master
run git fetch --all
git_assert_branch_in_sync || exit 2
run git checkout "${ver}"
git_assert_branch_in_sync || exit 2
popd >/dev/null
}
function package {
local target=${1}
local srcdir="${2}/bin"
local target=${1}
local srcdir="${2}/bin"
local ccdir="${srcdir}/${GOOS}_${GOARCH}"
if [ -d "${ccdir}" ]; then
srcdir="${ccdir}"
fi
local ext=""
if [ "${GOOS}" == "windows" ]; then
ext=".exe"
fi
for bin in etcd etcdctl; do
cp "${srcdir}/${bin}" "${target}/${bin}${ext}"
done
local ccdir="${srcdir}/${GOOS}_${GOARCH}"
if [ -d "${ccdir}" ]; then
srcdir="${ccdir}"
fi
local ext=""
if [ "${GOOS}" == "windows" ]; then
ext=".exe"
fi
for bin in etcd etcdctl; do
cp "${srcdir}/${bin}" "${target}/${bin}${ext}"
done
cp etcd/README.md "${target}"/README.md
cp etcd/etcdctl/README.md "${target}"/README-etcdctl.md
cp etcd/etcdctl/READMEv2.md "${target}"/READMEv2-etcdctl.md
cp etcd/README.md "${target}"/README.md
cp etcd/etcdctl/README.md "${target}"/README-etcdctl.md
cp etcd/etcdctl/READMEv2.md "${target}"/READMEv2-etcdctl.md
cp -R etcd/Documentation "${target}"/Documentation
cp -R etcd/Documentation "${target}"/Documentation
}
function main {
mkdir release
cd release
setup_env "${PROJ}" "${VER}"
local proj=$(echo "${REPOSITORY}" | sed 's|^.*/\([^/]*\)$|\1|g')
tarcmd=tar
if [[ $(go env GOOS) == "darwin" ]]; then
echo "Please use linux machine for release builds."
exit 1
fi
mkdir -p release
cd release
setup_env "${VER}" "${proj}"
for os in darwin windows linux; do
export GOOS=${os}
TARGET_ARCHS=("amd64")
tarcmd=tar
if [[ $(go env GOOS) == "darwin" ]]; then
echo "Please use linux machine for release builds."
exit 1
fi
if [ ${GOOS} == "linux" ]; then
TARGET_ARCHS+=("arm64")
TARGET_ARCHS+=("ppc64le")
TARGET_ARCHS+=("s390x")
fi
for os in darwin windows linux; do
export GOOS=${os}
TARGET_ARCHS=("amd64")
for TARGET_ARCH in "${TARGET_ARCHS[@]}"; do
export GOARCH=${TARGET_ARCH}
if [ ${GOOS} == "linux" ]; then
TARGET_ARCHS+=("arm64")
TARGET_ARCHS+=("ppc64le")
# TODO: Reenable when https://github.com/etcd-io/etcd/issues/12496 is fixed.
# TARGET_ARCHS+=("s390x")
fi
pushd etcd >/dev/null
GO_LDFLAGS="-s" ./build
popd >/dev/null
for TARGET_ARCH in "${TARGET_ARCHS[@]}"; do
export GOARCH=${TARGET_ARCH}
TARGET="etcd-${VER}-${GOOS}-${GOARCH}"
mkdir "${TARGET}"
package "${TARGET}" "${PROJ}"
pushd etcd >/dev/null
GO_LDFLAGS="-s" ./build
popd >/dev/null
if [ ${GOOS} == "linux" ]; then
${tarcmd} cfz "${TARGET}.tar.gz" "${TARGET}"
echo "Wrote release/${TARGET}.tar.gz"
else
zip -qr "${TARGET}.zip" "${TARGET}"
echo "Wrote release/${TARGET}.zip"
fi
done
done
TARGET="etcd-${VER}-${GOOS}-${GOARCH}"
mkdir "${TARGET}"
package "${TARGET}" "${proj}"
if [ ${GOOS} == "linux" ]; then
${tarcmd} cfz "${TARGET}.tar.gz" "${TARGET}"
echo "Wrote release/${TARGET}.tar.gz"
else
zip -qr "${TARGET}.zip" "${TARGET}"
echo "Wrote release/${TARGET}.zip"
fi
done
done
}
main