Skip to content

Commit

Permalink
add goreleaser (#2)
Browse files Browse the repository at this point in the history
Signed-off-by: Augustin Husson <[email protected]>
  • Loading branch information
Nexucis authored Oct 10, 2024
1 parent 9c75d62 commit 141ddf6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
21 changes: 20 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' || github.ref_name != 'main' }}

jobs:
build:
name: "go and github release"
runs-on: ubuntu-latest
Expand All @@ -31,4 +32,22 @@ concurrency:
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_go: true
- run: make build
- name: install goreleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
install-only: true
- name: Build Go binaries and docker images
run: make cross-build
- name: Publish main docker image
if: ${{ github.ref_name == 'main' }}
run: make push-main-docker-image
- name: Publish Release and binaries
## This step will only run when a new tag is pushed.
## It will build the Go binaries and the docker images and then publish:
## - the GitHub release with the archive built
## - docker images on the different docker registry selected
if: ${{ github.event_name == 'push' && startsWith(github.ref_name, 'v') }}
run: make cross-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31 changes: 31 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: 2
builds:
- id: "metric-usage"
main: ./main.go
binary: "metric-usage"
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm
- arm64
# We are ignoring this arch because it doesn't compile due to an issue with prometheus:
# failed to build for windows_arm_6
# github.com/prometheus/[email protected]/tsdb/fileutil/mmap_windows.go:38:12: undefined array length maxMapSize or missing type constraint
ignore:
- goarch: arm
goos: windows
env:
- CGO_ENABLED=0
ldflags:
- "{{.Env.LDFLAGS}}"
archives:
- id: "default"
builds:
- "metric-usage"
format: "tar.gz"
files:
- LICENSE
- README.md
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,13 @@ update-go-deps:
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
$(GO) get -d $$m; \
done


## Cross build binaries for all platforms (Use "make build" in development)
.PHONY: cross-build
cross-build: ## Cross build binaries for all platforms (Use "make build" in development)
goreleaser release --snapshot --clean

.PHONY: cross-release
cross-release:
goreleaser release --clean

0 comments on commit 141ddf6

Please sign in to comment.