ソースを参照

Add missing project files

Signed-off-by: Fletcher Nichol <fnichol@nichol.ca>
Fletcher Nichol 5 年 前
コミット
3e1b54a99a
6 ファイル変更94 行追加0 行削除
  1. 4 0
      .cirrus.yml
  2. 1 0
      .gitignore
  3. 1 0
      .prettierrc.yml
  4. 14 0
      Makefile
  5. 34 0
      vendor/mk/base.mk
  6. 40 0
      vendor/mk/shell.mk

+ 4 - 0
.cirrus.yml

@@ -0,0 +1,4 @@
+check_task:
+  container:
+    image: fnichol/check-shell:latest
+  check_script: make check

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+/tmp/

+ 1 - 0
.prettierrc.yml

@@ -0,0 +1 @@
+proseWrap: always

+ 14 - 0
Makefile

@@ -0,0 +1,14 @@
+include vendor/mk/base.mk
+include vendor/mk/shell.mk
+
+build:
+.PHONY: build
+
+test: test-shell ## Runs all tests
+.PHONY: test
+
+check: check-shell ## Checks all linting, styling, & other rules
+.PHONY: check
+
+clean: clean-shell ## Cleans up project
+.PHONY: clean

+ 34 - 0
vendor/mk/base.mk

@@ -0,0 +1,34 @@
+CHECK_TOOLS ?=
+TEST_TOOLS ?=
+
+all: clean build test check ## Runs clean, build, test, check
+.PHONY: all
+
+prepush: check test ## Runs all checks/test required before pushing
+	@echo "--- $@"
+	@echo "all prepush targets passed, okay to push."
+.PHONY: prepush
+
+checktools: ## Checks that required check tools are found on PATH
+	@echo "--- $@"
+	$(foreach tool, $(CHECK_TOOLS), $(if $(shell which $(tool)),, \
+		$(error "Required tool '$(tool)' not found on PATH")))
+.PHONY: checktools
+
+testtools: ## Checks that required test tools are found on PATH
+	@echo "--- $@"
+	$(foreach tool, $(TEST_TOOLS), $(if $(shell which $(tool)),, \
+		$(error "Required tool '$(tool)' not found on PATH")))
+.PHONY: testtools
+
+help: ## Prints help information
+	@printf -- "\033[1;36;40mmake %s\033[0m\n" "$@"
+	@echo
+	@echo "USAGE:"
+	@echo "    make [TARGET]"
+	@echo
+	@echo "TARGETS:"
+	@grep -hE '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk '\
+		BEGIN { FS = ":.*?## " }; \
+		{ printf "    \033[1;36;40m%-20s\033[0m %s\n", $$1, $$2 }'
+.PHONY: help

+ 40 - 0
vendor/mk/shell.mk

@@ -0,0 +1,40 @@
+SH_SOURCES ?= $(shell find . -type f -name '*.sh' -not -path './tmp/*' -and -not -path './vendor/*')
+SHELL_BIN ?= $(SHELL)
+SHUNIT2_VERSION := 2.1.7
+CHECK_TOOLS += shellcheck shfmt
+
+test-shell: testtools dl-shunit2 ## Runs all shell code tests
+	@echo "--- $@"
+	for test in $(SH_TESTS); do \
+		echo; echo "Running: $$test"; $(SHELL_BIN) $$test; done
+.PHONY: test-shell
+
+check-shell: shellcheck shfmt ## Checks linting & styling rules for shell code
+.PHONY: check-shell
+
+shellcheck: checktools ## Checks shell code for linting rules
+	@echo "--- $@"
+	shellcheck --external-sources $(SH_SOURCES)
+.PHONY: shellcheck
+
+shfmt: checktools ## Checks shell code for consistent formatting
+	@echo "--- $@"
+	shfmt -i 2 -ci -bn -d -l $(SH_SOURCES)
+.PHONY: shfmt
+
+clean-shell: ## Cleans up shell project
+	rm -rf tmp
+.PHONY: clean-shell
+
+dl-shunit2: tmp/shunit2 ## Downloads shUnit2
+.PHOHY: dl-shunit2
+
+tmp/shunit2: tmp/shunit2-$(SHUNIT2_VERSION)
+	@echo "--- $@"
+	ln -snf ./shunit2-$(SHUNIT2_VERSION) tmp/shunit2
+
+tmp/shunit2-$(SHUNIT2_VERSION):
+	@echo "--- $@"
+	mkdir -p $@
+	curl -sSfL https://github.com/kward/shunit2/archive/v$(SHUNIT2_VERSION).tar.gz \
+		| tar xzf - -C tmp/