From 4ba5fb303e9264b3b23fcaf8d11053e756892b1f Mon Sep 17 00:00:00 2001 From: cuisongliu Date: Mon, 30 Sep 2024 23:08:34 +0800 Subject: [PATCH] fix release for new --- .github/workflows/update_version_config.yml | 4 +- Makefile | 12 ++--- gen.go | 60 +++++++++++++++++++++ 3 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 gen.go diff --git a/.github/workflows/update_version_config.yml b/.github/workflows/update_version_config.yml index 3c545ee..c7b1805 100644 --- a/.github/workflows/update_version_config.yml +++ b/.github/workflows/update_version_config.yml @@ -18,10 +18,10 @@ jobs: run: | cat << EOF > .tagpr [tagpr] - vPrefix = false + vPrefix = true releaseBranch = main versionFile = .tagpr,Makefile,deploy/charts/automq-operator/Chart.yaml - command = IMG=ghcr.io/cuisongliu/automq-operator:v${{ github.event.inputs.version }} VERSION=${{ github.event.inputs.version }} make pre-deploy + command = go run gen.go ghcr.io/cuisongliu/automq-operator:${{ github.event.inputs.version }} && make check release = false changelog = true EOF diff --git a/Makefile b/Makefile index 0558e90..192ba5d 100644 --- a/Makefile +++ b/Makefile @@ -167,11 +167,7 @@ $(ENVTEST): $(LOCALBIN) crd: manifests kustomize ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. @cp -rf config/crd/bases/* deploy/charts/automq-operator/crds/ -VERSION ?= v0.0.1 -.PHONY: pre-deploy -pre-deploy: - @mkdir -p deploy/images/shim - @rm -f deploy/images/shim/image.txt - @echo "${IMG}" > deploy/images/shim/image.txt - @sed -i '/#replace_by_makefile/!b;n;c\image: ${IMG}' deploy/charts/automq-operator/values.yaml - @sed -i '/#replace_by_makefile/!b;n;c\version: ${VERSION}' deploy/charts/automq-operator/Chart.yaml +info: + @cat deploy/charts/automq-operator/values.yaml + @cat deploy/charts/automq-operator/Chart.yaml + @cat deploy/images/shim/image.txt diff --git a/gen.go b/gen.go new file mode 100644 index 0000000..947e60a --- /dev/null +++ b/gen.go @@ -0,0 +1,60 @@ +/* +Copyright 2023 cuisongliu@qq.com. + +Licensed 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. +*/ + +package main + +import ( + "fmt" + "os" + "os/exec" + "strings" +) + +func main() { + if len(os.Args) != 1 { + fmt.Printf("Usage: %s IMAGE_NAME\n", os.Args[0]) + os.Exit(1) + } + imageName := os.Args[1] + fmt.Printf("image name is %s", imageName) + _ = os.MkdirAll("deploy/images/shim", 0755) + _ = os.WriteFile("deploy/images/shim/image.txt", []byte(imageName), 0755) + cmd1 := fmt.Sprintf("sed -i '/#replace_by_makefile/!b;n;c\\image: %s' deploy/charts/automq-operator/values.yaml", imageName) + if err := execCmd("bash", "-c", cmd1); err != nil { + fmt.Printf("execCmd error %v", err) + os.Exit(1) + } + version := strings.Split(imageName, ":") + if len(version) != 2 { + fmt.Printf("image name error") + os.Exit(1) + } + shotVersion := strings.ReplaceAll(version[1], "v", "") + cmd2 := fmt.Sprintf("sed -i '/#replace_by_makefile/!b;n;c\\version: %s' deploy/charts/automq-operator/Chart.yaml", shotVersion) + if err := execCmd("bash", "-c", cmd2); err != nil { + fmt.Printf("execCmd error %v", err) + os.Exit(1) + } +} + +func execCmd(command string, args ...string) error { + cmd := exec.Command(command, args...) + cmd.Stdin = os.Stdin + cmd.Stderr = os.Stderr + cmd.Stdout = os.Stdout + + return cmd.Run() +}