Skip to content

Commit

Permalink
Set up CI with Azure Pipelines
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
deanishe committed Oct 18, 2019
1 parent c24de3c commit a02ee17
Show file tree
Hide file tree
Showing 20 changed files with 156 additions and 38 deletions.
37 changes: 37 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[run]
deadline = "5m"

[linters]
disable-all = true
enable = [
"deadcode",
"goconst",
"gofmt",
"goimports",
"ineffassign",
"scopelint",
"staticcheck",
"stylecheck",
"unconvert",
"unused",
# "maligned",
# "lll",
# "prealloc",
]

[linter-settings]
[linter-settings.errcheck]
check-blank = true
check-type-assertions = true

[linter-settings.goimports]
local-prefixes = "github.com/deanishe/awgo"

[issues]
max-same-issues = 50
max-issues-per-linter = 50
# exclude = ['ST1005']

[[issues.exclude-rules]]
linters = ['stylecheck']
text = "ST1005:"
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
AwGo — A Go library for Alfred workflows
========================================

[![Build Status][build-status-icon]][travis-link]
[![Build Status][azure-status-icon]][azure-link]
[![Go Report Card][goreport-icon]][goreport-link]
[![Codacy coverage][coverage-icon]][codacy-link]
[![GoDoc][godoc-icon]][godoc-link]
Expand Down Expand Up @@ -175,12 +175,14 @@ The icon is based on the [Go Gopher][gopher] by [Renee French][renee].
[godoc-link]: https://godoc.org/github.com/deanishe/awgo
[goreport-link]: https://goreportcard.com/report/github.com/deanishe/awgo
[goreport-icon]: https://goreportcard.com/badge/github.com/deanishe/awgo
[build-status-icon]: https://img.shields.io/travis/deanishe/awgo
[azure-status-icon]: https://img.shields.io/azure-devops/build/deanishe/6cd8e4fe-7366-4485-aea6-e9d75e7757b2/1
[azure-link]: https://dev.azure.com/deanishe/AwGo/_build
[coverage-icon]: https://img.shields.io/codacy/coverage/e785f7b0e830468da6fa2856d62e59ab?color=brightgreen
[travis-link]: https://travis-ci.org/deanishe/awgo
[codacy-link]: https://www.codacy.com/app/deanishe/awgo

<!--
[travis-status-icon]: https://img.shields.io/travis/deanishe/awgo
[travis-link]: https://travis-ci.org/deanishe/awgo
[codacy-quality-icon]: https://api.codacy.com/project/badge/Grade/e785f7b0e830468da6fa2856d62e59ab
[codacy-coverage-icon]: https://api.codacy.com/project/badge/Coverage/e785f7b0e830468da6fa2856d62e59ab
[coveralls-icon]: https://coveralls.io/repos/github/deanishe/awgo/badge.svg?branch=master&v3
Expand Down
73 changes: 73 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Go
# Build your Go project.
# Add steps that test, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/go

trigger:
- master

pool:
vmImage: 'macOS-10.13'

variables:
GOBIN: '$(GOPATH)/bin' # Go binaries path
GOROOT: '/usr/local/opt/go/libexec' # Go installation path
GOPATH: '$(system.defaultWorkingDirectory)/gopath' # Go workspace path
BUILD_NUMBER: '$(Build.BuildNumber)'
CI_PULL_REQUEST: '$(Build.SourceBranch)'
CI_PKG_NAME: 'github.com/$(Build.Repository.Name)'
PR_COMMIT: '$(System.PullRequest.SourceCommitId)'
BASE_COMMIT: '$(Build.SourceVersion)'
CODACY_TOKEN: '$(CodacyToken)'
CODECOV_TOKEN: '$(CodeCovToken)'
# COVERALLS_TOKEN: '$(CoverallsToken)'
modulePath: '$(GOPATH)/src/github.com/$(build.repository.name)' # Path to the module's code

steps:
- script: |
mkdir -p '$(GOBIN)'
mkdir -p '$(GOPATH)/pkg'
mkdir -p '$(modulePath)'
shopt -s extglob
shopt -s dotglob
mv !(gopath) '$(modulePath)'
echo '##vso[task.prependpath]$(GOBIN)'
echo '##vso[task.prependpath]$(GOROOT)/bin'
go version
displayName: 'Set up Go'

- script: |
go get -v -t -d ./...
workingDirectory: '$(modulePath)'
displayName: Fetch Code

- script: |
curl -fsSL https://github.com/golangci/golangci-lint/releases/download/v1.20.1/golangci-lint-1.20.1-darwin-amd64.tar.gz | tar -C '$(GOBIN)' -xz --strip-components=1 --include='*golangci-lint'
golangci-lint run -c .golangci.toml
workingDirectory: '$(modulePath)'
displayName: Lint

- script: |
./run-tests.sh -ic ./...
workingDirectory: '$(modulePath)'
displayName: Run Tests

# Coveralls doesn't work with Azure
# - displayName: Coveralls
# script: |
# go get github.com/mattn/goveralls
# goveralls -coverprofile=coverage.out -service=local; true
# workingDirectory: '$(modulePath)'
# displayName: 'coveralls.io'
- script: |
echo "PR_COMMIT=$PR_COMMIT"
echo "BASE_COMMIT=$BASE_COMMIT"
go get github.com/schrej/godacov
if [[ "$PR_COMMIT" != "" ]]; then
godacov -r coverage.out -t $(CODACY_TOKEN) -c $(PR_COMMIT); true
else
godacov -r coverage.out -t $(CODACY_TOKEN) -c $(BASE_COMMIT); true
fi
bash <(curl -s https://codecov.io/bash); true
workingDirectory: '$(modulePath)'
displayName: Coverage
8 changes: 4 additions & 4 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestCache_LoadOrStore(t *testing.T) {
withTempDir(func(dir string) {
c := NewCache(dir)
n := "test.txt"
maxAge := time.Duration(time.Second * 1)
maxAge := time.Second

// Sanity checks
p := c.path(n)
Expand All @@ -109,7 +109,7 @@ func TestCache_LoadOrStore(t *testing.T) {
assert.Equal(t, []byte(s), data, "unexpected cache data")
assert.False(t, reloadCalled, "reload called")

time.Sleep(time.Duration(time.Second * 1))
time.Sleep(time.Second)

assert.True(t, c.Expired(n, maxAge), "cache not expired")

Expand Down Expand Up @@ -183,7 +183,7 @@ func TestCache_LoadOrStoreJSON(t *testing.T) {
withTempDir(func(dir string) {
n := "test.json"
c := NewCache(dir)
maxAge := time.Duration(time.Second * 1)
maxAge := time.Second

// Sanity checks
require.False(t, util.PathExists(c.path(n)), "cache file already exists")
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestCache_LoadOrStoreJSON(t *testing.T) {
assert.Equal(t, a, b, "unexpected cache data")
assert.False(t, reloadCalled, "reload was called")

time.Sleep(time.Duration(time.Second * 1))
time.Sleep(time.Second)

assert.True(t, c.Expired(n, maxAge), "cache has not expired")

Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (cfg *Config) GetInt(key string, fallback ...int) int {
return fb
}

return int(i)
return i
}

// GetFloat returns the value for envvar "key" as a float.
Expand Down
7 changes: 7 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ func TestGet(t *testing.T) {

// Verify env is the same
for k, x := range env {
k, x := k, x
t.Run(fmt.Sprintf("Config.Get(%q)", k), func(t *testing.T) {
assert.Equal(t, x, cfg.Get(k), "unexpected value")
})
}

// Test Get
for _, td := range data {
td := td
t.Run(fmt.Sprintf("Config.Get(%q)", td.key), func(t *testing.T) {
assert.Equal(t, td.out, cfg.Get(td.key, td.fb...), "unexpected value")
})
Expand Down Expand Up @@ -129,6 +131,7 @@ func TestGetInt(t *testing.T) {
cfg := NewConfig(env)
// Test GetInt
for _, td := range data {
td := td
t.Run(fmt.Sprintf("Config.GetInt(%v)", td.key), func(t *testing.T) {
assert.Equal(t, td.out, cfg.GetInt(td.key, td.fb...), "unexpected value")
})
Expand Down Expand Up @@ -169,6 +172,7 @@ func TestGetFloat(t *testing.T) {
cfg := NewConfig(env)
// Test GetFloat
for _, td := range data {
td := td
t.Run(fmt.Sprintf("Config.GetFloat(%v)", td.key), func(t *testing.T) {
assert.Equal(t, td.out, cfg.GetFloat(td.key, td.fb...), "unexpected value")
})
Expand Down Expand Up @@ -211,6 +215,7 @@ func TestGetDuration(t *testing.T) {

// Test GetDuration
for _, td := range data {
td := td
t.Run(fmt.Sprintf("Config.GetDuration(%v)", td.key), func(t *testing.T) {
assert.Equal(t, td.out, cfg.GetDuration(td.key, td.fb...), "unexpected value")
})
Expand Down Expand Up @@ -257,6 +262,7 @@ func TestGetBool(t *testing.T) {

// Test GetBool
for _, td := range data {
td := td
t.Run(fmt.Sprintf("Config.GetBool(%q)", td.key), func(t *testing.T) {
assert.Equal(t, td.out, cfg.GetBool(td.key, td.fb...), "unexpected value")
})
Expand All @@ -281,6 +287,7 @@ func TestStringify(t *testing.T) {
}

for _, td := range data {
td := td
t.Run(fmt.Sprintf("stringify(%#v)", td.in), func(t *testing.T) {
assert.Equal(t, td.out, stringify(td.in), "unexpected value")
})
Expand Down
2 changes: 1 addition & 1 deletion env.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func validateEnv(env Env) error {
}

if issues != nil {
return fmt.Errorf("Invalid Workflow environment: %s", strings.Join(issues, ", "))
return fmt.Errorf("invalid Workflow environment: %s", strings.Join(issues, ", "))
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions feedback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ func TestEmptyModifiersIgnored(t *testing.T) {
}

for _, td := range tests {
td := td
t.Run(fmt.Sprintf("%v", td.keys), func(t *testing.T) {
it := fb.NewItem("title")
require.Equal(t, 0, len(it.mods), "unexpected modifier count")
Expand Down Expand Up @@ -365,6 +366,7 @@ func TestMultipleModifiers(t *testing.T) {
}

for _, td := range tests {
td := td
t.Run(fmt.Sprintf("%v", td.keys), func(t *testing.T) {
m := it.NewModifier(td.keys...)
assert.Equal(t, td.x, string(m.Key), "unexpected modifier")
Expand Down
8 changes: 2 additions & 6 deletions fuzzy/fuzzy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"unicode"

"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
Expand Down Expand Up @@ -316,15 +317,10 @@ func (s strSlice) Sort(query string) []*Result {
return Sort(s, query)
}

// isMn returns true if rune is a non-spacing mark
func isMn(r rune) bool {
return unicode.Is(unicode.Mn, r) // Mn: non-spacing mark
}

// stripDiacritics removes diacritics.
// Strings are decomposed, then non-ASCII characters are removed.
func stripDiacritics(s string) string {
stripper := transform.Chain(norm.NFD, transform.RemoveFunc(isMn))
stripper := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)))
stripped, _, err := transform.String(stripper, s)
if err != nil {
log.Printf("Couldn't strip diacritics from `%s`: %s", s, err)
Expand Down
4 changes: 4 additions & 0 deletions fuzzy/fuzzy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestSortStrings(t *testing.T) {
}

for _, td := range tests {
td := td
t.Run(td.q, func(t *testing.T) {
data := td.in[:]
SortStrings(data, td.q)
Expand All @@ -56,6 +57,7 @@ func TestMatchNoMatch(t *testing.T) {
}

for _, td := range tests {
td := td
t.Run(td.s, func(t *testing.T) {
data := []string{td.s}
r := SortStrings(data, td.q)
Expand Down Expand Up @@ -92,6 +94,7 @@ func TestFirstMatch(t *testing.T) {
}

for _, td := range tests {
td := td
t.Run(td.q, func(t *testing.T) {
data := td.in[:]
r := SortStrings(data, td.q)
Expand Down Expand Up @@ -123,6 +126,7 @@ func TestStripDiacritics(t *testing.T) {
}

for _, td := range tests {
td := td
t.Run(fmt.Sprintf("%q=%q", td.q, td.s), func(t *testing.T) {
assert.Equal(t, td.x, Match(td.s, td.q, StripDiacritics(td.strip)).Match, "unexpected match")
})
Expand Down
2 changes: 1 addition & 1 deletion magic.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (ma *magicActions) handleArgs(args []string, prefix string) ([]string, bool

if action != nil {

log.Printf(action.RunText())
log.Print(action.RunText())

ma.wf.NewItem(action.RunText()).
Icon(IconInfo).
Expand Down
2 changes: 2 additions & 0 deletions magic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func TestMagicExits(t *testing.T) {

// test wf.magicActions
for _, td := range tests {
td := td
withTestWf(func(wf *Workflow) {
me := &mockExit{}
exitFunc = me.Exit
Expand All @@ -212,6 +213,7 @@ func TestMagicExits(t *testing.T) {

// test wf.args
for _, td := range tests {
td := td
withTestWf(func(wf *Workflow) {
me := &mockExit{}
exitFunc = me.Exit
Expand Down
1 change: 1 addition & 0 deletions testutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func TestWithTestWf(t *testing.T) {
assert.Equal(t, tDebug, wf.Debug(), "unexpected debug")

for _, td := range data {
td := td
t.Run(td.name, func(t *testing.T) {
assert.Equal(t, td.x, td.v, "unexpected variable")
})
Expand Down
3 changes: 2 additions & 1 deletion update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

var (
// UpdateInterval is how often to check for updates.
UpdateInterval = time.Duration(24 * time.Hour)
UpdateInterval = 24 * time.Hour
// HTTPTimeout is the timeout for establishing an HTTP(S) connection.
HTTPTimeout = 60 * time.Second

Expand Down Expand Up @@ -302,6 +302,7 @@ func (u *Updater) latest() *Download {
return nil
}
for _, dl := range u.downloads {
dl := dl
if dl.Prerelease && !u.Prereleases {
continue
}
Expand Down
Loading

0 comments on commit a02ee17

Please sign in to comment.