From ed2ffc570c255a60512d893971adbbdecdb64c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=B0=8F=E7=99=BD?= <296015668@qq.com> Date: Thu, 19 Sep 2024 17:08:03 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20actions=20?= =?UTF-8?q?=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/golangci-lint.yml | 11 +-- .github/workflows/release-drafter.yml | 41 +++++---- .golangci.yml | 8 +- .goreleaser.yaml | 116 ++++++++++++++++++++++++++ Makefile | 28 +++---- 5 files changed, 168 insertions(+), 36 deletions(-) create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 9b983ee73..50f873c2c 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -13,17 +13,18 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v3 - with: - go-version: 1.22 - uses: actions/checkout@v4 + - name: Create ui/dist directory run: | mkdir -p ui/dist touch ui/dist/.gitkeep - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + - uses: actions/setup-go@v5 + with: + go-version: stable + + - uses: golangci/golangci-lint-action@v6 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: latest diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 42d33a667..9790a6af4 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 }} - - uses: actions/setup-node@v2 + version: ${{ env.TAG }} + tag: ${{ env.TAG }} + + - uses: actions/setup-node@v4 with: node-version: '20.15' - - uses: actions/setup-go@v2 + + - uses: actions/setup-go@v5 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/.golangci.yml b/.golangci.yml index 4e0b792a3..6e8737d40 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,9 @@ run: timeout: 5m modules-download-mode: readonly - skip-dirs: + +issues: + exclude-dirs: - cmd/demo - cmd/i18ntool - data @@ -10,7 +12,7 @@ run: - ui - .git - skip-files: + exclude-files: - pkg/utils/terminal.go linters: @@ -18,3 +20,5 @@ linters: - govet - staticcheck +output: + format: colored-line-number \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 000000000..f890ebf21 --- /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 87fa28ce1..a5c37ceb6 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: