Skip to content

Commit 0e0696e

Browse files
authored
chore: add CI workflows for ob-operator cli tool (#570)
1 parent 9e71aae commit 0e0696e

File tree

5 files changed

+159
-16
lines changed

5 files changed

+159
-16
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ jobs:
3737
run: go build -o bin/manager cmd/operator/main.go
3838

3939
- name: go build oceanbase-dashboard
40-
run: go build -o bin/oceanbase-dashboard cmd/dashboard/main.go
40+
run: go build -o bin/oceanbase-dashboard cmd/dashboard/main.go
41+
42+
- name: go build oceanbase-cli
43+
run: go build -o bin/obocli cmd/cli/main.go
44+

.github/workflows/release-cli.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: release cli
2+
3+
on:
4+
push:
5+
tags:
6+
- "cli-[0-9]+.[0-9]+.[0-9]+"
7+
8+
env:
9+
tagName: ${{ github.ref_name }}
10+
GO_VERSION : "1.22"
11+
BinaryName: "obocli"
12+
13+
jobs:
14+
release-oceanbase-cli:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set Version variables
21+
id: set_version_vars
22+
run: |
23+
echo "version=$(echo $tagName | grep -P '(\d*\.\d*\.\d*)' --only-matching)" >> $GITHUB_OUTPUT
24+
25+
- name: Set up Go 1.x
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version: ${{ env.GO_VERSION }} # The Go version to download (if necessary) and use.
29+
30+
- name: go mod vendor
31+
run: go mod vendor
32+
33+
- run: ./scripts/create-cli-release.sh "${tag}"
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
tag: ${{ env.tagName }}
37+

internal/cli/generated/bindata/bindata.go

Lines changed: 5 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

make/cli.mk

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
11
##@ cli
22

3-
PROJECT=oceanbase-cli
4-
PROCESSOR=4
5-
PWD ?= $(shell pwd)
3+
BINARY_NAME ?= obocli
4+
CLI_VERSION ?= 0.1.0
5+
GOARCH ?=$(shell uname -m)
6+
GOOS ?= $(shell uname -s | tr LD ld)
7+
8+
# If GOARCH not specified, set GOARCH based on the detected architecture
9+
ifeq ($(GOARCH),x86_64)
10+
GOARCH = amd64
11+
else ifeq ($(GOARCH),aarch64)
12+
GOARCH = arm64
13+
endif
14+
15+
# build args
16+
CLI_BUILD := GO11MODULE=ON CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build
17+
18+
# build dir for obocli
19+
BUILD_DIR?=bin/
620

721
.PHONY: cli-build
8-
cli-build: cli-bindata-gen cli-dep-install # Build oceanbase-cli
9-
go build -o bin/obocli cmd/cli/main.go
22+
cli-build: cli-dep-install cli-bindata-gen # Build oceanbase-cli
23+
@echo "Building $(BINARY_NAME) for $(GOOS)/$(GOARCH)..."
24+
$(CLI_BUILD) -o $(BUILD_DIR)$(BINARY_NAME) cmd/cli/main.go
1025

1126
.PHONY: cli-bindata-gen
1227
cli-bindata-gen: # Generate bindata
1328
go-bindata -o internal/cli/generated/bindata/bindata.go -pkg bindata internal/assets/cli-templates/...
1429

1530
.PHONY: cli-clean
1631
cli-clean: # Clean build
17-
rm -rf bin/obocli
32+
rm -rf $(RELEASE_DIR)/$(BINARY_NAME)
1833
go clean -i ./...
1934

2035
.PHONY : cli-dep-install
2136
cli-dep-install: # Install oceanbase-cli deps
2237
go install github.com/spf13/cobra
2338
go install github.com/go-bindata/go-bindata/...@v3.1.2+incompatible
39+
2440
.PHONY : cli-run
2541
cli-run: ## Run oceanbase-cli in dev mode
26-
go run ./cmd/cli/main.go
27-
42+
go run -p 4 ./cmd/cli/main.go

scripts/create-cli-release.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
set -o errexit
3+
set -o nounset
4+
set -o pipefail
5+
6+
if [[ -z "${1-}" ]]; then
7+
echo "Usage: $0 TAG"
8+
echo "TAG: the tag to build or release, e.g. cli-0.0.1"
9+
exit 1
10+
fi
11+
12+
git_tag=$1
13+
echo "release tag: $git_tag"
14+
15+
# Build the release binaries for every OS/arch combination.
16+
# It builds compressed artifacts on $release_dir.
17+
function build_binary {
18+
binary_name="obocli"
19+
echo "build $binary_name binaries"
20+
version=$1
21+
22+
release_dir=$2
23+
echo "build release artifacts to $release_dir"
24+
25+
# Create tmp dir for make binaries
26+
mkdir -p "output"
27+
28+
# Note: windows not supported yet
29+
platforms=("linux" "darwin")
30+
arch_list=("amd64" "arm64")
31+
for os in "${platforms[@]}"; do
32+
for arch in "${arch_list[@]}"; do
33+
echo "Building $os-$arch"
34+
make cli-build GOOS=$os GOARCH=$arch BUILD_DIR=output/
35+
if [ $? -ne 0 ]; then
36+
echo "Build failed for $os-$arch"
37+
exit 1
38+
fi
39+
# Compress as tar.gz format
40+
tar cvfz "${release_dir}/${binary_name}_${version}_${os}_${arch}.tar.gz" -C output $binary_name
41+
rm output/$binary_name
42+
done
43+
done
44+
45+
# Create checksum.txt
46+
pushd "${release_dir}"
47+
for release in *; do
48+
echo "generate checksum: $release"
49+
sha256sum "$release" >>checksums.txt
50+
done
51+
popd
52+
53+
rmdir output
54+
}
55+
56+
function create_release {
57+
git_tag=$1
58+
59+
# This is expected to match $module.
60+
module=${git_tag%-*}
61+
62+
# This is the version of cli
63+
version=${git_tag##*-}
64+
65+
additional_release_artifacts_arg=""
66+
67+
# Build cli binaries for all supported platforms
68+
if [[ "$module" == "cli" ]]; then
69+
release_artifact_dir=$(mktemp -d)
70+
build_binary "$version" "$release_artifact_dir"
71+
72+
additional_release_artifacts_arg=("$release_artifact_dir"/*)
73+
74+
# Create github releases
75+
gh release create "$git_tag" \
76+
--title "$git_tag" \
77+
--notes "$git_tag" \
78+
--draft "${additional_release_artifacts_arg[@]}"
79+
80+
return
81+
fi
82+
83+
# Create github releases
84+
gh release create "$git_tag" \
85+
--title "$git_tag" \
86+
--draft
87+
}
88+
89+
create_release "$git_tag"

0 commit comments

Comments
 (0)