From 8e4b8475ebc78da3a18cbfcbb19248d2f374272b Mon Sep 17 00:00:00 2001 From: Ian Lewis Date: Tue, 6 Sep 2022 05:26:00 +0000 Subject: [PATCH 1/2] Refactor Makefiles - Add Makefiles for compute-sha256 and detect-workflow actions. - Add pre-submit check that runs eslint. Signed-off-by: Ian Lewis --- .github/actions/compute-sha256/Makefile | 29 +++++++++++++++++++++ .github/actions/detect-workflow/Makefile | 33 ++++++++++++++++++++++++ .github/workflows/pre-submit.lint.yml | 9 +++++++ .github/workflows/pre-submit.units.yml | 32 ++--------------------- Makefile | 18 ++++++++----- 5 files changed, 84 insertions(+), 37 deletions(-) create mode 100644 .github/actions/compute-sha256/Makefile create mode 100644 .github/actions/detect-workflow/Makefile diff --git a/.github/actions/compute-sha256/Makefile b/.github/actions/compute-sha256/Makefile new file mode 100644 index 0000000000..3e4874833a --- /dev/null +++ b/.github/actions/compute-sha256/Makefile @@ -0,0 +1,29 @@ +SHELL := /bin/bash +OUTPUT_FORMAT = $(shell if [ "${GITHUB_ACTIONS}" == "true" ]; then echo "github"; else echo ""; fi) + +.PHONY: help +help: ## Shows all targets and help from the Makefile (this message). + @echo "compute-sha256 Makefile" + @echo "Usage: make [COMMAND]" + @echo "" + @grep --no-filename -E '^([/a-z.A-Z0-9_%-]+:.*?|)##' $(MAKEFILE_LIST) | \ + awk 'BEGIN {FS = "(:.*?|)## ?"}; { \ + if (length($$1) > 0) { \ + printf " \033[36m%-20s\033[0m %s\n", $$1, $$2; \ + } else { \ + if (length($$2) > 0) { \ + printf "%s\n", $$2; \ + } \ + } \ + }' + +node_modules/.installed: package.json package-lock.json + npm ci + touch node_modules/.installed + +## Testing +##################################################################### + +.PHONY: lint +lint: node_modules/.installed ## Runs eslint. + npm run lint diff --git a/.github/actions/detect-workflow/Makefile b/.github/actions/detect-workflow/Makefile new file mode 100644 index 0000000000..b183cd1fbb --- /dev/null +++ b/.github/actions/detect-workflow/Makefile @@ -0,0 +1,33 @@ +SHELL := /bin/bash +OUTPUT_FORMAT = $(shell if [ "${GITHUB_ACTIONS}" == "true" ]; then echo "github"; else echo ""; fi) + +.PHONY: help +help: ## Shows all targets and help from the Makefile (this message). + @echo "detect-workflow Makefile" + @echo "Usage: make [COMMAND]" + @echo "" + @grep --no-filename -E '^([/a-z.A-Z0-9_%-]+:.*?|)##' $(MAKEFILE_LIST) | \ + awk 'BEGIN {FS = "(:.*?|)## ?"}; { \ + if (length($$1) > 0) { \ + printf " \033[36m%-20s\033[0m %s\n", $$1, $$2; \ + } else { \ + if (length($$2) > 0) { \ + printf "%s\n", $$2; \ + } \ + } \ + }' + +## Testing +##################################################################### + +.PHONY: unit-test +unit-test: ## Runs all unit tests. + go mod vendor + go test -mod=vendor -v ./... + +## Build +##################################################################### + +.PHONY: build +build: ## Builds the docker image. + docker build . diff --git a/.github/workflows/pre-submit.lint.yml b/.github/workflows/pre-submit.lint.yml index 5c6f2ecc59..cd211739cb 100644 --- a/.github/workflows/pre-submit.lint.yml +++ b/.github/workflows/pre-submit.lint.yml @@ -62,3 +62,12 @@ jobs: # Run yamllint make yamllint + + eslint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - run: make eslint diff --git a/.github/workflows/pre-submit.units.yml b/.github/workflows/pre-submit.units.yml index e8f8a4b4c6..a0e7c9f136 100644 --- a/.github/workflows/pre-submit.units.yml +++ b/.github/workflows/pre-submit.units.yml @@ -26,38 +26,10 @@ jobs: with: go-version: "1.18" - - name: detect-workflow tests + - name: unit tests run: | set -euo pipefail - - cd .github/actions/detect-workflow - - # Download dependencies. - go mod vendor - - # Test. - go test -mod=vendor -v ./... - - - name: API tests - run: | - # Tests unit tests, including in generic and go builders - set -euo pipefail - - # Download dependencies. - go mod vendor - - # Test. - go test -mod=vendor -v ./... - - - name: Builder builds - run: | - set -euo pipefail - - # Build Go builder. - go build -mod=vendor ./internal/builders/go - - # Build Generic builder. - go build -mod=vendor ./internal/builders/generic + make unit-test check-verifier: name: verify slsa-verifier is latest diff --git a/Makefile b/Makefile index 0d8f5a5da1..4d83cf6eb1 100644 --- a/Makefile +++ b/Makefile @@ -20,13 +20,10 @@ help: ## Shows all targets and help from the Makefile (this message). ## Testing ##################################################################### +.PHONY: unit-test unit-test: ## Runs all unit tests. # Run unit tests for the detect-workflow action. - cd .github/actions/detect-workflow - go mod vendor - go test -mod=vendor -v ./... - # Run unit tests for the main package. - cd - + make -C .github/actions/detect-workflow/ unit-test go mod vendor go test -mod=vendor -v ./... @@ -34,9 +31,10 @@ unit-test: ## Runs all unit tests. ## Linters ##################################################################### -lint: ## Run all linters. -lint: golangci-lint shellcheck yamllint +.PHONY: lint +lint: golangci-lint shellcheck eslint yamllint ## Run all linters. +.PHONY: golangci-lint golangci-lint: ## Runs the golangci-lint linter. @set -e;\ extraargs=""; \ @@ -45,6 +43,7 @@ golangci-lint: ## Runs the golangci-lint linter. fi; \ golangci-lint run -c .golangci.yml ./... $$extraargs +.PHONY: shellcheck shellcheck: ## Runs the shellcheck linter. @set -e;\ FILES=$$(find . -type f -not -iwholename '*/.git/*' -not -iwholename '*/vendor/*' -not -iwholename '*/node_modules/*' -exec bash -c 'file "$$1" | cut -d':' -f2 | grep --quiet shell' _ {} \; -print); \ @@ -73,6 +72,11 @@ shellcheck: ## Runs the shellcheck linter. echo -n $$FILES | xargs shellcheck --external-sources; \ fi +.PHONY: eslint +eslint: ## Runs the eslint linter. + make -C .github/actions/compute-sha256 lint + +.PHONY: yamllint yamllint: ## Runs the yamllint linter. @set -e;\ extraargs=""; \ From 8a64a8184e55d43c5c2858399ea8c54ddad81867 Mon Sep 17 00:00:00 2001 From: Ian Lewis Date: Tue, 6 Sep 2022 05:31:39 +0000 Subject: [PATCH 2/2] Add eslint as a linter to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5e8d757e91..51bb7dda20 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,8 @@ install them on your development machine. - [yamllint](https://yamllint.readthedocs.io/) - [golangci-lint](https://golangci-lint.run/) - [shellcheck](https://www.shellcheck.net/) +- [eslint](https://eslint.org/) (NOTE: eslint is installed automatically so you + don't need to install it) Once each of these are installed you can run the linters using `make`.