Skip to content

Commit

Permalink
Merge pull request #42 from qvalentin/master
Browse files Browse the repository at this point in the history
[FIX] use goreleaser for cross compiling
  • Loading branch information
qvalentin authored Sep 30, 2023
2 parents 81b26fd + ea69ffc commit a6fc99e
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 55 deletions.
58 changes: 35 additions & 23 deletions .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ on:
- v*

jobs:

artifacts:
name: artifacts
strategy:
Expand All @@ -31,42 +30,44 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3

- name: Install go dependencies
run: go mod tidy

- name: Build artifacts
id: build
- name: release publish
run: |
make build-artifacts
printf '::set-output name=version::%s\n' "$(./dist/helm_ls_linux_amd64 version)"
make build-release
printf '::set-output name=version::%s\n' "$(./dist/linux-amd64_linux_amd64_v1/helm-ls version)"
- name: 'Upload macOS-amd64 artifact'
uses: actions/upload-artifact@v2
with:
name: helm_ls_darwin_amd64
path: ./dist/helm_ls-darwin-10.12-amd64
path: ./dist/darwin-amd64_darwin_amd64_v1/helm-ls
retention-days: 1

- name: 'Upload macOS-arm64 artifact'
uses: actions/upload-artifact@v2
with:
name: helm_ls_darwin_arm64
path: ./dist/darwin-arm64_darwin_arm64/helm-ls
retention-days: 1

- name: 'Upload linux/amd64 artifact'
uses: actions/upload-artifact@v2
with:
name: helm_ls_linux_amd64
path: ./dist/helm_ls-linux-amd64
path: ./dist/linux-amd64_linux_amd64_v1/helm-ls
retention-days: 1

- name: 'Upload linux/arm artifact'
uses: actions/upload-artifact@v2
with:
name: helm_ls_linux_arm
path: ./dist/helm_ls-linux-arm64
path: ./dist/linux-arm64_linux_arm64/helm-ls
retention-days: 1

- name: 'Upload windows/amd64 artifact'
uses: actions/upload-artifact@v2
with:
name: helm_ls_windows_amd64
path: ./dist/helm_ls-windows-4.0-amd64.exe
path: ./dist/windows-amd64_windows_amd64_v1/helm-ls.exe
retention-days: 1

publish:
Expand All @@ -93,22 +94,27 @@ jobs:
- name: Generate Linux-64 SHA256 checksums
run: |
sha256sum helm_ls_linux_amd64/helm_ls-linux-amd64 > helm_ls_linux_amd64.sha256sum
sha256sum helm_ls_linux_amd64/helm-ls > helm_ls_linux_amd64.sha256sum
echo "SHA_LINUX_64=$(cat helm_ls_linux_amd64.sha256sum)" >> $GITHUB_ENV
- name: Generate Windows-64 SHA256 checksums
run: |
sha256sum helm_ls_windows_amd64/helm_ls-windows-4.0-amd64.exe > helm_ls_windows_amd64.sha256sum
sha256sum helm_ls_windows_amd64/helm-ls.exe > helm_ls_windows_amd64.sha256sum
echo "SHA_WINDOWS_64=$(cat helm_ls_windows_amd64.sha256sum)" >> $GITHUB_ENV
- name: Generate macOS-amd64 SHA256 checksums
run: |
sha256sum helm_ls_darwin_amd64/helm_ls-darwin-10.12-amd64 > helm_ls_darwin_amd64.sha256sum
echo "SHA_MACOS=$(cat helm_ls_darwin_amd64.sha256sum)" >> $GITHUB_ENV
sha256sum helm_ls_darwin_amd64/helm-ls > helm_ls_darwin_amd64.sha256sum
echo "SHA_MACOS_AMD64=$(cat helm_ls_darwin_amd64.sha256sum)" >> $GITHUB_ENV
- name: Generate macOS-arm64 SHA256 checksums
run: |
sha256sum helm_ls_darwin_arm64/helm-ls > helm_ls_darwin_arm64.sha256sum
echo "SHA_MACOS_ARM64=$(cat helm_ls_darwin_arm64.sha256sum)" >> $GITHUB_ENV
- name: Generate Linux-ARM SHA256 checksums
run: |
sha256sum helm_ls_linux_arm/helm_ls-linux-arm64 > helm_ls_linux_arm.sha256sum
sha256sum helm_ls_linux_arm/helm-ls > helm_ls_linux_arm.sha256sum
echo "SHA_LINUX_ARM=$(cat helm_ls_linux_arm.sha256sum)" >> $GITHUB_ENV
- if: env.TAG_NAME == 'master'
Expand All @@ -127,13 +133,15 @@ jobs:
gzip: false
allow_override: true
files: |
helm_ls_darwin_amd64:./helm_ls_darwin_amd64/helm_ls-darwin-10.12-amd64
helm_ls_darwin_amd64:./helm_ls_darwin_amd64/helm-ls
helm_ls_darwin_amd64.sha256sum:./helm_ls_darwin_amd64.sha256sum
helm_ls_windows_amd64:./helm_ls_windows_amd64/helm_ls-windows-4.0-amd64.exe
helm_ls_darwin_arm64:./helm_ls_darwin_arm64/helm-ls
helm_ls_darwin_arm64.sha256sum:./helm_ls_darwin_arm64.sha256sum
helm_ls_windows_amd64.exe:./helm_ls_windows_amd64/helm-ls.exe
helm_ls_windows_amd64.sha256sum:./helm_ls_windows_amd64.sha256sum
helm_ls_linux_amd64:./helm_ls_linux_amd64/helm_ls-linux-amd64
helm_ls_linux_amd64:./helm_ls_linux_amd64/helm-ls
helm_ls_linux_amd64.sha256sum:./helm_ls_linux_amd64.sha256sum
helm_ls_linux_arm:./helm_ls_linux_arm/helm_ls-linux-arm64
helm_ls_linux_arm:./helm_ls_linux_arm/helm-ls
helm_ls_linux_arm.sha256sum:./helm_ls_linux_arm.sha256sum
body: |
```
Expand All @@ -142,6 +150,9 @@ jobs:
### macOS (x64)
1. Download **helm_ls_darwin_amd64**
2. Run `./helm_ls_darwin_amd64`
### macOS (ARM)
1. Download **helm_ls_darwin_arm64**
2. Run `./helm_ls_darwin_arm64`
### windows (x64)
1. Download **helm_ls_windows_amd64.exe**
2. Run `./helm_ls_windows_amd64.exe`
Expand All @@ -155,7 +166,8 @@ jobs:
```
${{ env.SHA_LINUX_64 }}
${{ env.SHA_MACOS }}
${{ env.SHA_MACOS_AMD64 }}
${{ env.SHA_MACOS_ARM64 }}
${{ env.SHA_WINDOWS_64 }}
${{ env.SHA_LINUX_ARM }}
```
80 changes: 80 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
builds:
- id: darwin-amd64
main: ./
binary: helm-ls
goos:
- darwin
goarch:
- amd64
env:
- CC=o64-clang
- CXX=o64-clang++
flags:
- -mod=readonly
ldflags:
- -s -w -X main.Version={{ .Env.GIT_COMMIT }} -X main.CompiledBy={{ .Env.COMPILED_BY }} -X main.BranchName={{ .Env.BRANCH_NAME }} -X main.BuildTime={{ .Env.BUILD_TIME }}
- id: darwin-arm64
binary: helm-ls
main: ./
goarch:
- arm64
goos:
- darwin
env:
- CC=oa64-clang
- CXX=oa64-clang++
flags:
- -trimpath
ldflags:
- -X main.Version={{ .Env.GIT_COMMIT }} -X main.CompiledBy={{ .Env.COMPILED_BY }} -X main.BranchName={{ .Env.BRANCH_NAME }} -X main.BuildTime={{ .Env.BUILD_TIME }}
- id: linux-amd64
main: ./
binary: helm-ls
goos:
- linux
goarch:
- amd64
flags:
- -mod=readonly
ldflags:
- -s -w -X main.Version={{ .Env.GIT_COMMIT }} -X main.CompiledBy={{ .Env.COMPILED_BY }} -X main.BranchName={{ .Env.BRANCH_NAME }} -X main.BuildTime={{ .Env.BUILD_TIME }}
- id: linux-arm64
main: ./
binary: helm-ls
goos:
- linux
goarch:
- arm64
env:
- CC=aarch64-linux-gnu-gcc
- CXX=aarch64-linux-gnu-g++
flags:
- -trimpath
ldflags:
- -s -w -X main.Version={{ .Env.GIT_COMMIT }} -X main.CompiledBy={{ .Env.COMPILED_BY }} -X main.BranchName={{ .Env.BRANCH_NAME }} -X main.BuildTime={{ .Env.BUILD_TIME }}
- id: windows-amd64
main: ./
binary: helm-ls
goarch:
- amd64
goos:
- windows
env:
- CC=x86_64-w64-mingw32-gcc
- CXX=x86_64-w64-mingw32-g++
flags:
- -trimpath
- -buildmode=exe
ldflags:
- -X main.Version={{ .Env.GIT_COMMIT }} -X main.CompiledBy={{ .Env.COMPILED_BY }} -X main.BranchName={{ .Env.BRANCH_NAME }} -X main.BuildTime={{ .Env.BUILD_TIME }}
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

48 changes: 16 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ export ROOT=$(realpath $(dir $(firstword $(MAKEFILE_LIST))))
export BIN=$(ROOT)/bin
export GOBIN?=$(BIN)
export GO=$(shell which go)
export CGO_ENABLED=1
export GOX=$(BIN)/gox
export XGO=$(BIN)/xgo
export PACKAGE_NAME=github.com/mrjosh/helm-ls
export GOLANG_CROSS_VERSION=v1.20.6

$(eval GIT_COMMIT=$(shell git rev-parse --short HEAD))
$(eval BRANCH_NAME=$(shell git rev-parse --abbrev-ref HEAD))
Expand Down Expand Up @@ -46,10 +45,6 @@ lint:
echo "and fix them if necessary before submitting the code for reviewal."; \
fi

.PHONY: gox
gox:
@gox -output="dist/helm_ls_{{.OS}}_{{.Arch}}"

# for ci jobs, runs lint against the changed packages in the commit
ci-lint:
@$(LINTER) $(LINTERCMD) --deadline 10m ./...
Expand All @@ -62,28 +57,17 @@ install-metalinter:
test:
@$(GO) test ./... -v -race

install-gox:
@$(GO) install github.com/mitchellh/[email protected]

install-xgo:
@$(GO) install src.techknowlogick.com/xgo@latest


.PHONY: build-linux
build-linux: install-xgo
echo ${GO_LDFLAGS}
$(XGO) -dest dist -ldflags '$(GO_LDFLAGS)' -targets 'linux/amd64,linux/arm64' -out helm_ls .

.PHONY: build-macOS
build-macOS: install-xgo
$(XGO) -dest dist -ldflags '$(GO_LDFLAGS)' -targets 'darwin-10.12/amd64' -out helm_ls .

.PHONY: build-windows
build-windows: install-xgo
$(XGO) -buildmode exe -dest dist -ldflags '-linkmode external -extldflags "-static" $(GO_LDFLAGS)' -targets 'windows/amd64' -out helm_ls .

.PHONY: build-artifacts
build-artifacts:
@$(MAKE) build-linux && \
$(MAKE) build-macOS && \
$(MAKE) build-windows
.PHONY: build-release
build-release:
@docker run \
--rm \
-e CGO_ENABLED=1 \
-e COMPILED_BY=$(COMPILED_BY) \
-e BRANCH_NAME=$(BRANCH_NAME) \
-e BUILD_TIME=$(BUILD_TIME) \
-e GIT_COMMIT=$(GIT_COMMIT) \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
--clean --skip-validate --skip-publish --snapshot

0 comments on commit a6fc99e

Please sign in to comment.