From a0203c80d01ed50419c4a94cb0226fc5dc2d47a8 Mon Sep 17 00:00:00 2001 From: panshuai-ps Date: Wed, 29 May 2024 10:25:32 +0800 Subject: [PATCH] chore(ci): add pre release workflow with goreleaser --- .github/workflows/release.yaml | 22 ++++++- .goreleaser/alpha_or_beta_tag.yml | 63 +++++++++++++++++++ .../rc_or_release_tag.yml | 4 +- 3 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 .goreleaser/alpha_or_beta_tag.yml rename .goreleaser.yml => .goreleaser/rc_or_release_tag.yml (96%) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 7987377f..8e16dd50 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -4,10 +4,10 @@ name: Release on: push: tags: - - 'v[0-9]+.[0-9]+.[0-9]+' - 'v[0-9]+.[0-9]+.[0-9]+-alpha.[0-9]+' - 'v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+' - 'v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+' + - 'v[0-9]+.[0-9]+.[0-9]+' permissions: contents: write jobs: @@ -104,11 +104,29 @@ jobs: CI=false npm run build touch build/.gitkeep + - name: Determine GoReleaser Config with Regex + run: | + tag=${GITHUB_REF#refs/tags/} + alpha='v[0-9]+.[0-9]+.[0-9]+-alpha.[0-9]+' + beta='v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+' + rc='v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+' + release='v[0-9]+.[0-9]+.[0-9]+' + if [[ $tag =~ $alpha ]] || [[ $tag =~ $beta ]]; then + echo "Match found for alpha or beta tag" + echo "GO_RELEASER_CONFIG=alpha_or_beta_tag.yml" >> $GITHUB_ENV + elif [[ $tag =~ $rc ]] || [[ $tag =~ $release ]]; then + echo "Match found for rc or release tag" + echo "GO_RELEASER_CONFIG=rc_or_release_tag.yml" >> $GITHUB_ENV + else + echo "No match found" + exit 1 + fi + - name: Release the karpor with GoReleaser uses: goreleaser/goreleaser-action@v2 with: distribution: goreleaser version: latest - args: release --clean + args: release --clean --config .goreleaser/${{ env.GO_RELEASER_CONFIG }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser/alpha_or_beta_tag.yml b/.goreleaser/alpha_or_beta_tag.yml new file mode 100644 index 00000000..ca613e78 --- /dev/null +++ b/.goreleaser/alpha_or_beta_tag.yml @@ -0,0 +1,63 @@ +# Copyright The Karpor Authors. +# +# 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. + +# This is an example .goreleaser.yml file with some sane defaults. +# Make sure to check the documentation at http://goreleaser.com + +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + +builds: + - env: + - CGO_ENABLED=0 + # GOOS list to build for. + # For more info refer to: https://golang.org/doc/install/source#environment + # + # Default: [ 'darwin', 'linux', 'windows' ] + goos: + - linux + # - windows + - darwin + # GOARCH to build for. + # For more info refer to: https://golang.org/doc/install/source#environment + # + # Default: [ '386', 'amd64', 'arm64' ] + goarch: + - amd64 + - arm64 + # By using ldflags="-s -w", the symbol table and debug information are removed to decrease the size of the release package. + ldflags: + - -s -w + main: ./cmd/ + skip: true + +dockers: +- image_templates: + - 'kusionstack/{{ .ProjectName }}:{{ .Tag }}' + - 'kusionstack/{{ .ProjectName }}:latest' + dockerfile: Dockerfile + use: docker + build_flag_templates: + - "--pull" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.name={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + - "--label=org.opencontainers.image.source={{.GitURL}}" + - "--platform=linux/amd64" + extra_files: + - ui/ + - config/relationship.yaml diff --git a/.goreleaser.yml b/.goreleaser/rc_or_release_tag.yml similarity index 96% rename from .goreleaser.yml rename to .goreleaser/rc_or_release_tag.yml index 5ad7cc9a..67a6a376 100644 --- a/.goreleaser.yml +++ b/.goreleaser/rc_or_release_tag.yml @@ -14,6 +14,7 @@ # This is an example .goreleaser.yml file with some sane defaults. # Make sure to check the documentation at http://goreleaser.com + before: hooks: # You may remove this if you don't use go modules. @@ -36,7 +37,7 @@ builds: goarch: - amd64 - arm64 - # 使用 ldflags="-s -w" 去掉符号表和调试信息,以减少发布包的大小 + # By using ldflags="-s -w", the symbol table and debug information are removed to decrease the size of the release package. ldflags: - -s -w main: ./cmd/ @@ -119,6 +120,7 @@ release: * `kusionstack/karpor:{{ .Tag }}` ## Thanks! + prerelease: auto dockers: - image_templates: