Skip to content

Commit

Permalink
perf: 优化 actions 构建
Browse files Browse the repository at this point in the history
  • Loading branch information
wojiushixiaobai committed Sep 19, 2024
1 parent e78763d commit 57ee18e
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 25 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: golangci-lint
on:
pull_request:
push:
branches:
- dev

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Create ui/dist directory
run: |
mkdir -p ui/dist
touch ui/dist/.gitkeep
- 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

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
43 changes: 27 additions & 16 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 }}-lion
restore-keys: ${{ runner.os }}-lion

- 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.TAG }}
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
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
20 changes: 20 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
run:
timeout: 5m
modules-download-mode: readonly

issues:
exclude-dirs:
- docs
- ui
- .git

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

linters:
enable:
- govet
- staticcheck

output:
format: colored-line-number
70 changes: 70 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
version: 2

project_name: lion

before:
hooks:
- go mod tidy
- go generate ./...

snapshot:
version_template: "{{ .Tag }}-next"

builds:
- id: lion
main: main.go
binary: lion
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 }}'

archives:
- format: tar.gz
wrap_in_directory: true
files:
- LICENSE
- README.md
- config_example.yml
- ui/dist/**

format_overrides:
- goos: windows
format: zip
name_template: "{{ .ProjectName }}-{{ .Tag }}-{{ .Os }}-{{ .Arch }}{{- if .Arm }}v{{ .Arm }}{{ end }}"

checksum:
name_template: "{{ .ProjectName }}_checksums.txt"

release:
draft: true
mode: append
extra_files:
- glob: dist/*.tar.gz
- glob: dist/*.txt
name_template: "Release {{.Tag}}"

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
17 changes: 8 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
NAME=lion
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)

GOOS:=$(shell go env GOOS)
GOARCH:=$(shell go env GOARCH)
VERSION ?= Unknown
BuildTime := $(shell date -u '+%Y-%m-%d %I:%M:%S%p')
COMMIT := $(shell git rev-parse HEAD)
GOVERSION := $(shell go version)

GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)

LDFLAGS=-w -s

Expand All @@ -18,8 +19,6 @@ GOLDFLAGS+=-X 'main.Goversion=$(GOVERSION)'
GOBUILD=CGO_ENABLED=0 go build -trimpath -ldflags "$(GOLDFLAGS) ${LDFLAGS}"

UIDIR=ui
NPMINSTALL=yarn
NPMBUILD=yarn build

define make_artifact_full
GOOS=$(1) GOARCH=$(2) $(GOBUILD) -o $(BUILDDIR)/$(NAME)-$(1)-$(2)
Expand Down Expand Up @@ -80,7 +79,7 @@ docker:

lion-ui:
@echo "build ui"
@cd $(UIDIR) && $(NPMINSTALL) && $(NPMBUILD)
@cd $(UIDIR) && yarn install && yarn build

clean:
rm -rf $(BUILDDIR)
Expand Down

0 comments on commit 57ee18e

Please sign in to comment.