Skip to content

Commit

Permalink
feat: update the latest version when releasing formal version (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
healthjyk committed Dec 27, 2023
1 parent f10f3c6 commit e92cd0d
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 20 deletions.
38 changes: 32 additions & 6 deletions .github/workflows/release.yaml
Expand Up @@ -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:
Expand All @@ -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: |
Expand All @@ -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 }}
Expand Down
22 changes: 8 additions & 14 deletions .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:
Expand All @@ -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
Expand All @@ -26,6 +26,7 @@ builds:
- goos: windows
goarch: arm64
main: .

archives:
- id: default
builds:
Expand All @@ -34,8 +35,10 @@ archives:
format_overrides:
- goos: windows
format: zip

checksum:
name_template: 'checksums.txt'

changelog:
use: github
sort: asc
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
78 changes: 78 additions & 0 deletions .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"

0 comments on commit e92cd0d

Please sign in to comment.