Skip to content

Commit

Permalink
build: goreleaser
Browse files Browse the repository at this point in the history
* build: Test goreleaser

* Remove build flags

* Added linux build

* Added windows

* Ready to roll

---------

Co-authored-by: Vladimir Levin <[email protected]>
  • Loading branch information
opa-oz and opaoz authored Jun 23, 2024
1 parent 7a173d7 commit f391efa
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 29 deletions.
43 changes: 14 additions & 29 deletions .github/workflows/build-and-push-lsp.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
name: "Build and push new LSP"

on:
workflow_dispatch:
release:
types: [ created ]

permissions:
contents: write
packages: write

push:
tags:
- v*
jobs:
releases-matrix:
name: Release Go Binary
release:
runs-on: ubuntu-latest
strategy:
matrix:
goos: [ linux, windows, darwin ]
goarch: [ "386", amd64, arm64 ]
exclude:
- goarch: "386"
goos: darwin
- goarch: arm64
goos: windows
steps:
- uses: actions/checkout@v4
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goversion: "1.22"
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
binary_name: "pug-lsp"
ldflags: "-s -w"

- name: checkout code
uses: actions/checkout@v4
- run: git fetch --prune --unshallow
- name: setup dependencies
uses: actions/setup-go@v2
- name: setup release environment
run: |-
echo 'GITHUB_TOKEN=${{ github.token }}' > .release-env
- name: release publish
run: make release
17 changes: 17 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Build CI
on:
push:
branches:
- "main"

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v4
- run: git fetch --prune --unshallow
- name: setup dependencies
uses: actions/setup-go@v2
- name: release dry run
run: make release-dry-run
120 changes: 120 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
project_name: pug-lsp
env:
- CO111MODULE=on
- CGO_ENABLED=1
builds:
- id: darwin-amd64
binary: pug-lsp
main: ./main.go
goarch:
- amd64
goos:
- darwin
env:
- CC=o64-clang
- CXX=o64-clang++
flags:
- "-mod=readonly"
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}}
- id: darwin-arm64
binary: pug-lsp
main: ./main.go
goarch:
- arm64
goos:
- darwin
env:
- CC=oa64-clang
- CXX=oa64-clang++
flags:
- "-mod=readonly"
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}}
- id: linux-amd64
binary: pug-lsp
main: ./main.go
goarch:
- amd64
goos:
- linux
env:
- CC=x86_64-linux-gnu-gcc
- CXX=x86_64-linux-gnu-g++
flags:
- "-mod=readonly"
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}}
- id: linux-arm64
binary: pug-lsp
main: ./main.go
goarch:
- arm64
goos:
- linux
env:
- CC=aarch64-linux-gnu-gcc
- CXX=aarch64-linux-gnu-g++
flags:
- "-mod=readonly"
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}}
- id: windows-amd64
binary: pug-lsp
main: ./main.go
goarch:
- amd64
goos:
- windows
env:
- CC=x86_64-w64-mingw32-gcc
- CXX=x86_64-w64-mingw32-g++
flags:
- "-mod=readonly"
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}}
universal_binaries:
- id: darwin-universal
ids:
- darwin-amd64
- darwin-arm64
replace: true
name_template: "pug-lsp"
archives:
- format: zip
id: w/version
builds:
- darwin-universal
- darwin-amd64
- darwin-arm64
- linux-amd64
- linux-arm64
- windows-amd64
name_template: "pug-lsp_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
wrap_in_directory: false
- format: zip
id: wo/version
builds:
- darwin-universal
- darwin-amd64
- darwin-arm64
- linux-amd64
- linux-arm64
- windows-amd64
name_template: "pug-lsp_{{ .Os }}_{{ .Arch }}"
wrap_in_directory: false
checksum:
name_template: "pug-lsp_{{ .Version }}_checksums.txt"

release:
mode: replace
github:
owner: opa-oz
name: pug-lsp
prerelease: auto
draft: true
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
PACKAGE_NAME := github.com/opa-oz/pug-lsp
GOLANG_CROSS_VERSION ?= v1.21.5

.PHONY: help

help:
Expand All @@ -23,3 +26,32 @@ toc: ## Format README.md to add TOC
markdown-toc -i README.md

.PHONY: toc

.PHONY: release-dry-run
release-dry-run:
@docker run \
--rm \
-e CGO_ENABLED=1 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v `pwd`/sysroot:/sysroot \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
--clean --skip=validate --skip=publish

.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) \
-v `pwd`/sysroot:/sysroot \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --clean

0 comments on commit f391efa

Please sign in to comment.