diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b42beb520..d6760facd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,4 +37,8 @@ jobs: run: go build -o bin/manager cmd/operator/main.go - name: go build oceanbase-dashboard - run: go build -o bin/oceanbase-dashboard cmd/dashboard/main.go \ No newline at end of file + run: go build -o bin/oceanbase-dashboard cmd/dashboard/main.go + + - name: go build oceanbase-cli + run: go build -o bin/obocli cmd/cli/main.go + \ No newline at end of file diff --git a/.github/workflows/release-cli.yml b/.github/workflows/release-cli.yml new file mode 100644 index 000000000..7c0e1e8b5 --- /dev/null +++ b/.github/workflows/release-cli.yml @@ -0,0 +1,37 @@ +name: release cli + +on: + push: + tags: + - "cli-[0-9]+.[0-9]+.[0-9]+" + +env: + tagName: ${{ github.ref_name }} + GO_VERSION : "1.22" + BinaryName: "obocli" + +jobs: + release-oceanbase-cli: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set Version variables + id: set_version_vars + run: | + echo "version=$(echo $tagName | grep -P '(\d*\.\d*\.\d*)' --only-matching)" >> $GITHUB_OUTPUT + + - name: Set up Go 1.x + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} # The Go version to download (if necessary) and use. + + - name: go mod vendor + run: go mod vendor + + - run: ./scripts/create-cli-release.sh "${tag}" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ env.tagName }} + \ No newline at end of file diff --git a/internal/cli/generated/bindata/bindata.go b/internal/cli/generated/bindata/bindata.go index d924357d9..39f8df169 100644 --- a/internal/cli/generated/bindata/bindata.go +++ b/internal/cli/generated/bindata/bindata.go @@ -156,13 +156,11 @@ var _bindata = map[string]func() (*asset, error){ // directory embedded in the file by go-bindata. // For example if you run go-bindata on data/... and data contains the // following hierarchy: -// -// data/ -// foo.txt -// img/ -// a.png -// b.png -// +// data/ +// foo.txt +// img/ +// a.png +// b.png // then AssetDir("data") would return []string{"foo.txt", "img"} // AssetDir("data/img") would return []string{"a.png", "b.png"} // AssetDir("foo.txt") and AssetDir("notexist") would return an error diff --git a/make/cli.mk b/make/cli.mk index a2270651d..b96c1943b 100644 --- a/make/cli.mk +++ b/make/cli.mk @@ -1,12 +1,27 @@ ##@ cli -PROJECT=oceanbase-cli -PROCESSOR=4 -PWD ?= $(shell pwd) +BINARY_NAME ?= obocli +CLI_VERSION ?= 0.1.0 +GOARCH ?=$(shell uname -m) +GOOS ?= $(shell uname -s | tr LD ld) + +# If GOARCH not specified, set GOARCH based on the detected architecture +ifeq ($(GOARCH),x86_64) + GOARCH = amd64 +else ifeq ($(GOARCH),aarch64) + GOARCH = arm64 +endif + +# build args +CLI_BUILD := GO11MODULE=ON CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build + +# build dir for obocli +BUILD_DIR?=bin/ .PHONY: cli-build -cli-build: cli-bindata-gen cli-dep-install # Build oceanbase-cli - go build -o bin/obocli cmd/cli/main.go +cli-build: cli-dep-install cli-bindata-gen # Build oceanbase-cli + @echo "Building $(BINARY_NAME) for $(GOOS)/$(GOARCH)..." + $(CLI_BUILD) -o $(BUILD_DIR)$(BINARY_NAME) cmd/cli/main.go .PHONY: cli-bindata-gen cli-bindata-gen: # Generate bindata @@ -14,14 +29,14 @@ cli-bindata-gen: # Generate bindata .PHONY: cli-clean cli-clean: # Clean build - rm -rf bin/obocli + rm -rf $(RELEASE_DIR)/$(BINARY_NAME) go clean -i ./... .PHONY : cli-dep-install cli-dep-install: # Install oceanbase-cli deps go install github.com/spf13/cobra go install github.com/go-bindata/go-bindata/...@v3.1.2+incompatible + .PHONY : cli-run cli-run: ## Run oceanbase-cli in dev mode - go run ./cmd/cli/main.go - + go run -p 4 ./cmd/cli/main.go diff --git a/scripts/create-cli-release.sh b/scripts/create-cli-release.sh new file mode 100755 index 000000000..df150de65 --- /dev/null +++ b/scripts/create-cli-release.sh @@ -0,0 +1,89 @@ +#!/bin/bash +set -o errexit +set -o nounset +set -o pipefail + +if [[ -z "${1-}" ]]; then + echo "Usage: $0 TAG" + echo "TAG: the tag to build or release, e.g. cli-0.0.1" + exit 1 +fi + +git_tag=$1 +echo "release tag: $git_tag" + +# Build the release binaries for every OS/arch combination. +# It builds compressed artifacts on $release_dir. +function build_binary { + binary_name="obocli" + echo "build $binary_name binaries" + version=$1 + + release_dir=$2 + echo "build release artifacts to $release_dir" + + # Create tmp dir for make binaries + mkdir -p "output" + + # Note: windows not supported yet + platforms=("linux" "darwin") + arch_list=("amd64" "arm64") + for os in "${platforms[@]}"; do + for arch in "${arch_list[@]}"; do + echo "Building $os-$arch" + make cli-build GOOS=$os GOARCH=$arch BUILD_DIR=output/ + if [ $? -ne 0 ]; then + echo "Build failed for $os-$arch" + exit 1 + fi + # Compress as tar.gz format + tar cvfz "${release_dir}/${binary_name}_${version}_${os}_${arch}.tar.gz" -C output $binary_name + rm output/$binary_name + done + done + + # Create checksum.txt + pushd "${release_dir}" + for release in *; do + echo "generate checksum: $release" + sha256sum "$release" >>checksums.txt + done + popd + + rmdir output +} + +function create_release { + git_tag=$1 + + # This is expected to match $module. + module=${git_tag%-*} + + # This is the version of cli + version=${git_tag##*-} + + additional_release_artifacts_arg="" + + # Build cli binaries for all supported platforms + if [[ "$module" == "cli" ]]; then + release_artifact_dir=$(mktemp -d) + build_binary "$version" "$release_artifact_dir" + + additional_release_artifacts_arg=("$release_artifact_dir"/*) + + # Create github releases + gh release create "$git_tag" \ + --title "$git_tag" \ + --notes "$git_tag" \ + --draft "${additional_release_artifacts_arg[@]}" + + return + fi + + # Create github releases + gh release create "$git_tag" \ + --title "$git_tag" \ + --draft +} + +create_release "$git_tag"