Skip to content

Commit

Permalink
feat: first commit
Browse files Browse the repository at this point in the history
Signed-off-by: thxCode <[email protected]>
  • Loading branch information
thxCode committed May 28, 2024
0 parents commit 6e851c1
Show file tree
Hide file tree
Showing 52 changed files with 6,021 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text=auto eol=lf

**/go.sum linguist-generated=true
**/zz_generated.*.go linguist-generated=true
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: ci

permissions:
contents: read
pull-requests: read
actions: read

defaults:
run:
shell: bash

on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'

jobs:
ci:
timeout-minutes: 15
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
persist-credentials: false
- name: Setup Go
timeout-minutes: 15
uses: actions/setup-go@v5
with:
go-version: "1.22.3"
cache-dependency-path: |
**/go.sum
- name: Setup Toolbox
timeout-minutes: 5
uses: actions/cache@v3
with:
key: toolbox-${{ runner.os }}
path: |
${{ github.workspace }}/.sbin
- name: Make
run: make ci
env:
LINT_DIRTY: "true"
44 changes: 44 additions & 0 deletions .github/workflows/cmd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: cmd

permissions:
contents: write
actions: read
id-token: write

defaults:
run:
shell: bash

on:
push:
tags:
- "v*.*.*"

jobs:
build:
timeout-minutes: 15
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
persist-credentials: false
- name: Setup Go
timeout-minutes: 15
uses: actions/setup-go@v5
with:
go-version: "1.22.3"
cache-dependency-path: |
**/go.sum
- name: Make
run: make build
env:
VERSION: "${{ github.ref_name }}"
- name: Release
uses: softprops/action-gh-release@v1
with:
fail_on_unmatched_files: true
tag_name: "${{ github.ref_name }}"
prerelease: ${{ contains(github.ref, 'rc') }}
files: ${{ github.workspace }}/.dist/*
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Files
.DS_Store
*.lock
*.test
*.out
*.swp
*.swo
*.db
*.exe
*.exe~
*.dll
*.so
*.dylib
*.log
go.work
go.work.*

# Dirs
/.idea
/.vscode
/.kube
/.terraform
/.vagrant
/.bundle
/.cache
/.docker
/.entc
/.sbin
/.dist
/log
/certs
146 changes: 146 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
run:
timeout: 10m
tests: true
modules-download-mode: readonly
go: "1.22"

# output configuration options
output:
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
path-prefix: ""
sort-results: true

linters:
disable-all: true
enable:
- asciicheck
- bidichk
- decorder
- durationcheck
- errcheck
- errname
- errorlint
- exportloopref
- godot
- goconst
- gocritic
- gosimple
- gosec
- govet
- gofumpt
- gofmt
- ineffassign
- importas
- lll
- makezero
- misspell
- nakedret
- nilerr
- prealloc
- predeclared
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- whitespace

linters-settings:
decorder:
dec-order:
- const
- var
- func
disable-init-func-first-check: false
disable-dec-order-check: true
errorlint:
errorf: true
asserts: true
comparison: true
godot:
scope: all
exclude:
- "(?i)^ FIXME:"
- "(?i)^ TODO:"
- "(?i)^ SPDX\\-License\\-Identifier:"
- "(?i)^ +"
period: true
capital: false
goconst:
min-len: 3
min-occurrences: 10
gosimple:
checks: [ "all" ]
gosec:
severity: "low"
confidence: "low"
excludes:
- G101
- G107
- G112
- G404
gofumpt:
extra-rules: true
gofmt:
simplify: true
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
- pattern: 'a[b:len(a)]'
replacement: 'a[b:]'
importas:
no-unaliased: true
lll:
line-length: 150
tab-width: 1
makezero:
always: false
misspell:
locale: US
nakedret:
max-func-lines: 60
revive:
rules:
- name: var-naming
disabled: true
arguments:
- [ "HTTP", "ID", "TLS", "TCP", "UDP", "API", "CA", "URL", "DNS" ]
staticcheck:
checks: [ "all", "-SA1019", "-SA2002", "-SA5008" ]
stylecheck:
checks: [ "all", "-ST1003" ]
unparam:
check-exported: false
unused:
field-writes-are-uses: true
post-statements-are-reads: true
exported-is-used: true
exported-fields-are-used: true
parameters-are-used: true
local-variables-are-used: true
generated-is-used: true
usestdlibvars:
http-method: true
http-status-code: true
time-weekday: true
time-month: true
time-layout: true
crypto-hash: true

issues:
exclude-files:
- "doc.go"
- "zz_generated.*.go"
- "gen.*.go"
exclude-rules:
- path: _test\.go
linters:
- errcheck
- gosec
- makezero
- lll
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 gguf-parser-go authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
86 changes: 86 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
.SILENT:
.DEFAULT_GOAL := ci

SHELL := /bin/bash

SRCDIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
LINT_DIRTY ?= false
VERSION ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null | tr '[:upper:]' '[:lower:]' || echo "unknown")

deps:
@echo "+++ deps +++"

go mod tidy
go mod download

@echo "--- deps ---"

generate:
@echo "+++ generate +++"

go generate $(SRCDIR)/...

@echo "--- generate ---"

lint:
@echo "+++ lint +++"

if [[ "$(LINT_DIRTY)" == "true" ]]; then \
if [[ -n $$(git status --porcelain) ]]; then \
echo "Code tree is dirty."; \
exit 1; \
fi; \
fi

[[ -f "$(SRCDIR)/.sbin/goimports-reviser" ]] || \
curl --retry 3 --retry-all-errors --retry-delay 3 -sSfL "https://github.com/incu6us/goimports-reviser/releases/download/v3.6.4/goimports-reviser_3.6.4_$(GOOS)_$(GOARCH).tar.gz" \
| tar -zxvf - --directory "$(SRCDIR)/.sbin" --no-same-owner --exclude ./LICENSE --exclude ./README.md && chmod +x "$(SRCDIR)/.sbin/goimports-reviser"
go list -f "{{.Dir}}" $(SRCDIR)/... | xargs -I {} find {} -maxdepth 1 -type f -name '*.go' ! -name 'gen.*' ! -name 'zz_generated.*' \
| xargs -I {} "$(SRCDIR)/.sbin/goimports-reviser" -use-cache -imports-order=std,general,company,project,blanked,dotted -output=file {}

[[ -f "$(SRCDIR)/.sbin/golangci-lint" ]] || \
curl --retry 3 --retry-all-errors --retry-delay 3 -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
| sh -s -- -b "$(SRCDIR)/.sbin" "v1.57.2"
"$(SRCDIR)/.sbin/golangci-lint" run --fix $(SRCDIR)/...

@echo "--- lint ---"

test:
@echo "+++ test +++"

go test -v -failfast -race -cover -timeout=30m $(SRCDIR)/...

@echo "--- test ---"

benchmark:
@echo "+++ benchmark +++"

go test -v -failfast -run="^Benchmark[A-Z]+" -bench=. -benchmem -timeout=30m $(SRCDIR)/...

@echo "--- benchmark ---"

gguf-parser:
@echo "+++ gguf-parser +++"
[[ -d "$(SRCDIR)/.dist" ]] || mkdir -p "$(SRCDIR)/.dist"

cd "$(SRCDIR)/cmd/gguf-parser" && for os in darwin linux windows; do \
for arch in amd64 arm64; do \
echo "Building gguf-parser for $$os-$$arch $(VERSION)"; \
if [[ $$os == "windows" ]]; then \
suffix=".exe"; \
else \
suffix=""; \
fi; \
GOOS="$$os" GOARCH="$$arch" CGO_ENABLED=1 go build \
-trimpath \
-ldflags="-w -s -X main.Version=$(VERSION)" \
-tags="netgo" \
-o $(SRCDIR)/.dist/gguf-parser-$$os-$$arch$$suffix; \
done; \
done

ci: deps generate test lint

build: gguf-parser
Loading

0 comments on commit 6e851c1

Please sign in to comment.