Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update configs and scripts (#310) #312

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 40 additions & 13 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
name: Cobrass Continuous Integration


on:
push:

Expand All @@ -7,43 +9,68 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: 1.22
go-version: 1.23
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.56.2
version: v1.60.3
args: --verbose

test:
strategy:
matrix:
go-version: [1.22]
go-version: [1.23]
platform: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.platform }}

env:
COVER_DIR: ${{ github.workspace }}/coverage
COVER_FILE: coverage.out
COVER_OUT_PATH: ${{ github.workspace }}/coverage/coverage.out
COVER_HTML_PATH: ${{ github.workspace }}/coverage/coverage.html
GINKGO_REPORT: ginkgo.report

steps:
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Install goveralls
run: go install github.com/mattn/goveralls@latest

- name: Install ginkgo
run: go install github.com/onsi/ginkgo/v2/[email protected]

- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- run: go test -v -coverprofile=coverage.out ./...
- name: Ensure coverage directory exists
run: |
mkdir -p ${{ github.workspace }}/coverage

- name: Run tests and generate coverage profile with Ginkgo
run: |
ginkgo run -r -json-report {{env.GINKGO_REPORT}} -coverpkg=./... -coverprofile=coverage.out

- uses: shogo82148/actions-goveralls@v1
- name: Apply coverage exclusions
run: |
${{ github.workspace }}/scripts/apply-coverage-exclusions.sh

- name: Check coverage directory contents
run: |
echo "Contents of ${{ github.workspace }}/coverage:"
ls -la ${{ github.workspace }}/coverage

- name: Generate HTML coverage report
run: |
go tool cover -html=coverage.out -o ${{ github.workspace }}/coverage/coverage.html

- name: Upload coverage to Coveralls
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out

- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=coverage.out -service=github
35 changes: 35 additions & 0 deletions .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Cobrass Release

on:
push:
tags:
- '*'

permissions:
contents: write

jobs:
goreleaser:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Git Fetch
run: git fetch --force --tags
- name: Setup
uses: actions/setup-go@v3
with:
go-version: '>=1.23'
cache: true
- name: Generate Changelog Only
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ generators/gola/out/
.env

coverage
coverage.out
ginkgo.report
report.json
coverage.html

src/assistant/internal/l10n/out/translate.en-US.json

Expand Down
24 changes: 10 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ linters-settings:
goconst:
min-len: 2
min-occurrences: 3
# since upgrading to v1.22.0 of go:
# ERRO [linters_context] gocritic: load embedded ruleguard
# rules: rules/rules.go:13: can't load fmt: setting an explicit GOROOT can fix this problem.
#
gocritic:
enabled-tags:
- diagnostic
Expand All @@ -16,43 +12,43 @@ linters-settings:
- performance
- style
govet:
check-shadowing: true
shadow: true
disable:
- fieldalignment # too strict

nolintlint:
require-explanation: true
require-explanation: false
require-specific: true

linters:
disable-all: true
enable:
- bodyclose
# - deadcode
# depguard needs to be reviewed properly and then configured, before
# it can be re-enabled.
# https://github.com/OpenPeeDeeP/depguard#example-configs
# - depguard
- copyloopvar
- dogsled
# - dupl
- errcheck
- exportloopref
- exhaustive
- goconst
- gocritic
- gofmt
- goimports
- gomnd
- gocyclo
- gosec
- gosimple
- govet
- ineffassign
- misspell
- mnd
- nolintlint
- nakedret
- prealloc
- predeclared
# - revive // over-bearing for generated code, too many instances
- revive
- staticcheck
# - structcheck
- stylecheck
Expand All @@ -70,10 +66,10 @@ issues:
fix: true
exclude:
- "cuddle"
exclude-files:
- ".*-auto\\.go$"
- ".*-auto_test\\.go$"

run:
skip-dirs:
- /generators/gola/templates
skip-files:
- .*\.tmpl$
issues-exit-code: 1
timeout: "5m"
51 changes: 51 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
before:
hooks:
- go mod tidy
# ? do we need a - go mod generate
# - go mod generate

builds:
- id: "cobrass"
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
no_main_check: true
skip: true

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- 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"
changelog:
use: github
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
groups:
- title: "🚀 Features"
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
order: 0
- title: "🐛 Bug fixes"
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
order: 1
- title: "🥝 Others"
order: 999
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.54.2
rev: v1.56.2
hooks:
- id: golangci-lint

Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"cogen",
"colors",
"Comparables",
"copyloopvar",
"deadcode",
"depguard",
"dogsled",
Expand All @@ -38,13 +39,15 @@
"gomega",
"gomnd",
"gomock",
"gomod",
"GOROOT",
"gosec",
"gosimple",
"goveralls",
"govet",
"gradientf",
"gradientsf",
"incpatch",
"ineffassign",
"infex",
"Infexion",
Expand All @@ -56,6 +59,7 @@
"memfs",
"mockgen",
"nakedret",
"nefilim",
"nicksnyder",
"nolint",
"nolintlint",
Expand Down
16 changes: 8 additions & 8 deletions generators/gola/content-parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"

"github.com/samber/lo"
"github.com/snivilised/cobrass/generators/gola/internal/storage"
nef "github.com/snivilised/nefilim"
)

// parseInline does not need to use the filesystem to acquire
Expand All @@ -20,26 +20,26 @@ func parseInline(contents CodeContent) (*SignatureResult, error) {
}

// parseFromFS parses content acquired from the filesystem.
func parseFromFS(vfs storage.VirtualFS, directoryPath string) (*SignatureResult, error) {
func parseFromFS(fS nef.ReaderFS, directoryPath string) (*SignatureResult, error) {
var (
entries []fs.DirEntry
contents CodeContent
readErr, acqErr error
)

if entries, readErr = readEntries(vfs, directoryPath); readErr != nil {
if entries, readErr = readEntries(fS, directoryPath); readErr != nil {
return nil, readErr
}

if contents, acqErr = acquire(vfs, directoryPath, entries); acqErr != nil {
if contents, acqErr = acquire(fS, directoryPath, entries); acqErr != nil {
return nil, acqErr
}

return parseContents(contents)
}

func readEntries(vfs storage.VirtualFS, directoryPath string) ([]fs.DirEntry, error) {
entries, err := vfs.ReadDir(directoryPath)
func readEntries(fS nef.ReaderFS, directoryPath string) ([]fs.DirEntry, error) {
entries, err := fS.ReadDir(directoryPath)

if err != nil {
return nil, err
Expand All @@ -64,13 +64,13 @@ func readEntries(vfs storage.VirtualFS, directoryPath string) ([]fs.DirEntry, er
return entries, nil
}

func acquire(vfs storage.VirtualFS, directoryPath string, entries []fs.DirEntry) (CodeContent, error) {
func acquire(fS nef.ReaderFS, directoryPath string, entries []fs.DirEntry) (CodeContent, error) {
contents := make(CodeContent, len(entries))

for _, entry := range entries {
name := entry.Name()
sourcePath := filepath.Join(directoryPath, name)
c, err := vfs.ReadFile(sourcePath)
c, err := fS.ReadFile(sourcePath)

if err != nil {
return nil, err
Expand Down
Loading
Loading