Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use goreleaser for mullti-arch release builds #39

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: setup-go
uses: actions/setup-go@v4
with:
go-version: 1.18

- name: lint
run: make fmt

- name: build
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --snapshot --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 0 additions & 25 deletions .github/workflows/go.yml

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: RELEASE

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags

- name: setup-go
uses: actions/setup-go@v4
with:
go-version: 1.18

- name: build
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
35 changes: 35 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
ldflags:
- '-extldflags "-static"'
goos:
- linux
- windows
- darwin

archives:
- format: tar.gz
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
format_overrides:
- goos: windows
format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
9 changes: 2 additions & 7 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ fmt:
fmtcheck:
@sh -c "'$(CURDIR)/scripts/fmtcheck.sh'"

build: linux windows

linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-extldflags "-static"' -o bin/tfectl_linux_x86_64

windows:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags '-extldflags "-static"' -o bin/tfectl_win_x86_64
build:
goreleaser release --snapshot --clean

test:
@echo "==> Testing <=="
Expand Down
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,20 +542,17 @@ Use "tfectl [command] --help" for more information about a command.
```

### Build
* Using GNU Make
```bash
make build
```
GoReleaser is used to produce binaries for multiple platforms (Windows, Mac, Linux).

* Linux
```bash
$ make linux
```
To build all binaries locally:

- Install GoReleaser https://goreleaser.com/install/
- Run the build target command:

* Windows
```bash
$ make windows
$ make build
```
- Binaries will be built and output to the `/dist` folder.

## Contributing
* see `CONTRIBUTING.md`