diff --git a/.github/workflows/artifact-delete.yml b/.github/workflows/artifact-delete.yml new file mode 100644 index 00000000..356bac04 --- /dev/null +++ b/.github/workflows/artifact-delete.yml @@ -0,0 +1,31 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name: artifact-delete +on: + pull_request: + types: [closed] + +permissions: + id-token: write # This is required for requesting the JWT + contents: read # This is required for actions/checkout + +jobs: + artifact-delete: + uses: StackAdapt/actions/.github/workflows/stargate-delete.yml@main + with: + component: kvrocks-controller + branch: ${{ github.head_ref }} diff --git a/.github/workflows/artifact-upload.yml b/.github/workflows/artifact-upload.yml new file mode 100644 index 00000000..384fc079 --- /dev/null +++ b/.github/workflows/artifact-upload.yml @@ -0,0 +1,56 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name: artifact-upload +on: + pull_request: + types: [opened, synchronize] +permissions: + id-token: write # This is required for requesting the JWT + contents: read # This is required for actions/checkout +jobs: + artifact-upload-server: + if: "!contains(github.event.pull_request.labels.*.name, 'skip-kvrocks-controller-upload')" + strategy: # If you only need 1 architecture, remove this matrix strategy and directly pass in the architecture + matrix: + architecture: [amd64, arm64] + uses: StackAdapt/actions/.github/workflows/stargate-upload.yml@main + with: + component: kvrocks-controller + binary-name: kvctl-server + branch: ${{ github.head_ref }} + commit: ${{ github.event.pull_request.head.sha }} + architecture: ${{ matrix.architecture }} + make-command: server + output-dir: cmd/server + secrets: + action-token: ${{ secrets.GO_PRIVATE_MODULES }} + artifact-upload-client: + if: "!contains(github.event.pull_request.labels.*.name, 'skip-kvrocks-controller-upload')" + strategy: # If you only need 1 architecture, remove this matrix strategy and directly pass in the architecture + matrix: + architecture: [amd64, arm64] + uses: StackAdapt/actions/.github/workflows/stargate-upload.yml@main + with: + component: kvrocks-controller + binary-name: kvctl + branch: ${{ github.head_ref }} + commit: ${{ github.event.pull_request.head.sha }} + architecture: ${{ matrix.architecture }} + make-command: client + output-dir: cmd/client + secrets: + action-token: ${{ secrets.GO_PRIVATE_MODULES }} diff --git a/.github/workflows/tags.yml b/.github/workflows/tags.yml new file mode 100644 index 00000000..495ded9a --- /dev/null +++ b/.github/workflows/tags.yml @@ -0,0 +1,71 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name: tags +on: + push: + branches: + - main + +permissions: + contents: write + id-token: write # This is required for requesting the JWT + +jobs: + tag: + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.tag_version.outputs.new_tag }} + steps: + - uses: actions/checkout@v3 + - name: Bump version and push tag + id: tag_version + uses: StackAdapt/github-tag-action@v6.1 + with: + release_branches: main + github_token: ${{ secrets.GITHUB_TOKEN }} + + artifact-upload-server: + needs: [tag] + strategy: # If you only need 1 architecture, remove this matrix strategy and directly pass in the architecture + matrix: + architecture: [amd64, arm64] + uses: StackAdapt/actions/.github/workflows/stargate-upload.yml@main + with: + component: kvrocks-controller + binary-name: kvctl-server + tag: ${{ needs.tag.outputs.tag }} + architecture: ${{ matrix.architecture }} + output-dir: cmd/server + make-command: server + secrets: + action-token: ${{ secrets.GO_PRIVATE_MODULES }} + + artifact-upload-client: + needs: [tag] + strategy: # If you only need 1 architecture, remove this matrix strategy and directly pass in the architecture + matrix: + architecture: [amd64, arm64] + uses: StackAdapt/actions/.github/workflows/stargate-upload.yml@main + with: + component: kvrocks-controller + binary-name: kvctl + tag: ${{ needs.tag.outputs.tag }} + architecture: ${{ matrix.architecture }} + output-dir: cmd/client + make-command: client + secrets: + action-token: ${{ secrets.GO_PRIVATE_MODULES }} diff --git a/.gitignore b/.gitignore index cbdc5ea8..91d89795 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,5 @@ cmd/server/kvrocks_controller .kc_cli_history .vscode/ vendor +cmd/client/kvctl +cmd/server/kvctl-server diff --git a/Makefile b/Makefile index ac15bee7..98bcf014 100644 --- a/Makefile +++ b/Makefile @@ -21,11 +21,16 @@ CCCOLOR="\033[37;1m" MAKECOLOR="\033[32;1m" ENDCOLOR="\033[0m" +GOARCH ?= $(shell go env GOARCH) +GOOS ?= $(shell go env GOOS) +VERSION =`cat ../../VERSION.txt` +GO_PROJECT =github.com/stackadapt/kvrocks-controller +LDFLAGS := $(LDFLAGS) -X main.commit=$(GIT_COMMIT)${GIT_DIRTY} -X main.branch=$(GIT_BRANCH) -X main.date=$(DATE) -X $(GO_PROJECT)/version.Version=$(VERSION) + all: $(PROGRAM) .PHONY: all - $(PROGRAM): @bash scripts/build.sh @echo "" @@ -46,3 +51,11 @@ test: lint: @printf $(CCCOLOR)"GolangCI Lint...\n"$(ENDCOLOR) @golangci-lint run + +.PHONY: client +client: + cd cmd/client; CGO_ENABLED=0 GOARCH=$(GOARCH) GOOS=$(GOOS) go build -v -ldflags "$(LDFLAGS)" -o ./kvctl + +.PHONY: server +server: + cd cmd/server; CGO_ENABLED=0 GOARCH=$(GOARCH) GOOS=$(GOOS) go build -v -ldflags "$(LDFLAGS)" -o ./kvctl-server