diff --git a/.github/workflows/publish_binaries.yaml b/.github/workflows/publish_binaries.yaml new file mode 100644 index 00000000..28d15d5d --- /dev/null +++ b/.github/workflows/publish_binaries.yaml @@ -0,0 +1,29 @@ +name: publish-binaries + +on: + push: + tags: + - v*.*.* + +jobs: + build-and-push-binaries: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Create a Release on Github + uses: ncipollo/release-action@v1 + with: + generateReleaseNotes: true + makeLatest: true + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index ee9cd9ee..a1593447 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ konstraint* ## File-based project format: *.iws *.iml +# Added by goreleaser init: +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..d29b6c6f --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,39 @@ +version: 2 + +before: + hooks: + - go mod tidy + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + ldflags: + - -s + - -w + - -X 'github.com/plexsystems/konstraint/internal/commands.version={( .Version })' + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/Makefile b/Makefile index ed304025..2538047a 100644 --- a/Makefile +++ b/Makefile @@ -33,19 +33,5 @@ update-static: build ## Updates the static assets in the repository. fmt: ## Ensures consistent formatting on policy tests. conftest fmt examples -# -##@ Releases -# - -.PHONY: release -release: ## Builds the binaries for each OS and creates the checksums. - @test $(version) - GOOS=darwin GOARCH=amd64 go build -o build/konstraint-darwin-amd64 -ldflags="-s -w -X 'github.com/plexsystems/konstraint/internal/commands.version=$(version)'" - GOOS=darwin GOARCH=arm64 go build -o build/konstraint-darwin-arm64 -ldflags="-s -w -X 'github.com/plexsystems/konstraint/internal/commands.version=$(version)'" - GOOS=windows GOARCH=amd64 go build -o build/konstraint-windows-amd64.exe -ldflags="-s -w -X 'github.com/plexsystems/konstraint/internal/commands.version=$(version)'" - GOOS=linux GOARCH=amd64 go build -o build/konstraint-linux-amd64 -ldflags="-s -w -X 'github.com/plexsystems/konstraint/internal/commands.version=$(version)'" - GOOS=linux GOARCH=arm64 go build -o build/konstraint-linux-arm64 -ldflags="-s -w -X 'github.com/plexsystems/konstraint/internal/commands.version=$(version)'" - docker run --user $(shell id -u):$(shell id -g) --rm -v $(shell pwd):/konstraint alpine:3 /bin/ash -c 'cd /konstraint/build && sha256sum konstraint-* > checksums.txt' - help: @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)