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 8f8111f
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 106 deletions.
64 changes: 50 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,65 @@ 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: Build binary
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "v2.1.0"
args: release --clean --parallelism=1 --config=.goreleaser-linux.yml
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}

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

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
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
- 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 --config=.goreleaser-darwin.yml
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}

41 changes: 41 additions & 0 deletions .goreleaser-darwin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: 2

project_name: flux-graph
builds:
- id: darwin
env:
- CGO_ENABLED=1
goos:
- darwin
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 }}

checksum:
name_template: "checksums_{{ .Os }}_{{ .Arch }}.txt"

archives:
- name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
format_overrides:
- goos: windows
format: zip
builds_info:
group: root
owner: root
mode: 0644
mtime: 2008-01-02T15:04:05Z
files:
- README.md
- LICENSE

sboms:
- artifacts: archive

release:
github:
owner: rishinair11
name: flux-graph
45 changes: 45 additions & 0 deletions .goreleaser-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: 2

project_name: flux-graph
builds:
- id: linux
env:
- CGO_ENABLED=1
- >-
{{- if eq .Os "linux" }}
{{- if eq .Arch "arm64"}}CC=aarch64-linux-gnu-gcc{{- end }}
{{- end }}
goos:
- linux
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 }}

checksum:
name_template: "checksums_{{ .Os }}_{{ .Arch }}.txt"

archives:
- name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
format_overrides:
- goos: windows
format: zip
builds_info:
group: root
owner: root
mode: 0644
mtime: 2008-01-02T15:04:05Z
files:
- README.md
- LICENSE

sboms:
- artifacts: archive

release:
github:
owner: rishinair11
name: flux-graph
92 changes: 0 additions & 92 deletions .goreleaser.yml

This file was deleted.

0 comments on commit 8f8111f

Please sign in to comment.