From 461fd90abec28a22391f939d9b645eac8f5c4968 Mon Sep 17 00:00:00 2001 From: Roman Sharkov Date: Sun, 4 Aug 2024 12:38:32 +0200 Subject: [PATCH] ci: Use goreleaser --- .github/workflows/release.yml | 31 ++++++++++++++++++++++ .gitignore | 2 ++ .goreleaser.yml | 48 +++++++++++++++++++++++++++++++++++ internal/config/config.go | 2 +- 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2563c4c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,31 @@ +name: goreleaser + +on: + push: + # Run only on tags + tags: + - "*" + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: stable + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: "~> v1" + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 0759c92..2f79b0a 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ bin # Editors .idea + +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..9d2f0bc --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,48 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 2 + +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + # you may remove this if you don't need go generate + - go generate ./... + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + ldflags: + - "-X github.com/romshark/templier/internal/config.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/internal/config/config.go b/internal/config/config.go index 0d9800c..96ef2b3 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -20,7 +20,7 @@ import ( "github.com/romshark/yamagiconf" ) -// version is set from ldflags="-X internal/config.Version" +// version is set from ldflags="-X github.com/romshark/templier/internal/config.version" var version string var config Config