Skip to content
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

chore: ran the Makefile through a linter #5

Merged
merged 1 commit into from
Oct 5, 2023
Merged
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
84 changes: 44 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,77 +1,81 @@
SHELL := /bin/bash
.DEFAULT_GOAL := help
.ONESHELL:

define check_var
@if [ -z "$($1)" ]; then
echo >&2 "Please set the $1 variable";
exit 2;
fi
endef

SUBDIR = $(shell ls apps)

.PHONY: help
## help: shows this help message
help:
@ echo "Usage: make [target]"
@ sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
@echo "Usage: make [target]"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'

.PHONY: go-lint
## go-lint: runs linter for a given directory, specified via PACKAGE variable
go-lint:
@ if [ -z "$(PACKAGE)" ]; then echo >&2 please set directory via variable PACKAGE; exit 2; fi
@ docker run --rm -v "`pwd`:/workspace:cached" -w "/workspace/$(PACKAGE)" golangci/golangci-lint:latest golangci-lint run
go-lint:
$(call check_var,PACKAGE)
docker run --rm -v "`pwd`:/workspace:cached" -w "/workspace/$(PACKAGE)" golangci/golangci-lint:latest golangci-lint run

.PHONY: go-lint-all
## go-lint-all: runs linter for all packages
go-lint-all:
@ docker run --rm -v "`pwd`:/workspace:cached" -w "/workspace/." golangci/golangci-lint:latest golangci-lint run
go-lint-all:
docker run --rm -v "`pwd`:/workspace:cached" -w "/workspace/." golangci/golangci-lint:latest golangci-lint run

.PHONY: go-test
## go-test: run go tests
go-test:
@ go build ./...
@ go test -v -race ./...
go build ./...
go test -v -race ./...

.PHONY: sam-lint
## sam-lint: validate and lint cloudformation templates
sam-lint:
@ if [ -z "$(APP)" ]; then echo >&2 please set directory via variable APP; exit 2; fi
@ sam validate --lint --template apps/$(APP)/template.yaml
$(call check_var,APP)
sam validate --lint --template apps/$(APP)/template.yaml

SUBDIR = $(shell ls apps)
.PHONY: sam-lint
## sam-lint-all: validate and lint cloudformation templates
## sam-lint-all: validate and lint all cloudformation templates
sam-lint-all:
@ for dir in $(SUBDIR); do APP=$$dir $(MAKE) sam-lint || exit 1; done
for dir in $(SUBDIR); do
APP=$$dir $(MAKE) sam-lint || exit 1;
done

.PHONY: sam-build
## sam-build: build assets
sam-build:
@ if [ -z "$(APP)" ]; then echo >&2 please set directory via variable APP; exit 2; fi
@ if [ -z "$(AWS_REGION)" ]; then echo >&2 please set AWS_REGION explicitly; exit 2; fi
# build the lambda
# requires Go to be installed
# Ideally we'd use a provided container here (-u), but alas https://github.com/aws/aws-sam-cli/issues/5280
@ cd apps/$(APP) && sam build --region $(AWS_REGION)

.PHONY: sam-package
$(call check_var,APP)
$(call check_var,AWS_REGION)
cd apps/$(APP) && sam build --region $(AWS_REGION)

## sam-package: package cloudformation templates and push assets to S3
sam-package: sam-build
# requires AWS credentials.
# currently dynamically generates bucket. We will want to use a fixed set of buckets for our production artifacts.
$(call check_var,AWS_REGION)
sam package --template apps/$(APP)/.aws-sam/build/template.yaml --output-template-file apps/$(APP)/.aws-sam/build/packaged.yaml --region $(AWS_REGION) --debug --resolve-s3

.PHONY: sam-publish
## sam-publish: publish serverless repo app
sam-publish: sam-package
@ sam publish --template-file apps/$(APP)/.aws-sam/build/packaged.yaml --region $(AWS_REGION)
$(call check_var,AWS_REGION)
sam publish --template-file apps/$(APP)/.aws-sam/build/packaged.yaml --region $(AWS_REGION)

.PHONY: sam-package-all
## sam-package-all: package all cloudformation templates and push assets to S3
sam-package-all:
@ for dir in $(SUBDIR); do APP=$$dir $(MAKE) sam-package || exit 1; done

.PHONY: sam-publish-all
for dir in $(SUBDIR); do
APP=$$dir $(MAKE) sam-package || exit 1;
done

## sam-publish-all: publish all apps
sam-publish-all:
@ for dir in $(SUBDIR); do APP=$$dir $(MAKE) sam-publish || exit 1; done
for dir in $(SUBDIR); do
APP=$$dir $(MAKE) sam-publish || exit 1;
done

build-App:
@ if [ -z "$(APP)" ]; then echo >&2 please set APP explicitly; exit 2; fi
@ if [ -z "$(ARTIFACTS_DIR)" ]; then echo >&2 please set ARTIFACTS_DIR explicitly; exit 2; fi
$(call check_var,APP)
$(call check_var,ARTIFACTS_DIR)
GOARCH=arm64 GOOS=linux go build -tags lambda.norpc -o ./bootstrap cmd/$(APP)/main.go
cp ./bootstrap $(ARTIFACTS_DIR)/.

build-Forwarder:
APP=forwarder $(MAKE) build-App

.PHONY: help go-lint go-lint-all go-test sam-lint sam-lint-all sam-build sam-package sam-publish sam-package-all sam-publish-all build-App build-Forwarder
Loading