Skip to content

Commit

Permalink
feat: use Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jun 15, 2024
1 parent b3d1b01 commit 5ce7d8e
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 32 deletions.
19 changes: 4 additions & 15 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,7 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Run gci
run: |
go install github.com/daixiang0/gci@latest
gci write --skip-generated --skip-vendor -s standard -s default .
working-directory: ./tests/go
- name: Run golines
run: |
go install mvdan.cc/gofumpt@latest
go install github.com/segmentio/golines@latest
golines --base-formatter=gofumpt --ignore-generated --tab-len=1 --max-len=120 --write-output .
working-directory: ./tests/go
- name: Check git diff
run: |
git diff --exit-code
working-directory: ./tests/go
- name: Install Go formatting tooling
run: make install-format-go
- name: Formating check
run: make format-go
7 changes: 3 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Install golangci-lint
run: make install-lint-go
- name: Run golangci-lint
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint run ./...
working-directory: ./tests/go
run: make lint-go
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start
- name: Run tests
run: nvim --headless -c "PlenaryBustedDirectory tests {minimal_init = 'tests/minimal_init.lua', sequential = true}"
run: make test-lua
go:
runs-on: ubuntu-latest
steps:
Expand All @@ -37,6 +37,5 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Check tests
run: go test ./...
working-directory: ./tests/go
- name: Run tests
run: make test-go
12 changes: 4 additions & 8 deletions .github/workflows/vuln.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Go vet (vulnerabilities)
run: go vet ./...
working-directory: ./tests/go
- name: Run gosec (security)
run: |
go install github.com/securego/gosec/v2/cmd/gosec@latest
gosec ./...
working-directory: ./tests/go
- name: Install gosec
run: make install-vuln-go
- name: Run vulnerability check
run: make vuln-go
71 changes: 71 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
TESTS_INIT=tests/minimal_init.lua
TESTS_DIR=tests/

# --- Default targets ---

.PHONY: install
install: install-go-tooling
.PHONY: install-go-tooling
install-go-tooling: install-format-go install-lint-go install-vuln-go
.PHONY: all
all: test format lint vuln git-diff
.PHONY: test
test: test-lua test-go
.PHONY: format
format: format-go
.PHONY: lint
lint: lint-go
.PHONY: vuln
vuln: vuln-go


# --- Targets ---

.PHONY: test-lua
test-lua:
nvim \
--headless \
--noplugin \
-u ${TESTS_INIT} \
-c "PlenaryBustedDirectory ${TESTS_DIR} { minimal_init = '${TESTS_INIT}' }"

.PHONY: test-go
test-go:
cd tests/go && \
go test -v ./...

.PHONY: format-go
format-go:
cd tests/go && \
gci write --skip-generated --skip-vendor -s standard -s default . && \
golines --base-formatter=gofumpt --ignore-generated --tab-len=1 --max-len=120 --write-output . && \
git diff --exit-code

.PHONY: lint-go
lint-go:
cd tests/go && \
golangci-lint run --verbose ./...

.PHONY: vuln-go
vuln-go:
cd tests/go && \
go vet ./... && \
gosec ./...


# --- Installation of tooling ---

.PHONY: install-format-go
install-format-go:
go install github.com/daixiang0/gci@latest && \
go install github.com/segmentio/golines@latest && \
go install mvdan.cc/gofumpt@latest # NOTE: golines uses gofumpt

.PHONY: install-lint-go
install-lint-go:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

.PHONY: install-vuln-go
install-vuln-go:
go install github.com/securego/gosec/v2/cmd/gosec@latest

8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,10 @@ return {
## 🙏 PRs are welcome

Improvement suggestion PRs to this repo are very much welcome, and I encourage
you to begin in the discussions in case the change is not trivial.
you to begin in the [discussions](discussions) in case the change is not
trivial.

You can run tests, formatting and linting locally with `make all`. Install
dependencies with `make install`. Have a look at the [Makefile](Makefile) for
more details. You can also use the neotest-plenary and neotest-golang adapters
to run the tests of this repo within Neovim.

0 comments on commit 5ce7d8e

Please sign in to comment.