Skip to content

Commit

Permalink
feat: add goreleaser for gt cli
Browse files Browse the repository at this point in the history
Signed-off-by: Engin Diri <engin.diri@mail.schwarz>
  • Loading branch information
Engin Diri committed Oct 19, 2021
1 parent 943c2b1 commit 9dc00d7
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 3 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Release

on:
push:
tags:
- '*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38 changes: 38 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
project_name: gt

snapshot:
name_template: '{{ .Tag }}-SNAPSHOT'

before:
hooks:
- go mod tidy

dist: bin

builds:
- id: gt
env:
- CGO_ENABLED=0
main: ./cmd/gt
ldflags:
- -s
- -w
- -extldflags '-static'
- -X github.com/schwarzit/go-template/config.GitCommit={{.ShortCommit}}
- -X github.com/schwarzit/go-template/config.Date={{.Date}}
binary: gt-{{ .Os }}-{{ .Arch }}
goos:
- linux
- windows
- darwin
ignore:
- goos: windows
goarch: arm64
no_unique_dist_dir: true
goarch:
- amd64
- arm64

archives:
- format: binary
name_template: "{{ .Binary }}"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@

### Install

If you have Go 1.16+, you can directly install by running:

```bash
go install github.com/schwarzit/go-template/cmd/gt@latest
```

#### Install from the released binaries
Download the desired version for your operating system and processor architecture from the [go-template releases page](https://github.com/SchwarzIT/go-template/releases).
Make the file executable and place it in a directory available in your $PATH.

### Initialize your repo from the template

[![asciicast](https://asciinema.org/a/441624.svg)](https://asciinema.org/a/441624?autoplay=1&speed=2&size=medium)
Expand Down
3 changes: 2 additions & 1 deletion config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
var (
Version = strings.TrimSpace(version)
VersionSemver = semver.MustParse(Version)

GitCommit = "HEAD"
Date string
//go:embed version.txt
version string
)
4 changes: 3 additions & 1 deletion pkg/gotemplate/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const (
)

func (gt *GT) PrintVersion() {
gt.printf(config.Version)
gt.printf("Version: %s\n", config.Version)
gt.printf("Git Commit: %s\n", config.GitCommit)
gt.printf("Build date: %s\n", config.Date)
}

func (gt *GT) CheckVersion() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/gotemplate/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gotemplate_test
import (
"bytes"
"context"
"fmt"
"strings"
"testing"

Expand All @@ -19,7 +20,7 @@ func TestGT_PrintVersion(t *testing.T) {
buffer := &bytes.Buffer{}
gt.Out = buffer
gt.PrintVersion()
assert.Equal(t, config.Version, strings.Trim(buffer.String(), "\n"))
assert.Equal(t, fmt.Sprintf("Version: %s\nGit Commit: HEAD\nBuild date: ", config.Version), strings.Trim(buffer.String(), "\n"))
}

func TestGT_CheckVersion(t *testing.T) {
Expand Down

0 comments on commit 9dc00d7

Please sign in to comment.