Skip to content

Commit

Permalink
ci: add goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Apr 27, 2024
1 parent eee278d commit 14a49fa
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: goreleaser

on:
push:
tags:
- v*

jobs:
goreleaser:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21.0'
env:
GOPATH: ${{ env.HOME }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean
env:
GOPATH: ${{ env.HOME }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,22 @@ jobs:
- name: Test
run: make test


releaser-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --snapshot --clean --skip=publish --verbose
env:
WORKDIR: ${{ github.workspace }}
41 changes: 41 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
before:
hooks:
- sudo apt-get install -y gcc flex bison make libelf-dev
- make libpcap

builds:
- id: ptcpdump
binary: ptcpdump
env:
- CGO_ENABLED=1
- LD_LIBRARY_PATH="-L/home/runner/work/ptcpdump/ptcpdump/output/libpcap"
- CGO_CPPFLAGS="-I/home/runner/work/ptcpdump/ptcpdump/output/libpcap"
- LDFLAGS="-l/home/runner/work/ptcpdump/ptcpdump/output/libpcap/lib/libpcap.a"
- CGO_CFLAGS="-I/home/runner/work/ptcpdump/ptcpdump/output/libpcap/include"
- CGO_LDFLAGS="-L/home/runner/work/ptcpdump/ptcpdump/output/libpcap/lib -lelf -lz /home/runner/work/ptcpdump/ptcpdump/output/libpcap/lib/libpcap.a"
# overrides:
# - env:
# - LDFLAGS="-l/home/runner/work/ptcpdump/ptcpdump/output/libpcap/lib/libpcap.a"
# - CGO_ENABLED=1
# - CGO_CFLAGS="-I/home/runner/work/ptcpdump/ptcpdump/output/libpcap/include"
# - CGO_LDFLAGS="-L/home/runner/work/ptcpdump/ptcpdump/output/libpcap/lib -lelf -lz /home/runner/work/ptcpdump/ptcpdump/output/libpcap/lib/libpcap.a"
flags:
- -tags=static
ldflags:
- -linkmode 'external'
- -extldflags "-static"
- -X github.com/mozillazg/ptcpdump/internal.Version={{.Version}}
- -X github.com/mozillazg/ptcpdump/internal.GitCommit={{.Commit}}
goos:
- linux
goarch:
- amd64

checksum:
name_template: 'checksums.txt'

release:
prerelease: auto

snapshot:
name_template: "{{ .Tag }}-next"
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ LIBPCAP_OBJ = $(abspath $(LIBPCAP_OBJ_DIR)/libpcap.a)
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
VERSION ?= $(shell git describe --tags --abbrev=0)
CGO_CFLAGS_STATIC = "-I$(LIBPCAP_HEADER_DIR)"
CGO_LDFLAGS_STATIC = "-L$(LIBPCAP_OBJ_DIR) -lelf -lz $(LIBPCAP_OBJ)"
CGO_LDFLAGS_STATIC = "-L$(LIBPCAP_OBJ_DIR) $(LIBPCAP_OBJ)"
CGO_ENABLED ?= 1
GOARCH ?= $(shell go env GOARCH)
GOOS ?= $(shell go env GOOS)
LDFLAGS := -extldflags "-static"
LDFLAGS := -linkmode "external" -extldflags "-static"
LDFLAGS += -X github.com/mozillazg/ptcpdump/internal.Version=$(VERSION)
LDFLAGS += -X github.com/mozillazg/ptcpdump/internal.GitCommit=$(GIT_COMMIT)

Expand Down

0 comments on commit 14a49fa

Please sign in to comment.