Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
firefart committed Sep 5, 2024
1 parent 3ea2a72 commit ff7aa18
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 64 deletions.
93 changes: 93 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# https://github.com/gitattributes/gitattributes/blob/master/Common.gitattributes

# Common settings that generally should always be used with your language specific settings

# Auto detect text files and perform LF normalization
* text=auto

#
# The above will handle all files NOT found below
#

# Documents
*.bibtex text diff=bibtex
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
*.md text diff=markdown
*.mdx text diff=markdown
*.tex text diff=tex
*.adoc text
*.textile text
*.mustache text
*.csv text eol=crlf
*.tab text
*.tsv text
*.txt text
*.sql text
*.epub diff=astextplain

# Graphics
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.tif binary
*.tiff binary
*.ico binary
# SVG treated as text by default.
*.svg text
# If you want to treat it as binary,
# use the following line instead.
# *.svg binary
*.eps binary

# Scripts
*.bash text eol=lf
*.fish text eol=lf
*.sh text eol=lf
*.zsh text eol=lf
# These are explicitly windows files and should use crlf
*.bat text eol=crlf
*.cmd text eol=crlf
*.ps1 text eol=crlf

# Serialisation
*.json text
*.toml text
*.xml text
*.yaml text
*.yml text

# Archives
*.7z binary
*.gz binary
*.tar binary
*.tgz binary
*.zip binary

# Text files where line endings should be preserved
*.patch -text

#
# Exclude files from exporting
#

.gitattributes export-ignore
.gitignore export-ignore
.gitkeep export-ignore

# https://github.com/gitattributes/gitattributes/blob/master/Go.gitattributes

# Treat all Go files in this repo as binary, with no git magic updating
# line endings. Windows users contributing to Go will need to use a
# modern version of git and editors capable of LF line endings.

*.go -text diff=golang
24 changes: 13 additions & 11 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ jobs:
with:
go-version: ${{ matrix.go }}

- name: Install Task
uses: arduino/setup-task@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check out code
uses: actions/checkout@v4

- name: build cache
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Get dependencies
run: |
go get -v -t -d ./...
run: task deps

- name: Install dependencies
run: task setup

- name: Build
run: make build
run: task build

- name: Test
run: task test
1 change: 1 addition & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout=5m
15 changes: 11 additions & 4 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,25 @@ jobs:
with:
go-version: "stable"

- name: Install Task
uses: arduino/setup-task@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: setup
run: task setup

- name: update
run: |
make update
run: task update

- name: setup git config
run: |
git config user.name "Github"
git config user.email "<>"
- name: commit changes
# need to override the default shell so we can check
# for error codes. Otherwise it will always fail if
# need to override the default shell, so we can check
# for error codes. Otherwise, it will always fail if
# one command returns an error code other than 0
shell: bash --noprofile --norc -o pipefail {0}
run: |
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
linters:
enable:
- nonamedreturns
- revive
29 changes: 15 additions & 14 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 2

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
- env:
- CGO_ENABLED=0
Expand All @@ -16,7 +25,7 @@ builds:

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
Expand All @@ -26,20 +35,12 @@ archives:
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
- goos: windows
format: zip

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

# The lines beneath this are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
- "^docs:"
- "^test:"
25 changes: 0 additions & 25 deletions Makefile

This file was deleted.

54 changes: 54 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: "3"

vars:
PROGRAM: cisco-snmp-pwner

tasks:
deps:
cmds:
- go mod tidy -v

update:
cmds:
- go get -u
- go mod tidy -v

setup:
cmds:
- go install mvdan.cc/gofumpt@latest

build:
aliases: [default]
deps: [deps]
env:
CGO_ENABLED: 0
cmds:
- go fmt ./...
- gofumpt -l -w .
- go vet ./...
- go build -o {{.PROGRAM}}

test:
deps: [deps]
env:
CGO_ENABLED: 1 # required by -race
cmds:
- go test -race -cover ./...

run:
deps: [build]
cmds:
- ./{{.PROGRAM}}

lint:
cmds:
- golangci-lint run ./... --timeout=30m
- go mod tidy

lint-update:
cmds:
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b {{ .GOPATH }}/bin
- golangci-lint --version
vars:
GOPATH:
sh: go env GOPATH
2 changes: 1 addition & 1 deletion helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func randomString(n int) string {
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
Expand Down
9 changes: 1 addition & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"bufio"
"fmt"
"math/rand"
"os"
"time"

Expand All @@ -13,13 +12,7 @@ import (
"github.com/urfave/cli/v2"
)

var (
log *logrus.Logger
)

func init() {
rand.Seed(time.Now().UnixNano())
}
var log *logrus.Logger

type options struct {
debug bool
Expand Down
2 changes: 1 addition & 1 deletion tftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (t tftpStuff) writeHandler(filenameRaw string, wt io.WriterTo) error {
}
filename = fmt.Sprintf("%s_%s", filename, randomString(5))

file, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0644)
file, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o644)
if err != nil {
log.Errorf("%v", err)
return err
Expand Down

0 comments on commit ff7aa18

Please sign in to comment.