From 5ce7d8e28f284335ecd0235210a0ce02487518e5 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sat, 15 Jun 2024 09:35:02 +0200 Subject: [PATCH] feat: use Makefile --- .github/workflows/format.yml | 19 ++-------- .github/workflows/lint.yml | 7 ++-- .github/workflows/test.yml | 7 ++-- .github/workflows/vuln.yml | 12 ++---- Makefile | 71 ++++++++++++++++++++++++++++++++++++ README.md | 8 +++- 6 files changed, 92 insertions(+), 32 deletions(-) create mode 100644 Makefile diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 8fec53f5..58b5f5f6 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -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 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 511b97a4..9cd05080 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1096ae61..b077481e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: @@ -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 diff --git a/.github/workflows/vuln.yml b/.github/workflows/vuln.yml index 6976aa7c..99561283 100644 --- a/.github/workflows/vuln.yml +++ b/.github/workflows/vuln.yml @@ -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 diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..c1f103bf --- /dev/null +++ b/Makefile @@ -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 + diff --git a/README.md b/README.md index b8c99c5c..a004e99b 100644 --- a/README.md +++ b/README.md @@ -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.