From b35b0cd298e7d82fbe3a8879d70cb91ee07a70e9 Mon Sep 17 00:00:00 2001 From: Sparkle <1284531+baurine@users.noreply.github.com> Date: Wed, 27 Dec 2023 15:33:27 +0800 Subject: [PATCH] chore: supply a script to update tidb-dashboard (#7610) close tikv/pd#7612 Signed-off-by: baurine <2008.hbl@gmail.com> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- build.ps1 | 19 -------------- scripts/dashboard-version | 3 +++ scripts/describe-dashboard.sh | 4 ++- scripts/embed-dashboard-ui.ps1 | 45 ---------------------------------- scripts/embed-dashboard-ui.sh | 2 +- scripts/update-dashboard.sh | 32 ++++++++++++++++++++++++ 6 files changed, 39 insertions(+), 66 deletions(-) delete mode 100644 build.ps1 create mode 100644 scripts/dashboard-version delete mode 100644 scripts/embed-dashboard-ui.ps1 create mode 100755 scripts/update-dashboard.sh diff --git a/build.ps1 b/build.ps1 deleted file mode 100644 index 2e54b17164e..00000000000 --- a/build.ps1 +++ /dev/null @@ -1,19 +0,0 @@ -# For `--version` -$PD_PKG = "github.com/tikv/pd" -$GO_LDFLAGS = "-X `"$PD_PKG/server.PDReleaseVersion=$(git describe --tags --dirty --always)`"" -$GO_LDFLAGS += " -X `"$PD_PKG/server.PDBuildTS=$(date -u '+%Y-%m-%d_%I:%M:%S')`"" -$GO_LDFLAGS += " -X `"$PD_PKG/server.PDGitHash=$(git rev-parse HEAD)`"" -$GO_LDFLAGS += " -X `"$PD_PKG/server.PDGitBranch=$(git rev-parse --abbrev-ref HEAD)`"" - -# Download Dashboard UI -powershell.exe -File ./scripts/embed-dashboard-ui.ps1 - -# Output binaries -go build -ldflags $GO_LDFLAGS -o bin/pd-server.exe cmd/pd-server/main.go -echo "bin/pd-server.exe" -go build -ldflags $GO_LDFLAGS -o bin/pd-ctl.exe tools/pd-ctl/main.go -echo "bin/pd-ctl.exe" -go build -o bin/pd-tso-bench.exe tools/pd-tso-bench/main.go -echo "bin/pd-tso-bench.exe" -go build -o bin/pd-recover.exe tools/pd-recover/main.go -echo "bin/pd-recover.exe" diff --git a/scripts/dashboard-version b/scripts/dashboard-version new file mode 100644 index 00000000000..8887b43cc78 --- /dev/null +++ b/scripts/dashboard-version @@ -0,0 +1,3 @@ +# This file is updated by running scripts/update-dashboard.sh +# Don't edit it manullay +2023.12.18.1 diff --git a/scripts/describe-dashboard.sh b/scripts/describe-dashboard.sh index 502a2a55266..5d474c81bae 100755 --- a/scripts/describe-dashboard.sh +++ b/scripts/describe-dashboard.sh @@ -14,7 +14,9 @@ DASHBOARD_DIR=$(go list -f "{{.Dir}}" -m github.com/pingcap/tidb-dashboard) if [ "$1" = "git-hash" ]; then echo "${DASHBOARD_DIR}" | awk -F- '{print $NF}' elif [ "$1" = "internal-version" ]; then - grep -v '^#' "${DASHBOARD_DIR}/release-version" + CUR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + BASE_DIR="$(dirname "$CUR_DIR")" + grep -v '^#' "$BASE_DIR/scripts/dashboard-version" else exit 1 fi diff --git a/scripts/embed-dashboard-ui.ps1 b/scripts/embed-dashboard-ui.ps1 deleted file mode 100644 index 53eb8453d6e..00000000000 --- a/scripts/embed-dashboard-ui.ps1 +++ /dev/null @@ -1,45 +0,0 @@ -$DIR = Split-Path -Parent $MyInvocation.MyCommand.Definition -$BASE_DIR = (get-item $DIR).parent.FullName -$CACHE_DIR = Join-Path($BASE_DIR) "\.dashboard_download_cache" - -echo '+ Create asset cache directory' - -mkdir -p $CACHE_DIR -Force | Out-Null - -echo '+ Fetch TiDB Dashboard Go module' -go mod download -go mod tidy - -echo '+ Discover TiDB Dashboard release version' - -$DASHBOARD_DIR=$(go list -f "{{.Dir}}" -m github.com/pingcap/tidb-dashboard) -echo " - Dashboard directory: $DASHBOARD_DIR" - -$DASHBOARD_RELEASE_VERSION= cat "${DASHBOARD_DIR}/release-version" | Select-String -Pattern "^#" -NotMatch -echo " - TiDB Dashboard release version: $DASHBOARD_RELEASE_VERSION" - -echo '+ Check embedded assets exists in cache' -$CACHE_FILE= Join-Path($CACHE_DIR) \embedded-assets-golang-${DASHBOARD_RELEASE_VERSION}.zip - -if (Test-Path "$CACHE_FILE" ){ - echo " - Cached archive exists: $CACHE_FILE" -} -else{ - echo ' - Cached archive does not exist' - echo ' - Download pre-built embedded assets from GitHub release' - $DOWNLOAD_URL="https://github.com/pingcap/tidb-dashboard/releases/download/v${DASHBOARD_RELEASE_VERSION}/embedded-assets-golang.zip" - $DOWNLOAD_FILE= Join-Path($CACHE_DIR) \embedded-assets-golang.zip - echo " - Download ${DOWNLOAD_URL}" - Invoke-WebRequest -Uri "${DOWNLOAD_URL}" -OutFile "${DOWNLOAD_FILE}" - - echo " - Save archive to cache: ${CACHE_FILE}" - mv "${DOWNLOAD_FILE}" "${CACHE_FILE}" -} - -echo '+ Unpack embedded asset from archive' -Expand-Archive -Path "${CACHE_FILE}" -DestinationPath "$CACHE_DIR" -Force -$MOVE_FILE="${CACHE_DIR}\embedded_assets_handler.go" -gofmt -s -w "$MOVE_FILE" -$MOVE_DEST="${BASE_DIR}\pkg\dashboard\uiserver" -move-item -path "${MOVE_FILE}" -destination "${MOVE_DEST}" -Force -echo " - Unpacked ${MOVE_DEST}" diff --git a/scripts/embed-dashboard-ui.sh b/scripts/embed-dashboard-ui.sh index 6ea9153d265..c5e28df9cb2 100755 --- a/scripts/embed-dashboard-ui.sh +++ b/scripts/embed-dashboard-ui.sh @@ -41,7 +41,7 @@ mkdir -p "${CACHE_DIR}" function download_embed_asset { echo '+ Discover TiDB Dashboard release version' - DASHBOARD_RELEASE_VERSION=$(grep -v '^#' "${DASHBOARD_DIR}/release-version") + DASHBOARD_RELEASE_VERSION=$(grep -v '^#' "${BASE_DIR}/scripts/dashboard-version") echo " - TiDB Dashboard release version: ${DASHBOARD_RELEASE_VERSION}" echo '+ Check whether pre-built assets are available' diff --git a/scripts/update-dashboard.sh b/scripts/update-dashboard.sh new file mode 100755 index 00000000000..ec7fbbc99f8 --- /dev/null +++ b/scripts/update-dashboard.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -euo pipefail + +CUR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +BASE_DIR="$(dirname "$CUR_DIR")" +DASHBOARD_VERSION_FILE="$BASE_DIR/scripts/dashboard-version" +# old version +DASHBOARD_VERSION=$(grep -v '^#' "$DASHBOARD_VERSION_FILE") + +# new version +# Usage: ./scripts/update-dashboard.sh +# Example: ./scripts/update-dashboard.sh 2023.12.18.1 +if [ "$#" -ge 1 ]; then + DASHBOARD_VERSION=$1 + echo $1 > $DASHBOARD_VERSION_FILE +fi + +echo "+ Update dashboard version to v$DASHBOARD_VERSION" + +cd $BASE_DIR + +go get -d github.com/pingcap/tidb-dashboard@v$DASHBOARD_VERSION +go mod tidy +make pd-server +go mod tidy + +cd tests/integrations/client +go mod tidy +cd ../mcs +go mod tidy +cd ../tso +go mod tidy