diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c47ded9..a065408 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -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 diff --git a/.gitignore b/.gitignore index d40b14b..004ebce 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,6 @@ bin /.vscode e2e/results/* + +# CGO Cross-compile GoReleaser-cross env file +.release-env diff --git a/.goreleaser.yml b/.goreleaser.yml index b3f6c5c..e2eb36b 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -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' diff --git a/Makefile b/Makefile index ed2463b..58a122f 100644 --- a/Makefile +++ b/Makefile @@ -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