diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 42d33a66..cca420f5 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -13,38 +13,49 @@ jobs: outputs: upload_url: ${{ steps.create_release.outputs.upload_url }} steps: - - name: Checkout code - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + + - uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + /usr/local/share/.cache/yarn + key: ${{ runner.os }}-koko + restore-keys: ${{ runner.os }}-koko + - name: Get version - id: get_version run: | TAG=$(basename ${GITHUB_REF}) - VERSION=${TAG/v/} - echo "::set-output name=TAG::$TAG" - echo "::set-output name=VERSION::$VERSION" + echo "TAG=$TAG" >> $GITHUB_ENV + - name: Create Release id: create_release - uses: release-drafter/release-drafter@v5 + uses: release-drafter/release-drafter@v6 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: config-name: release-config.yml - version: ${{ steps.get_version.outputs.VERSION }} - tag: ${{ steps.get_version.outputs.TAG }} + version: ${{ env.TAG }} + tag: ${{ env.TAG }} + - uses: actions/setup-node@v2 with: node-version: '20.15' + - uses: actions/setup-go@v2 with: - go-version: '1.22.x' # The Go version to download (if necessary) and use. + go-version: '1.22' # The Go version to download (if necessary) and use. + - name: Make Build id: make_build - env: - VERSION: ${{ steps.get_version.outputs.TAG }} run: | make all -s && ls build + env: + VERSION: ${{ env.TAG }} + - name: Release Upload Assets - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') with: draft: true diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..f890ebf2 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,116 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +version: 2 + +project_name: koko + +before: + hooks: + - go mod tidy + - go generate ./... + +snapshot: + version_template: "{{ .Tag }}-next" + +builds: + - id: koko + main: ./cmd/koko/ + binary: koko + goos: + - linux + - darwin + - freebsd + - netbsd + goarch: + - amd64 + - arm64 + - mips64le + - ppc64le + - s390x + - riscv64 + - loong64 + env: + - CGO_ENABLED=0 + ldflags: + - -w -s + - -X 'main.Buildstamp={{ .Date }}' + - -X 'main.Githash={{ .ShortCommit }}' + - -X 'main.Goversion={{ .Env.GOVERSION }}' + - -X 'main.Version={{ .Tag }}' + - -X 'github.com/jumpserver/koko/pkg/config.CipherKey={{ .Env.CipherKey }}' + - id: kubectl + main: ./cmd/kubectl/ + binary: kubectl + goos: + - linux + - darwin + - freebsd + - netbsd + goarch: + - amd64 + - arm64 + - mips64le + - ppc64le + - s390x + - riscv64 + - loong64 + env: + - CGO_ENABLED=0 + ldflags: + - -w -s + - -X 'github.com/jumpserver/koko/pkg/config.CipherKey={{ .Env.CipherKey }}' + - id: helm + main: ./cmd/helm/ + binary: helm + goos: + - linux + - darwin + - freebsd + - netbsd + goarch: + - amd64 + - arm64 + - mips64le + - ppc64le + - s390x + - riscv64 + - loong64 + env: + - CGO_ENABLED=0 + ldflags: + - -w -s + - -X 'github.com/jumpserver/koko/pkg/config.CipherKey={{ .Env.CipherKey }}' + +archives: + - format: tar.gz + wrap_in_directory: true + files: + - LICENSE + - README.md + - config_example.yml + - locale/* + - src: utils/init-kubectl.sh + dst: init-kubectl + strip_parent: true + + format_overrides: + - goos: windows + format: zip + name_template: "{{ .ProjectName }}-{{ .Tag }}-{{ .Os }}-{{ .Arch }}" + +checksum: + name_template: "{{ .ProjectName }}_checksums.txt" + +release: + draft: true + mode: append + extra_files: + - glob: dist/*.tar.gz + - glob: dist/{{ .ProjectName }}_checksums.txt + name_template: "Release {{.Tag}}" + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" \ No newline at end of file diff --git a/Makefile b/Makefile index 87fa28ce..a5c37ceb 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,23 @@ NAME=koko BUILDDIR=build +VERSION ?= Unknown +BuildTime := $(shell date -u '+%Y-%m-%d %I:%M:%S%p') +COMMIT := $(shell git rev-parse HEAD) +GOVERSION := $(shell go version) + BASEPATH := $(shell pwd) -BRANCH := $(shell git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3) -BUILD := $(shell git rev-parse --short HEAD) KOKOSRCFILE := $(BASEPATH)/cmd/koko/ KUBECTLFILE := $(BASEPATH)/cmd/kubectl/ HELMFILE := $(BASEPATH)/cmd/helm/ -VERSION ?= $(BRANCH)-$(BUILD) -BuildTime:= $(shell date -u '+%Y-%m-%d %I:%M:%S%p') -COMMIT:= $(shell git rev-parse HEAD) -GOVERSION:= $(shell go version) +COMMIT := $(shell git rev-parse HEAD) +GOVERSION := $(shell go version) CipherKey := $(shell head -c 100 /dev/urandom | base64 | head -c 32) TARGETARCH ?= amd64 -UIDIR=ui -NPMINSTALL=yarn install -NPMBUILD=yarn build +GOOS := $(shell go env GOOS) +GOARCH := $(shell go env GOARCH) LDFLAGS=-w -s @@ -32,7 +32,7 @@ K8SCMDFLAGS=-X 'github.com/jumpserver/koko/pkg/config.CipherKey=$(CipherKey)' KOKOBUILD=CGO_ENABLED=0 go build -trimpath -ldflags "$(KOKOLDFLAGS) ${LDFLAGS}" K8SCMDBUILD=CGO_ENABLED=0 go build -trimpath -ldflags "$(K8SCMDFLAGS) ${LDFLAGS}" -CURRENT_OS_ARCH = $(shell go env GOOS)-$(shell go env GOARCH) +UIDIR=ui define make_artifact_full GOOS=$(1) GOARCH=$(2) $(KOKOBUILD) -o $(BUILDDIR)/$(NAME)-$(1)-$(2) $(KOKOSRCFILE) @@ -52,9 +52,9 @@ define make_artifact_full endef build: - $(KOKOBUILD) -o $(BUILDDIR)/$(NAME)-$(CURRENT_OS_ARCH) $(KOKOSRCFILE) - $(K8SCMDBUILD) -o $(BUILDDIR)/kubectl-$(CURRENT_OS_ARCH) $(KUBECTLFILE) - $(K8SCMDBUILD) -o $(BUILDDIR)/helm-$(CURRENT_OS_ARCH) $(HELMFILE) + GOARCH=$(GOARCH) GOOS=$(GOOS) $(KOKOBUILD) -o $(BUILDDIR)/$(NAME) $(KOKOSRCFILE) + GOARCH=$(GOARCH) GOOS=$(GOOS) $(K8SCMDBUILD) -o $(BUILDDIR)/kubectl $(KUBECTLFILE) + GOARCH=$(GOARCH) GOOS=$(GOOS) $(K8SCMDBUILD) -o $(BUILDDIR)/helm $(HELMFILE) all: koko-ui $(call make_artifact_full,darwin,amd64) @@ -98,7 +98,7 @@ linux-riscv64: koko-ui koko-ui: @echo "build ui" - @cd $(UIDIR) && $(NPMINSTALL) && $(NPMBUILD) + @cd $(UIDIR) && yarn install && yarn build .PHONY: docker docker: