Skip to content

Refactor Makefiles #792

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

Merged
merged 3 commits into from
Sep 7, 2022
Merged
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
29 changes: 29 additions & 0 deletions .github/actions/compute-sha256/Makefile
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions .github/actions/detect-workflow/Makefile
Original file line number Diff line number Diff line change
@@ -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 .
9 changes: 9 additions & 0 deletions .github/workflows/pre-submit.lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 2 additions & 30 deletions .github/workflows/pre-submit.units.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,21 @@ 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 ./...


## 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=""; \
Expand All @@ -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); \
Expand Down Expand Up @@ -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=""; \
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down