Skip to content

Commit

Permalink
Merge pull request #2 from jahnestacado/feature/workflows
Browse files Browse the repository at this point in the history
Feature/workflows
  • Loading branch information
jahnestacado authored Sep 2, 2022
2 parents ca13a46 + 1dfe0c0 commit d687c09
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 25 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build

on: [ push ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.13', '1.14', '1.15', '1.16', '1.17', '1.18' ]
name: Go ${{ matrix.go }} sample
steps:
- uses: actions/checkout@v2
with:
fetch-depth: '0'
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}

- name: Run tests
run: make test

- name: Upload test coverage to Codecov
uses: codecov/codecov-action@v3
if: matrix.go == '1.18'
with:
files: ./coverage.txt
fail_ci_if_error: true
verbose: true

- name: Run linter
run: make lint

- name: Run vulnerabilities scan
run: make scan

tag:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
with:
fetch-depth: '0'
- name: Bump version and push tag
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
WITH_V: true
VERBOSE: true
DEFAULT_BUMP: patch
17 changes: 17 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Release

on:
push:
tags:
- "v*"

jobs:
tagged-release:
name: "Tagged Release"
runs-on: "ubuntu-latest"

steps:
- uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.PAT }}"
prerelease: false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage.txt
102 changes: 102 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# This file contains all available configuration options
# with their default values (in comments).

# Options for analysis running.
run:
# The default concurrency value is the number of available CPU.
concurrency: 8

# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
timeout: 5m

# Exit code when at least one issue was found.
# Default: 1
issues-exit-code: 1

# Include test files or not.
# Default: true
tests: false

# Enables skipping of directories:
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
# Default: true
skip-dirs-use-default: true


# Allow multiple parallel golangci-lint instances running.
# If false (default) - golangci-lint acquires file lock on start.
allow-parallel-runners: true


# output configuration options
output:
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
#
# Multiple can be specified by separating them by comma, output can be provided
# for each of them by separating format name and path by colon symbol.
# Output path can be either `stdout`, `stderr` or path to the file to write to.
# Example: "checkstyle:report.json,colored-line-number"
#
# Default: colored-line-number
format: colored-line-number

# Print lines of code with issue.
# Default: true
print-issued-lines: true

# Print linter name in the end of issue text.
# Default: true
print-linter-name: true

# Make issues output unique by line.
# Default: true
uniq-by-line: true

# Add a prefix to the output file references.
# Default is no prefix.
path-prefix: ""

# Sort results by: filepath, line and column.
sort-results: true


linters:
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default-linters
enable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- goimports
- gofmt


# # Enable presets.
# # https://golangci-lint.run/usage/linters
# presets:
# - bugs
# - complexity
# - error
# - format
# - import
# - metalinter
# - module
# - performance
# - sql
# - style
# - test
# - unused

issues:
# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 3
max-same-issues: 50
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.DEFAULT_GOAL := help

#help: @ List available tasks on this project
help:
@grep -E '[a-zA-Z\.\-]+:.*?@ .*$$' $(MAKEFILE_LIST)| tr -d '#' | awk 'BEGIN {FS = ":.*?@ "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'


#test: @ Runs unit tests
test:
go test -race -v -coverprofile=coverage.txt -covermode=atomic

#test: @ Runs performance tests
bench:
go test -bench=.

#lint: @ Lints source code
lint:
docker run --rm -v ${CURDIR}:/app -w /app golangci/golangci-lint:v1.49.0 golangci-lint run -v

#scan: @ Scans source code dependencies for vulnerabilities
scan:
go list -json -deps | docker run --rm -i sonatypecommunity/nancy:v1.0.29 sleuth

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ err := cache.SetState(state)
### Run Tests

```sh
go test -v
make test
```

### Benchmarks

```sh
go test -bench=.
make bench
```

```
Expand Down
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module github.com/jahnestacado/tlru

go 1.13
go 1.18

require github.com/stretchr/testify v1.5.1

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
)
9 changes: 4 additions & 5 deletions tlru.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,10 @@ const (

type tlru struct {
sync.RWMutex
cache map[string]*doublyLinkedNode
config Config
headNode *doublyLinkedNode
tailNode *doublyLinkedNode
evictionPolicy evictionPolicy
cache map[string]*doublyLinkedNode
config Config
headNode *doublyLinkedNode
tailNode *doublyLinkedNode
}

// New returns a new instance of TLRU cache
Expand Down

0 comments on commit d687c09

Please sign in to comment.