Skip to content

Commit

Permalink
Merge pull request #5 from observeinc/chore/Makefile
Browse files Browse the repository at this point in the history
chore: ran the Makefile through a linter
  • Loading branch information
obs-gh-colinhutchinson authored Oct 5, 2023
2 parents 907c834 + f8a1da7 commit a294975
Showing 1 changed file with 44 additions and 40 deletions.
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

0 comments on commit a294975

Please sign in to comment.