Skip to content

Commit

Permalink
ci(release): install cross-compiling toolchain
Browse files Browse the repository at this point in the history
Signed-off-by: Massimiliano Giovagnoli <[email protected]>
  • Loading branch information
maxgio92 committed Feb 4, 2023
1 parent 6584d4a commit ce71d61
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 29 deletions.
42 changes: 15 additions & 27 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,24 @@ name: Release
on:
push:
tags:
- v*
- v*

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-20.04

release-cross:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Get Go version from file
run: |
FROM_SOURCE=$(sed -nE 's/go[[:space:]]+([[:digit:]]\.[[:digit:]]+)/\1/p' go.mod)
echo "GO_VERSION=$FROM_SOURCE" >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: checkout code
uses: actions/checkout@v2
with:
submodules: 'true'
- run: git fetch --prune --unshallow
- name: Set up Go and dependencies
uses: actions/setup-go@v2
- name: Setup release environment
run: |-
echo 'GITHUB_TOKEN=${{secrets.GORELEASER_ACCESS_TOKEN}}' > .release-env
- name: Publish release
run: make release
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ bin
/.vscode

e2e/results/*

# CGO Cross-compile GoReleaser-cross env file
.release-env
42 changes: 40 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,49 @@ builds:
ignore:
- goos: darwin
goarch: '386'
- goos: windows
goarch: 'arm'
- goos: windows
goarch: 'arm64'
ldflags:
- -s -w -X main.buildVersion={{ .Version }}
overrides:
- goos: windows
goarch: amd64
goamd64: v1
env:
- CC=x86_64-w64-mingw32-gcc
- goos: windows
goarch: arm64
env:
- CC=/llvm-mingw/llvm-mingw/bin/aarch64-w64-mingw32-gcc
- goos: darwin
goarch: amd64
goamd64: v1
env:
- CC=o64-clang
- goos: darwin
goarch: arm64
env:
- CC=oa64-clang
- goos: linux
goarch: arm64
env:
- CC=aarch64-linux-gnu-gcc
- goos: linux
goarch: arm
goarm: '6'
env:
- CC=arm-linux-gnueabihf-gcc
- goos: linux
goarch: arm
goarm: '7'
ldflags:
- -s -w -X main.buildVersion={{ .Version }}
env:
- CC=arm-linux-gnueabihf-gcc
- goos: linux
goarch: amd64
env:
- CC=gcc

checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
Expand Down
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,22 @@ e2e: clean build $(patsubst %,e2e/%,$(DISTROS))

.PHONY: publish
publish: clean build $(patsubst %,publish/%,$(DISTROS))

PACKAGE_NAME := github.com/maxgio92/$(app)
GOLANG_CROSS_VERSION ?= v$(shell sed -nE 's/go[[:space:]]+([[:digit:]]\.[[:digit:]]+)/\1/p' go.mod)

.PHONY: release
release:
@if [ ! -f ".release-env" ]; then \
echo "\033[91m.release-env is required for release\033[0m";\
exit 1;\
fi
docker run \
--rm \
-e CGO_ENABLED=1 \
--env-file .release-env \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --rm-dist

0 comments on commit ce71d61

Please sign in to comment.