Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Westman <[email protected]>
Co-authored-by: Arundhati Rao <[email protected]>
Co-authored-by: Mitch Cimenski <[email protected]>
Co-authored-by: Nathaniel Cook <[email protected]>
  • Loading branch information
5 people committed Jun 3, 2019
0 parents commit 8dce0c6
Show file tree
Hide file tree
Showing 1,036 changed files with 127,111 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
*.log
/setup.cfg
/setup.pid
/config.json.bak

# Created by .ignore support plugin (hsz.mobi)
### Go template
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
*.out
*.pid
.env
.ready
/run.sh
/config.json*

# Folders
_obj
_test
temp
bin

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof

# IDE
.idea
*.iml
*.ipr
.vscode
debug

# glide
vendor
vendor.orig

# MacOS
.DS_Store

ngrok.log

smoketest_db_dump
74 changes: 74 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at
[[email protected]](mailto:[email protected]). All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org
39 changes: 39 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Contributing to GoAlert

We welcome feature requests, bug reports and contributions for code and documentation.

## Reporting Issues

Reporting bugs can be done in the GitHub [issue tracker](https://github.com/target/goalert/issues). Please search for a possible pre-existing issue first to help prevent duplicates.

Please include the version (`goalert version`) with new bug reports.

## Code Contribution

GoAlert is already used in production environments, so any new changes/features/functionality must (where possible):

- Not alter existing behavior without an explicit config change
- Co-exist with older versions without disruption
- Must have a safe way to disable/roll-back

It should always be safe to roll out a new version of GoAlert into an existing environment/deployment without downtime.

As an example, things like DB changes/migrations should preserve behavior across revisions.

## Pull Requests

Patches are welcome, but we ask that any significant change start as an [issue](https://github.com/target/goalert/issues/new) in the tracker, prefereably before work is started.

Be sure to run `make check` before opening a PR to catch common errors.

### UI Change Guidelines

- Complex logic should be broken out with corresponding unit tests (we use [Jest](https://jestjs.io/docs/en/using-matchers)) into the same directory. For example: [util.js](./web/src/app/rotations/util.js) and [util.test.js](./web/src/app/rotations/util.test.js).
- New functionality should have an integration test (we use [Cypress](https://docs.cypress.io/guides/getting-started/writing-your-first-test.html#Write-a-simple-test) for these) testing the happy-path at a minimum. Examples [here](./web/src/cypress/integration/sidebar.ts), and [more information here](./web/src/cypress/README.md).
- React components should follow React idioms, using common prop names, and having prop-types defined.

### Backend Change Guidelines

- Use unit tests as a tool to validate complex logic
- New functionality should have a behavioral smoketest at a minimum. For [example](./smoketest/simplenotification_test.go). Documentation on our smoketest framework can be found [here](./smoketest/README.md).
- New Go code should pass `golint`, exported functions/methods should be commented, etc..
21 changes: 21 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This is the official list of people who have contributed code to
# the GoAlert repository.
#
# Names should be added to this file like so:
# Individual's name <submission email address>
# Individual's name <submission email address> <email2> <emailN>
#
# Please keep the list sorted.

Adam Westman <[email protected]>
Andrew Deck <[email protected]>
Andrew From <[email protected]>
Arundhati Rao <[email protected]>
Dan Maas <[email protected]>
Jared Anson <[email protected]>
Kevin Marquardsen <[email protected]>
Michael Black <[email protected]>
Mitch Cimenski <[email protected]>
Nathaniel Caza <[email protected]>
Nathaniel Cook <[email protected]>
Nicholas Cappo <[email protected]>
13 changes: 13 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (c) 2019 Target Brands, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
170 changes: 170 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
.PHONY: stop start build-docker lint tools regendb resetdb
.PHONY: smoketest generate check all test test-long install install-race
.PHONY: cy-wide cy-mobile cy-wide-prod cy-mobile-prod cypress postgres
.PHONY: config.json.bak jest new-migration
.SUFFIXES:

GOFILES = $(shell find . -path ./web/src -prune -o -path ./vendor -prune -o -path ./.git -prune -o -type f -name "*.go" -print | grep -v web/inline_data_gen.go) go.sum
INLINER = devtools/inliner/*.go
CFGPARAMS = devtools/configparams/*.go
DB_URL = postgres://goalert@localhost:5432/goalert?sslmode=disable

LOG_DIR=
GOPATH=$(shell go env GOPATH)
BIN_DIR=bin

GIT_VERSION=$(shell git describe --tags --dirty --match 'v*' || echo 'dev')
GIT_COMMIT=$(shell git rev-parse HEAD || echo '?')
GIT_TREE=$(shell git diff-index --quiet HEAD -- && echo clean || echo dirty)
BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")

LD_FLAGS+=-X github.com/target/goalert/app.gitCommit=$(GIT_COMMIT)
LD_FLAGS+=-X github.com/target/goalert/app.gitVersion=$(GIT_VERSION)
LD_FLAGS+=-X github.com/target/goalert/app.gitTreeState=$(GIT_TREE)
LD_FLAGS+=-X github.com/target/goalert/app.buildDate=$(BUILD_DATE)


ifdef LOG_DIR
RUNJSON_ARGS += -logs=$(LOG_DIR)
endif

export CGO_ENABLED = 0
export PATH := $(PWD)/bin:$(PATH)
export GOOS = $(shell go env GOOS)

ifdef BUNDLE
GOFILES += web/inline_data_gen.go
endif

all: test install

$(BIN_DIR)/runjson: go.sum devtools/runjson/*.go
go build -o $@ ./devtools/$(@F)
$(BIN_DIR)/waitfor: go.sum devtools/waitfor/*.go
go build -o $@ ./devtools/$(@F)
$(BIN_DIR)/simpleproxy: go.sum devtools/simpleproxy/*.go
go build -o $@ ./devtools/$(@F)
$(BIN_DIR)/mockslack: go.sum $(shell find ./devtools/mockslack -name '*.go')
go build -o $@ ./devtools/mockslack/cmd/mockslack
$(BIN_DIR)/goalert: go.sum $(GOFILES) graphql2/mapconfig.go
go build -tags "$(BUILD_TAGS)" -ldflags "$(LD_FLAGS)" -o $@ ./cmd/goalert

install: $(GOFILES)
go install -tags "$(BUILD_TAGS)" -ldflags "$(LD_FLAGS)" ./cmd/goalert

cypress: bin/runjson bin/waitfor bin/simpleproxy bin/mockslack bin/goalert web/src/node_modules
web/src/node_modules/.bin/cypress install

cy-wide: cypress web/src/build/vendorPackages.dll.js
CYPRESS_viewportWidth=1440 CYPRESS_viewportHeight=900 bin/runjson $(RUNJSON_ARGS) <devtools/runjson/localdev-cypress.json
cy-mobile: cypress web/src/build/vendorPackages.dll.js
CYPRESS_viewportWidth=375 CYPRESS_viewportHeight=667 bin/runjson $(RUNJSON_ARGS) <devtools/runjson/localdev-cypress.json
cy-wide-prod: web/inline_data_gen.go cypress
CYPRESS_viewportWidth=1440 CYPRESS_viewportHeight=900 bin/runjson $(RUNJSON_ARGS) <devtools/runjson/localdev-cypress-prod.json
cy-mobile-prod: web/inline_data_gen.go cypress
CYPRESS_viewportWidth=375 CYPRESS_viewportHeight=667 bin/runjson $(RUNJSON_ARGS) <devtools/runjson/localdev-cypress-prod.json

start: bin/waitfor web/src/node_modules web/src/build/vendorPackages.dll.js bin/runjson
# force rebuild to ensure build-flags are set
touch cmd/goalert/main.go
make bin/goalert BUILD_TAGS+=sql_highlight
bin/runjson <devtools/runjson/localdev.json

jest: web/src/node_modules
cd web/src && node_modules/.bin/jest $(JEST_ARGS)

test: web/src/node_modules jest
go test -short ./...

check: generate web/src/node_modules
# go run devtools/ordermigrations/main.go -check
go vet ./...
go run github.com/gordonklaus/ineffassign .
CGO_ENABLED=0 go run honnef.co/go/tools/cmd/staticcheck ./...
(cd web/src && yarn fmt)
./devtools/ci/tasks/scripts/codecheck.sh


migrate/inline_data_gen.go: migrate/migrations migrate/migrations/*.sql $(INLINER)
go generate ./migrate

graphql2/mapconfig.go: $(CFGPARAMS) config/config.go
(cd ./graphql2 && go run ../devtools/configparams/main.go -out mapconfig.go && goimports -w ./mapconfig.go) || go generate ./graphql2

graphql2/generated.go: graphql2/schema.graphql graphql2/gqlgen.yml
go generate ./graphql2

generate:
go generate ./...

smoketest: generate bin/goalert
(cd smoketest && go test -timeout 20m)

test-migrations: migrate/inline_data_gen.go bin/goalert
(cd smoketest && go test -run TestMigrations)

tools:
go get -u golang.org/x/tools/cmd/gorename
go get -u golang.org/x/tools/cmd/present
go get -u golang.org/x/tools/cmd/bundle
go get -u golang.org/x/tools/cmd/gomvpkg
go get -u github.com/golang/lint/golint
go get -u golang.org/x/tools/cmd/goimports
go get -u github.com/gordonklaus/ineffassign
go get -u honnef.co/go/tools/cmd/staticcheck
go get -u golang.org/x/tools/cmd/stringer

web/src/yarn.lock: web/src/package.json
(cd web/src && yarn --no-progress --silent && touch yarn.lock)

web/src/node_modules: web/src/node_modules/.bin/cypress
touch web/src/node_modules

web/src/node_modules/.bin/cypress: web/src/yarn.lock
(cd web/src && yarn --no-progress --silent --frozen-lockfile && touch node_modules/.bin/cypress)

web/src/build/index.html: web/src/webpack.prod.config.js web/src/node_modules $(shell find ./web/src/app -type f )
(cd web/src && node_modules/.bin/webpack --config webpack.prod.config.js)
echo "" >>web/src/build/index.html
echo "<!-- Version: $(GIT_VERSION) -->" >>web/src/build/index.html
echo "<!-- GitCommit: $(GIT_COMMIT) ($(GIT_TREE)) -->" >>web/src/build/index.html
echo "<!-- BuildDate: $(BUILD_DATE) -->" >>web/src/build/index.html

web/inline_data_gen.go: web/src/build/index.html $(CFGPARAMS) $(INLINER)
go generate ./web

web/src/build/vendorPackages.dll.js: web/src/node_modules web/src/webpack.dll.config.js
(cd web/src && node_modules/.bin/webpack --config ./webpack.dll.config.js --progress)

config.json.bak: bin/goalert
(bin/goalert get-config "--db-url=$(DB_URL)" 2>/dev/null >config.json.new || echo '{"Auth":{"RefererURLs":["http://localhost:3030", "http://[::]:3030", "http://127.0.0.1:3030"]}}' >config.json.new) && mv config.json.new config.json.bak

postgres:
docker run -d \
--restart=always \
-e POSTGRES_USER=goalert \
--name goalert-postgres \
-p 5432:5432 \
postgres:11-alpine

regendb: bin/goalert migrate/inline_data_gen.go config.json.bak
go run ./devtools/resetdb --with-rand-data
test -f config.json.bak && bin/goalert set-config --allow-empty-data-encryption-key "--db-url=$(DB_URL)" <config.json.bak || true
bin/goalert add-user --admin --email [email protected] --user admin --pass admin123 "--db-url=$(DB_URL)"

resetdb: migrate/inline_data_gen.go config.json.bak
go run ./devtools/resetdb --no-migrate

clean:
git clean -xdf ./web ./bin ./vendor ./smoketest

build-docker: bin/goalert bin/mockslack

lint: $(GOFILES)
go run github.com/golang/lint/golint $(shell go list ./...)

new-migration:
@test "$(NAME)" != "" || (echo "NAME is required" && false)
@test ! -f migrate/migrations/*-$(NAME).sql || (echo "Migration already exists with the name $(NAME)." && false)
@echo "-- +migrate up\n\n\n-- +migrate Down\n" >migrate/migrations/$(shell date +%Y%m%d%H%M%S)-$(NAME).sql
@echo "Created: migrate/migrations/$(shell date +%Y%m%d%H%M%S)-$(NAME).sql"
Loading

0 comments on commit 8dce0c6

Please sign in to comment.