Skip to content

Commit

Permalink
- [+] add goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
suntong committed Jul 8, 2023
1 parent 3d31c08 commit b6545ae
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/go-release-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: build

on:
push:
branches:
- 'master'
tags:
- 'v*'
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19

-
name: Cache Go modules
uses: actions/cache@v1
# Do before go get
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
-
name: Tests
run: |
go mod tidy
go build -v -trimpath
go test -v ./...
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
if: success() && startsWith(github.ref, 'refs/tags/')
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

-
name: Install Cloudsmith CLI
run: pip install --upgrade cloudsmith-cli
if: success() && startsWith(github.ref, 'refs/tags/')
# Cloudsmith CLI tooling for pushing releases
# See https://help.cloudsmith.io/docs/cli

# Publish to cloudsmith repo
-
name: Publish package to cloudsmith
if: success() && startsWith(github.ref, 'refs/tags/')
env:
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
run: |
for filepath in dist/*; do
echo "== Analyzing '$filepath' for publishing"
filename=$(basename -- "$filepath")
extension="${filename##*.}"
filename="${filename%.*}"
case "$extension" in
'apk')
echo "Pushing '$filepath' to cloudsmith repo"
cloudsmith push alpine suntong/repo/alpine/any-version $filepath
;;
'deb' | 'rpm')
echo "Pushing '$filepath' to cloudsmith repo"
cloudsmith push $extension suntong/repo/any-distro/any-version $filepath
;;
*)
echo "File .$extension skipped publishing"
echo
;;
esac
done
24 changes: 24 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
builds:
- env: [CGO_ENABLED=0]
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64

main: ./cmd/mainA
id: mainA

- env: [CGO_ENABLED=0]
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64

main: ./cmd/mainB
id: mainB
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/suntong/gorelease2

go 1.17

0 comments on commit b6545ae

Please sign in to comment.