#! /bin/bashset -eSUDO=${SUDO-sudo}GITHUB_USER=${GITHUB_USER:-weaveworks}DOCKERHUB_USER=${DOCKERHUB_USER:-weaveworks}RELEASE_NAME=${RELEASE_NAME:-"Weave Scope"}RELEASE_DESCRIPTION=${RELEASE_DESCRIPTION:-"Container Visibility"}PWD=$(pwd)infer_release_type() {if echo "1ドル" | grep -qE '^v[0-9]+\.[0-9]+\.0+$'; thenecho MAINLINEelif echo "1ドル" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; thenecho BRANCHelseecho PRERELEASEfi}setup() {# Ensure we have exactly one annotated tag pointing at HEADHEAD_TAGS=$(git tag --points-at HEAD)# shellcheck disable=SC2116# shellcheck disable=SC2005TAG_COUNT=$(echo "$(echo "$HEAD_TAGS" | wc -w)") # mac hackif [ "$TAG_COUNT" -eq 1 ]; thenif [ "$HEAD_TAGS" != "latest_release" ]; thenLATEST_TAG=$HEAD_TAGSelseecho "Cannot determine version - latest_release points at HEAD" >&2exit 1fielif [ "$TAG_COUNT" -eq 0 ]; thenecho "Cannot determine version - no tags point at HEAD" >&2exit 1elseecho "Cannot determine version - multiple tags point at HEAD:" >&2for TAG in $HEAD_TAGS; doecho -e "\\t$TAG" >&2doneexit 1fiRELEASE_TYPE=$(infer_release_type "$LATEST_TAG")echo "== Inferred release type $RELEASE_TYPE from tag $LATEST_TAG"LATEST_TAG_SHA=$(git rev-parse "$LATEST_TAG")LATEST_TAG_COMMIT_SHA=$(git rev-list -1 "$LATEST_TAG")LATEST_RELEASE_SHA=$(git rev-parse latest_release)LATEST_RELEASE_COMMIT_SHA=$(git rev-list -1 latest_release)if [ "$RELEASE_TYPE" != 'PRERELEASE' ]; thenVERSION=${LATEST_TAG#v}elseVERSION=${LATEST_TAG}fi# NB does not check that this tag is on masterRELEASE_DIR=./releases/$LATEST_TAG}build() {setupecho "== Clone repo at $LATEST_TAG for version $VERSION"if [ -d "$RELEASE_DIR" ]; thenecho -e "\\u2757 Release directory $RELEASE_DIR already exists, you may want to" >&2echo -e "\\trm -rf $RELEASE_DIR" >&2exit 1fi## Clone the repo at the tag and go theremkdir -p releasesgit clone -q -b "$LATEST_TAG" . "$RELEASE_DIR" 2>/dev/nullcd "$RELEASE_DIR"## Check that the top changelog entry is this versionif ! latest_changelog=$(perl -nle'print $& if m{(?<=^## Release ).*}' ./CHANGELOG.md | head -1) \|| ! [ "$latest_changelog" = "$VERSION" ]; thenecho -e "\\u2757 Latest changelog entry \"$latest_changelog\" does not match the release version $VERSION" >&2exit 1fiechoecho "== Build and test"## Inject the version numbers and build the distributables## (library versions?)sed -i.tmp "s/SCRIPT_VERSION=\"[^\"]*\"/SCRIPT_VERSION=\"$VERSION\"/" ./scopemake SUDO="$SUDO" SCOPE_VERSION="$VERSION" DOCKERHUB_USER="$DOCKERHUB_USER" realclean allif make tests SUDO="$SUDO"; thenecho -e '\u2713 Tests pass'elseecho -e "\\u2757 Tests failed, probably best not publish this one" >&2exit 1fi## Run tests with the distributables, including version check#v=$(./scope version | grep -o '[0-9].*')#if ! [ "$v" == "$VERSION" ]; then# echo "Version of distributable "$v" does not match release version $VERSION" >&2# exit 1#fitag_imagesecho -e '\u2713 Build OK'echo '** Release artefacts in' "$RELEASE_DIR"}draft() {setupcd "$PWD"/"$RELEASE_DIR"echo "== Sanity checks"## Check that the tag exists by looking at githubif ! curl -sSf "https://api.github.com/repos/$GITHUB_USER/scope/git/tags/$LATEST_TAG_SHA" >/dev/null 2>&1; thenecho -e "\\u2757 Tag $LATEST_TAG is not on GitHub, or is not the same as the local tag" >&2echo -e "\\thttps://github.com/$GITHUB_USER/scope/tags" >&2echo "You may need to" >&2echo -e "\\tgit push git@github.com:$GITHUB_USER/scope $LATEST_TAG"exit 1fiecho -e "\\u2713 Tag $LATEST_TAG exists in GitHub repo $GITHUB_USER/scope"## Check that the version does not already exist by looking at github## releasesif github-release info --user "$GITHUB_USER" --repo scope --tag "$LATEST_TAG" >/dev/null 2>&1; thenecho -e "\\u2757 Release $LATEST_TAG already exists on GitHub" >&2echo -e "\\thttps://github.com/$GITHUB_USER/scope/releases/$LATEST_TAG" >&2exit 1fiecho '** Sanity checks OK for publishing tag' "$LATEST_TAG" as "$DOCKERHUB_USER/scope:$VERSION"RELEASE_ARGS="--draft"if [ "$RELEASE_TYPE" = 'PRERELEASE' ]; thenRELEASE_ARGS="$RELEASE_ARGS --pre-release"fiecho "== Creating GitHub release $RELEASE_ARGS$RELEASE_NAME$VERSION"github-release release "$RELEASE_ARGS" \--user "$GITHUB_USER" \--repo scope \--tag "$LATEST_TAG" \--name "$RELEASE_NAME$VERSION" \--description "$RELEASE_DESCRIPTION"github-release upload \--user "$GITHUB_USER" \--repo scope \--tag "$LATEST_TAG" \--name "scope" \--file "./scope"echo "** Draft $TYPE$RELEASE_NAME$VERSION created at"echo -e "\\thttps://github.com/$GITHUB_USER/scope/releases/$LATEST_TAG"}publish() {setupcd "$PWD"/"$RELEASE_DIR"if [ "$RELEASE_TYPE" = 'PRERELEASE' ]; thenpush_imagesecho "== Publishing pre-release on GitHub"github-release publish \--user "$GITHUB_USER" \--repo scope \--tag "$LATEST_TAG"echo "** Pre-release $RELEASE_NAME$VERSION published at"echo -e "\\thttps://github.com/$GITHUB_USER/scope/releases/$LATEST_TAG"elseecho "== Sanity checks"if ! [ "$LATEST_TAG_COMMIT_SHA" == "$LATEST_RELEASE_COMMIT_SHA" ]; thenecho -e "\\u2757 The tag latest_release does not point to the same commit as $LATEST_TAG" >&2echo "You may need to" >&2echo -e "\\tgit tag -af latest_release $LATEST_TAG" >&2exit 1fi## Check that the 'latest_release' tag exists by looking at githubif ! curl -sSf "https://api.github.com/repos/$GITHUB_USER/scope/git/tags/$LATEST_RELEASE_SHA" >/dev/null 2>&1; thenecho -e "\\u2757 Tag latest_release is not on GitHub, or is not the same as the local tag" >&2echo -e "\\thttps://github.com/$GITHUB_USER/scope/tags" >&2echo "You may need to" >&2echo -e "\\tgit push -f git@github.com:$GITHUB_USER/scope latest_release" >&2exit 1fiecho '** Sanity checks OK for publishing tag' "$LATEST_TAG" as "$DOCKERHUB_USER/scope:$VERSION"push_imagesecho "== Publishing release on GitHub"github-release publish \--user "$GITHUB_USER" \--repo scope \--tag "$LATEST_TAG"if github-release info --user "$GITHUB_USER" --repo scope \--tag latest_release >/dev/null 2>&1; thengithub-release delete \--user "$GITHUB_USER" \--repo scope \--tag latest_releasefigithub-release release \--user "$GITHUB_USER" \--repo scope \--tag latest_release \--name "$RELEASE_NAME latest ($VERSION)" \--description "[Release Notes](https://github.com/$GITHUB_USER/scope/releases/$LATEST_TAG)"github-release upload \--user "$GITHUB_USER" \--repo scope \--tag latest_release \--name "scope" \--file "./scope"echo "** Release $RELEASE_NAME$VERSION published at"echo -e "\\thttps://github.com/$GITHUB_USER/scope/releases/$LATEST_TAG"echo -e "\\thttps://github.com/$GITHUB_USER/scope/releases/latest_release"fi}tag_images() {echo "== Tagging images for docker hub as user $DOCKERHUB_USER"for IMAGE in "scope" "cloud-agent"; do$SUDO docker tag "$DOCKERHUB_USER/$IMAGE" "$DOCKERHUB_USER/$IMAGE:$VERSION"$SUDO docker tag "$DOCKERHUB_USER/$IMAGE:$VERSION" "$DOCKERHUB_USER/$IMAGE:latest_release"doneecho "** Docker images tagged"}push_images() {echo "== Pushing images on docker hub as user $DOCKERHUB_USER"for IMAGE in "scope" "cloud-agent"; do$SUDO docker push "$DOCKERHUB_USER/$IMAGE:$VERSION"$SUDO docker push "$DOCKERHUB_USER/$IMAGE:latest_release"doneecho "** Docker images pushed"}usage() {echo "Usage:"echo -e "\\t./bin/release build"echo "-- Build artefacts for the latest version tag"echo -e "\\t./bin/release draft"echo "-- Create draft release with artefacts in GitHub"echo -e "\\t./bin/release publish"echo "-- Publish the GitHub release and update DockerHub"exit 1}# Ensure required tooling is installedif ! command -v github-release >/dev/null; thenecho "Please install git-release:" >&2echo -e "\\tgo get github.com/weaveworks/github-release" >&2echo "and create a git token per https://github.com/weaveworks/github-release" >&2exit 1fi[ $# -eq 0 ] && usageCOMMAND=1ドルshiftcase "$COMMAND" inbuild)build "$@";;draft)draft "$@";;publish)publish "$@";;*)echo "Unknown command \"$COMMAND\""usage;;esac
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。