Skip to content

Commit

Permalink
Merge pull request #1512 from jumpserver/pr@dev@perf_actions_build
Browse files Browse the repository at this point in the history
perf: 优化 actions 构建
  • Loading branch information
wojiushixiaobai authored Sep 19, 2024
2 parents b4780f4 + ed2ffc5 commit 67ab3e9
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 36 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 26 additions & 15 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
run:
timeout: 5m
modules-download-mode: readonly
skip-dirs:

issues:
exclude-dirs:
- cmd/demo
- cmd/i18ntool
- data
Expand All @@ -10,11 +12,13 @@ run:
- ui
- .git

skip-files:
exclude-files:
- pkg/utils/terminal.go

linters:
enable:
- govet
- staticcheck

output:
format: colored-line-number
116 changes: 116 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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:"
28 changes: 14 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 67ab3e9

Please sign in to comment.