Skip to content

Commit

Permalink
Try to fix release pipeline for cross compiling CGO binary
Browse files Browse the repository at this point in the history
  • Loading branch information
rishinair11 committed Aug 3, 2024
1 parent 30d5d1f commit 5dd3c8b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 64 deletions.
63 changes: 49 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
- "*"

jobs:
build-and-release:
name: Build and Release
build-and-release-linux:
name: Build and Release Linux Binaries
runs-on: ubuntu-latest

steps:
Expand All @@ -19,29 +19,64 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: 1.22.3

- name: Install goreleaser
run: |
curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh -s -- -b $(go env GOPATH)/bin v2.0.1

- name: Install syft
- name: Install dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y gcc-aarch64-linux-gnu
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
- name: Clean modcache
run: |
make go-clean
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "v2.1.0"
args: release --clean --parallelism=1 --id=linux
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}

build-and-release-darwin:
name: Build and Release Darwin Binaries
runs-on: macos-latest

- name: Build binary
steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Install dependencies
run: |
make build
brew install coreutils
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "v2.0.1"
args: release --clean
args: release --clean --parallelism=1 --id=darwin
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}

66 changes: 16 additions & 50 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ version: 2

project_name: flux-graph
builds:
- env:
- id: linux
env:
- CGO_ENABLED=1
- >-
{{- if eq .Os "darwin" }}
{{- if eq .Arch "amd64"}}CC=o64-clang{{- end }}
{{- if eq .Arch "arm64"}}CC=aarch64-apple-darwin20.2-clang{{- end }}
{{- end }}
{{- if eq .Os "windows" }}
{{- if eq .Arch "amd64" }}CC=x86_64-w64-mingw32-gcc{{- end }}
{{- end }}
{{- if eq .Os "linux" }}
{{- if eq .Arch "arm64" }}CC=aarch64-linux-gnu-gcc{{- end }}
{{- if eq .Arch "arm64" }}CC=x86_64-linux-gnu-gcc{{- end }}
{{- if eq .Os "linux" }}
{{- if eq .Arch "arm64"}}CC=aarch64-linux-gnu-gcc{{- end }}
{{- end }}
goos:
- linux
- windows
goarch:
- amd64
- arm64
flags:
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser -X main.treeState={{ .IsGitDirty }}

- id: darwin
env:
- CGO_ENABLED=1
goos:
- darwin
goarch:
- amd64
- arm64
ignore:
- goos: windows
goarch: arm64
mod_timestamp: "{{ .CommitTimestamp }}"
flags:
- -trimpath
ldflags:
Expand All @@ -35,40 +35,6 @@ builds:
checksum:
name_template: "checksums.txt"

changelog:
sort: asc
use: github
filters:
exclude:
- "^test:"
- "^test\\("
- "merge conflict"
- Merge pull request
- Merge remote-tracking branch
- Merge branch
- go mod tidy
groups:
- title: Dependency updates
regexp: '^.*?(.+)\(deps\)!?:.+$'
order: 300
- title: "New Features"
regexp: '^.*?feat(\(.+\))??!?:.+$'
order: 100
- title: "Security updates"
regexp: '^.*?sec(\(.+\))??!?:.+$'
order: 150
- title: "Bug fixes"
regexp: '^.*?(fix|refactor)(\(.+\))??!?:.+$'
order: 200
- title: "Documentation updates"
regexp: ^.*?docs?(\(.+\))??!?:.+$
order: 400
- title: "Build process updates"
regexp: ^.*?(build|ci)(\(.+\))??!?:.+$
order: 400
- title: Other work
order: 9999

archives:
- name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
format_overrides:
Expand Down

0 comments on commit 5dd3c8b

Please sign in to comment.