From e92cd0d0705332fdb36c1fcdbe9f25232eb8a553 Mon Sep 17 00:00:00 2001 From: KK <68334452+healthjyk@users.noreply.github.com> Date: Wed, 27 Dec 2023 17:46:01 +0800 Subject: [PATCH] feat: update the latest version when releasing formal version (#726) --- .github/workflows/release.yaml | 38 ++++++++++++++--- .goreleaser.yml | 22 ++++------ .goreleaser_informal.yml | 78 ++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 20 deletions(-) create mode 100644 .goreleaser_informal.yml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 5335d726..bfd1177a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -45,7 +45,7 @@ jobs: with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version version: v1.52.2 - Publish: # Pack and publish image to Docker Hub and Github Release + Publish: # Pack and publish image to Docker Hub and GitHub Release runs-on: ubuntu-latest needs: [Test, Lint] steps: @@ -57,7 +57,7 @@ jobs: uses: actions/setup-go@v2 with: go-version: 1.19 - # <--- Get version informations ---> + # Get version information - name: Get version id: get_version run: | @@ -66,19 +66,45 @@ jobs: echo "kclgo_version=$(cat version.txt | grep kclGoVersion | cut -d ':' -f 2 | awk '$1=$1')" >> $GITHUB_OUTPUT echo "kclplugin_version=$(cat version.txt | grep kclPluginVersion | cut -d ':' -f 2 | awk '$1=$1')" >> $GITHUB_OUTPUT rm version.txt - # <--- Login, build and push image to Docker Hub ---> + # Check formal version or not + - name: Check Formal Version + id: check_formal_version + run: | + VERSION_PATTERN="^[0-9]+\.[0-9]+\.[0-9]+$" + if [[ "${{ steps.get_version.outputs.kusion_version }}" =~ ${VERSION_PATTERN} ]]; then + echo "is_formal_version=true" >> $GITHUB_OUTPUT + echo "Release a formal version!" + else + echo "is_formal_version=false" >> $GITHUB_OUTPUT + echo "Release an informal version!" + fi + # Login to Docker Hub - name: Login to Docker Hub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - # <--- End ---> - - name: Run GoReleaser + # Run informal GoReleaser + - name: Run Informal GoReleaser + if: ${{ steps.check_formal_version.outputs.is_formal_version == 'false' }} + uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --config .goreleaser_formal.yml --clean + env: + GITHUB_TOKEN: ${{ secrets.KUSIONSTACK_BOT_TOKEN }} + KUSION_VERSION: ${{ steps.get_version.outputs.kusion_version }} + KCL_GO_VERSION: ${{ steps.get_version.outputs.kclgo_version }} + KCL_PLUGIN_VERSION: ${{ steps.get_version.outputs.kclplugin_version }} + # Run formal GoReleaser + - name: Run Formal GoReleaser + if: ${{ steps.check_formal_version.outputs.is_formal_version == 'true' }} uses: goreleaser/goreleaser-action@v4 with: distribution: goreleaser version: latest - args: release --rm-dist + args: release --clean env: GITHUB_TOKEN: ${{ secrets.KUSIONSTACK_BOT_TOKEN }} KUSION_VERSION: ${{ steps.get_version.outputs.kusion_version }} diff --git a/.goreleaser.yml b/.goreleaser.yml index 80b83177..3fee7444 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,10 +1,10 @@ -# This is an example .goreleaser.yml file with some sane defaults. -# Make sure to check the documentation at http://goreleaser.com +# For more information, check the documentation at http://goreleaser.com before: hooks: # You may remove this if you don't use go modules. - go mod tidy - go generate ./pkg/version + builds: - id: default env: @@ -16,7 +16,7 @@ builds: goarch: - amd64 - arm64 - # 使用 ldflags="-s -w" 去掉符号表和调试信息,以减少发布包的大小 + # ldflags="-s -w" removes the symbol table and debugging information to reduce the size of the release package ldflags: - -s - -w @@ -26,6 +26,7 @@ builds: - goos: windows goarch: arm64 main: . + archives: - id: default builds: @@ -34,8 +35,10 @@ archives: format_overrides: - goos: windows format: zip + checksum: name_template: 'checksums.txt' + changelog: use: github sort: asc @@ -63,7 +66,8 @@ dockers: goarch: amd64 dockerfile: Dockerfile image_templates: - - kusionstack/{{ .ProjectName }}:{{ .Tag }}-amd64 + - kusionstack/{{ .ProjectName }}:{{ .Tag }} + - kusionstack/{{ .ProjectName }}:latest build_flag_templates: - "--target=goreleaser" - "--pull" @@ -74,16 +78,6 @@ dockers: - "--label=org.opencontainers.image.source={{.GitURL}}" - "--platform=linux/amd64" -docker_manifests: - - use: docker - name_template: kusionstack/{{ .ProjectName }}:{{ .Tag }} - image_templates: - - kusionstack/{{ .ProjectName }}:{{ .Tag }}-amd64 - - use: docker - name_template: kusionstack/{{ .ProjectName }}:latest - image_templates: - - kusionstack/{{ .ProjectName }}:{{ .Tag }}-amd64 - brews: - tap: owner: KusionStack diff --git a/.goreleaser_informal.yml b/.goreleaser_informal.yml new file mode 100644 index 00000000..5497545e --- /dev/null +++ b/.goreleaser_informal.yml @@ -0,0 +1,78 @@ +# For more information, check the documentation at http://goreleaser.com +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + - go generate ./pkg/version + +builds: + - id: default + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + # ldflags="-s -w" removes the symbol table and debugging information to reduce the size of the release package + ldflags: + - -s + - -w + ignore: + - goos: linux + goarch: arm64 + - goos: windows + goarch: arm64 + main: . + +archives: + - id: default + builds: + - default + name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + format_overrides: + - goos: windows + format: zip + +checksum: + name_template: 'checksums.txt' + +changelog: + use: github + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + +release: + github: + owner: KusionStack + name: kusion + draft: false + footer: | + ## Docker Images + * `kusionstack/kusion:{{ .Env.KUSION_VERSION }}` + + ## Dependent version + * [kcl-go](https://github.com/kcl-lang/kcl-go): `{{ .Env.KCL_GO_VERSION }}` + * [kcl-plugin](https://github.com/kcl-lang/kcl-plugin): `{{ .Env.KCL_PLUGIN_VERSION }}` + +dockers: + - use: buildx + goos: linux + goarch: amd64 + dockerfile: Dockerfile + image_templates: + - kusionstack/{{ .ProjectName }}:{{ .Tag }} + build_flag_templates: + - "--target=goreleaser" + - "--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"