Skip to content

Latest commit

 

History

History
176 lines (136 loc) · 5.2 KB

README_CN.md

File metadata and controls

176 lines (136 loc) · 5.2 KB

GoReleaseCli

Lisense Release GoReport

English | 中文

~$ release --help-long
usage: release [<flags>] <target>

Golang build production release helper.

Flags:
  -h, --[no-]help            Show context-sensitive help (also try --help-long
                             and --help-man).
  -v, --[no-]version         Show application version.
  -j, --thread=(NumCpu+1)    How many threads to use for parallel compilation.
  -c, --compress=COMPRESS    Compress the binary into the specified format of
                             compressed file.
      --[no-]disable-default-ldflags
                             Disable ldflags added by default.
      --[no-]disable-auto-clean  Files in output dir will be kept.
      --mod-download-args=MOD-DOWNLOAD-ARGS
                             custom args for go mod download.
      --ldflags=LDFLAGS      Add custom ldflags.
      --[no-]cgo             Enable go cgo.
      --os=OS                Target os.
      --arch=ARCH            Target arch.
      --platforms=PLATFORMS  Specify platforms
      --[no-]extra-arches    Build all extra arches.
      --[no-]extra-arches-show-default
                             Show default extra arch name.
  -d, --output="build"       Output dir path.
  -f, --output-format=OUTPUT-FORMAT  
                             Output file name format.
  -o, --name=NAME            Output binary file name.
      --divider="-"          Divider in name.

Args:
  <target>  Target package.

🎷 使用

CGO、软浮点、生成压缩文件默认关闭

默认编译所有架构类型,可以使用 flag --os--arch 指定系统或架构,使用英文逗号分隔。程序会自动匹配出有效架构进行编译

~$ release ./cmd/release
~$ release ./cmd/release --os linux,windows
~$ release ./cmd/release --arch amd64,386

如果你想跳过内置的架构列表手动指定架构,你可以使用 flag --platforms。此 flag 添加的架构不会经过有效性校验

~$ release ./cmd/release --platforms linux/386,windows/amd64

# 也可以结合两种方法
~$ release ./cmd/release --os linux --arch 386 --platforms windows/amd64 

编译时默认已带有 -extldflags "-static -fpic" -s -w 以及 -trimpath 的 ldflags,如果需要附加自定义 ldflags,可以用 flag 继续加

~$ release ./cmd/release --ldflags='-X main.Version=5.5.5'

~$ release ./cmd/release --disable-default-ldflags # 移除默认 ldflags

当使用 --extra-arches 时,会编译出所有子架构如 arm/v6 arm/v7

默认情况下,默认架构编译结果的名称不会添加额外的子架构后缀。但你可以通过 --extra-arches-show-default 启用它

~$ release ./cmd/release --extra-arches

~$ release ./cmd/release --extra-arches --extra-arches-show-default # 为默认架构添加子架构后缀

压缩到指定格式,依赖 7z lib,没有 7z 时会尝试使用 zip + zipnote / tar 分别为不同压缩类型压缩,目前支持 zip tar.gz

~$ release  ./cmd/release -c tar.gz

默认情况下,会使用 target 目录的目录名,编译结果放在 build 目录下,这也是可以通过 flag 修改的

~$ release ./cmd/release --output dist # 修改输出目录为 dist
~$ release ./cmd/release -d dist

~$ release ./cmd/release --name asd # 修改名称为 asd
~$ release ./cmd/release -o asd

🏭 在 GitHub Action 中使用

在容器中构建

name: Release

on:
  push:
    tags:
      - v**
jobs:
  release_docker:
    runs-on: ubuntu-latest
    steps:

  release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Build
        uses: Mmx233/[email protected]
        with:
          target: ./cmd/derper
          compress: tar.gz

      - name: Upload assets
        uses: softprops/action-gh-release@v1
        with:
          files: build/*.tar.gz
          prerelease: false

在 Action Runner 环境中构建

name: Release

on:
  push:
    tags:
      - v**
jobs:
  release_docker:
    runs-on: ubuntu-latest
    steps:

  release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - uses: actions/setup-go@v5
        with:
          go-version: 'stable'

      - name: Setup Release Cli
        uses: robinraju/[email protected]
        with:
          repository: "Mmx233/GoReleaseCli"
          latest: true
          fileName: 'release_linux_amd64.tar.gz'
          extract: true
          out-file-path: './build/'

      - name: Build
        run: ./build/release ./cmd/derper --perm 777 -c tar.gz --extra-arches --output build/output

      - name: Upload assets
        uses: softprops/action-gh-release@v1
        with:
          files: build/output/*.tar.gz
          prerelease: false