Skip to content

Commit

Permalink
update goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
cxjava authored Feb 14, 2023
1 parent fbbaac2 commit 9c2f4ab
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 91 deletions.
87 changes: 25 additions & 62 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,81 +1,44 @@
name: Release
name: GoReleaser

on:
push:
tags:
- "v*"
workflow_dispatch:
# inputs:
# upx_version:
# description: 'UPX version'
# required: true
# default: '3.96'
inputs:
bump_type:
description: 'Bump tag type: major, minor, patch. default: minor'
required: true
default: 'minor'

permissions: write-all

jobs:
release:
runs-on: ${{ matrix.os }}
goreleaser:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
go: [1.19.x]
os: [ubuntu-latest]
name: Go ${{ matrix.go }} in ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: Environment
run: |
go version
go env
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
- name: Test
go-version: "1.20"
- name: Bump tag version
id: bumpTag
uses: anothrNick/github-tag-action@1.61.0
env:
GOFLAGS: -mod=mod
run: go test -race -coverpkg=./... -coverprofile=coverage.txt ./...

# So GoReleaser can generate the changelog properly
- name: Unshallowify the repo clone
run: git fetch --prune --unshallow

- name: Check git tag exist
run: |
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
gitTagExists=$(git tag --points-at HEAD)
if ! [ -n "$gitTagExists" ]; then
echo "no tag, create one."
latesttag=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "latest tag: ${latesttag}"
newtag=$(echo ${latesttag} | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}')
echo "new tag: ${newtag}"
git tag $newtag
fi
# - name: Installing upx
# env:
# UPX_VERSION: ${{ github.event.inputs.upx_version }}
# run: |
# echo "Installing upx .."
# curl -OL "https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-amd64_linux.tar.xz"
# tar xvf "upx-${UPX_VERSION}-amd64_linux.tar.xz"
# cp "upx-${UPX_VERSION}-amd64_linux/upx" "$(go env GOPATH)/bin"
# upx --version

GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DRY_RUN: true
DEFAULT_BUMP: "${{ github.event.inputs.bump_type }}"
- name: Bump tag locally
run: git tag ${{ steps.bumpTag.outputs.new_tag }}
- name: Set environment variables
run: |
echo "GOLANG_VERSION=$(go version)" >> $GITHUB_ENV
echo "BUILT_BY=$(whoami)@$(hostname)" >> $GITHUB_ENV
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
- uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --rm-dist --skip-validate --skip-sign --debug
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOLANG_VERSION: ${{ env.GOLANG_VERSION }}
BUILT_BY: ${{ env.BUILT_BY }}
BUILT_BY: ${{ env.BUILT_BY }}
62 changes: 33 additions & 29 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
env:
- GO111MODULE=on

before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
ldflags:
- '-s -w'
- "-s -w"
- -X 'github.com/{{.Env.GITHUB_REPOSITORY}}/cmd.Version={{.Version}}'
- -X 'github.com/{{.Env.GITHUB_REPOSITORY}}/cmd.Commit={{.FullCommit}}'
- -X 'github.com/{{.Env.GITHUB_REPOSITORY}}/cmd.RepoUrl={{.GitURL}}'
- -X 'github.com/{{.Env.GITHUB_REPOSITORY}}/cmd.BuildDate={{.Date}}'
- -X 'github.com/{{.Env.GITHUB_REPOSITORY}}/cmd.BuiltWithGoVersion={{.Env.GOLANG_VERSION}}'
- -X 'github.com/{{.Env.GITHUB_REPOSITORY}}/cmd.BuiltBy={{.Env.BUILT_BY}}'
goos:
- windows
- darwin
- linux
# - freebsd
goarch:
- 386
- amd64
- arm
- arm64
# - mips
# - mipsle
# - mips64
# - mips64le
# gomips:
# - hardfloat
# - softfloat
# hooks:
# post:
# - bash -c 'upx "{{ .Path }}" || true'
targets:
- darwin_amd64
- darwin_arm64
- linux_386
- linux_amd64
- linux_amd64_v3
- linux_arm_5
- linux_arm_6
- linux_arm_7
- linux_arm64
# - linux_mips_softfloat
# - linux_mips_hardfloat
# - linux_mipsle_softfloat
# - linux_mipsle_hardfloat
# - linux_mips64
# - linux_mips64le
# - linux_s390x
# - linux_riscv64
# - freebsd_386
# - freebsd_amd64
- windows_386
- windows_amd64
- windows_amd64_v3
- windows_arm64

archives:
- name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}_v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}'
- wrap_in_directory: false
format: tar.gz
files:
- none*
format_overrides:
- goos: windows
format: zip
wrap_in_directory: false
replacements:
amd64: 64-bit
386: 32-bit
Expand All @@ -52,7 +54,9 @@ archives:
openbsd: OpenBSD
netbsd: NetBSD
freebsd: FreeBSD
checksum:
name_template: "checksums.txt"
release:
draft: true
prerelease: auto
name_template: '{{.ProjectName}}-v{{.Version}}-{{.Date}}'
name_template: "{{.ProjectName}}-v{{.Version}}-{{.Date}}"

0 comments on commit 9c2f4ab

Please sign in to comment.