Skip to content

Commit

Permalink
Add automatic release with goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
akupila committed May 12, 2018
1 parent 7ddd7f4 commit b204901
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 71 deletions.
57 changes: 49 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
version: 2
defaults: &defaults
docker:
- image: golang:1.10
working_directory: /go/src/github.com/akupila/gitprompt

jobs:
build:
docker:
- image: golang:1.10
working_directory: /go/src/github.com/akupila/gitprompt
<<: *defaults
steps:
- checkout

- run:
name: Install gometalinter
command: |
go get github.com/alecthomas/gometalinter
gometalinter --install
- run:
name: Run gometalinter
environment:
CGO_ENABLED: 0
command: |
gometalinter ./...
- run:
name: Test
command: |
Expand All @@ -28,10 +27,52 @@ jobs:
git config --global user.name "Test"
bash scripts/test.sh
bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN
- run:
name: Build
environment:
CGO_ENABLED: 0
command: |
go build -ldflags="-s -w" -o /out/gitprompt ./cmd/gitprompt
- persist_to_workspace:
root: .
paths: .
release:
<<: *defaults
steps:
- attach_workspace:
at: /go/src/github.com/akupila/gitprompt
- run:
name: Install goreleaser
command: |
go get github.com/goreleaser/goreleaser
- run:
name: Release
command: |
GOVERSION=$(go version) goreleaser
workflows:
version: 2
build:
jobs:
- build:
filters:
branches:
only: /.*/
tags:
ignore: /^v[0-9]+(\.[0-9]+)*/
build-and-release:
jobs:
- build:
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+(\.[0-9]+)*/
- release:
requires:
- build
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+(\.[0-9]+)*/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
coverage.txt
dist
21 changes: 21 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
project_name: gitprompt
builds:
- main: ./cmd/gitprompt
binary: gitprompt
ldflags: -s -w -X "main.version={{.Version}}" -X "main.commit={{.Commit}}" -X "main.date={{.Date}}" -X "main.goversion={{.Env.GOVERSION}}"
env:
- CGO_ENABLED=0
archive:
format: tar.gz
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
git:
short_hash: true
74 changes: 74 additions & 0 deletions cmd/gitprompt/gitprompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ package main

import (
"flag"
"fmt"
"os"
"strings"

"github.com/akupila/gitprompt"
)

var (
version = "dev"
commit = "none"
date = "unknown"
goversion = "unknown"
)

const defaultFormat = "#B([@b#R%h][#y ›%s][#m ↓%b][#m ↑%a][#r x%c][#g +%m][#y %u]#B)"

type formatFlag struct {
Expand Down Expand Up @@ -34,8 +43,73 @@ func (f *formatFlag) String() string {

var format formatFlag

var exampleStatus = &gitprompt.GitStatus{
Branch: "master",
Sha: "0455b83f923a40f0b485665c44aa068bc25029f5",
Untracked: 1,
Modified: 2,
Staged: 3,
Conflicts: 4,
Ahead: 5,
Behind: 6,
}

var formatHelp = func() string {
return strings.TrimSpace(fmt.Sprintf(`
Define output format.
Default format is: %q
Example result: %s
Data:
%%h Current branch or SHA1
%%s Number of files staged
%%b Number of commits behind remote
%%a Number of commits ahead of remote
%%c Number of conflicts
%%m Number of files modified
%%u Number of untracked files
Colors:
#k Black
#r Red
#g Green
#y Yellow
#b Blue
#m Magenta
#c Cyan
#w White
#K Highlight Black
#R Highlight Red
#G Highlight Green
#Y Highlight Yellow
#B Highlight Blue
#M Highlight Magenta
#C Highlight Cyan
#W Highlight White
Text attributes:
@b Set bold
@B Clear bold
@f Set faint/dim color
@F Clear faint/dim color
@i Set italic
@I Clear italic
`, defaultFormat, gitprompt.Print(exampleStatus, defaultFormat)))
}

func main() {
v := flag.Bool("version", false, "Print version inforformation.")
flag.Var(&format, "format", formatHelp())
flag.Parse()

if *v {
fmt.Printf("Version: %s\n", version)
fmt.Printf("Commit: %s\n", commit)
fmt.Printf("Build date: %s\n", date)
fmt.Printf("Go version: %s\n", goversion)
os.Exit(0)
}

gitprompt.Exec(format.String())
}
63 changes: 0 additions & 63 deletions cmd/gitprompt/help.go

This file was deleted.

0 comments on commit b204901

Please sign in to comment.