Skip to content

Commit

Permalink
Configure github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mgerasimchuk committed Oct 26, 2023
1 parent ea79828 commit 2174a45
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 237 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/lint-architecture.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Lint Architecture
on: push

jobs:
test-unit:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Lint Architecture
run: make lint-architecture
10 changes: 10 additions & 0 deletions .github/workflows/lint-golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Lint Go
on: push

jobs:
test-unit:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Lint Go
run: make lint-golangci
10 changes: 10 additions & 0 deletions .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Test Integration
on: push

jobs:
test-integration-api:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Test Integration
run: make test-integration-api
10 changes: 10 additions & 0 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Test Unit
on: push

jobs:
test-unit:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Test Unit
run: make test-unit
27 changes: 19 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
DOCKER_COMPOSE_FILENAME=deployments/docker-compose/docker-compose.yaml

start: vendor-install
docker-compose -f ${DOCKER_COMPOSE_FILENAME} down -v --remove-orphans ; docker-compose -f ${DOCKER_COMPOSE_FILENAME} up -d
start-from-scratch: vendor-install
docker-compose -f ${DOCKER_COMPOSE_FILENAME} down -v --remove-orphans ; docker-compose -f ${DOCKER_COMPOSE_FILENAME} up --build -d
docker-compose -f ${DOCKER_COMPOSE_FILENAME} up -d
start-from-scratch: stop
docker-compose --file ${DOCKER_COMPOSE_FILENAME} up --remove-orphans --renew-anon-volumes --force-recreate --build -d
stop:
docker-compose -f ${DOCKER_COMPOSE_FILENAME} down
restart: stop start
logs-api:
docker-compose -f ${DOCKER_COMPOSE_FILENAME} logs -f api
logs-verifier:
docker-compose -f ${DOCKER_COMPOSE_FILENAME} logs -f verifier
test:
docker run -v $(shell pwd):/app golang:1.20.0 /bin/bash -c 'cd /app && GO111MODULE=on go test -mod vendor -covermode=count -coverprofile=assets/coverage/coverage.out -v ./... && go tool cover -html=assets/coverage/coverage.out -o=assets/coverage/coverage.html'
test-integration-api:
docker-compose -f ${DOCKER_COMPOSE_FILENAME} run test-integration-api
test-unit: vendor-install
docker run -v $(shell pwd):/app -w /app golang:1.20.0 /bin/bash \
-c 'go test -covermode=count -coverprofile=assets/coverage/coverage.out -v ./internal/... && go tool cover -html=assets/coverage/coverage.out -o=assets/coverage/coverage.html'
test-integration-api: start
if ! docker-compose -f ${DOCKER_COMPOSE_FILENAME} run test-integration-api; then \
echo "\nLogs for api from docker-compose:" ;\
docker-compose -f ${DOCKER_COMPOSE_FILENAME} logs api; \
echo "\nServices status:" ;\
docker-compose -f ${DOCKER_COMPOSE_FILENAME} ps ;\
exit 255 ;\
fi
lint-golangci: vendor-install
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.55.1 \
golangci-lint run --timeout 5m30s -v
lint-architecture:
docker run --rm -v $(shell pwd):/app -w /app golang:1.20.0 /bin/bash -c "go install github.com/fdaines/[email protected] && arch-go -v"
docker run --rm -v $(shell pwd):/app -w /app golang:1.20.0 /bin/bash \
-c "go install github.com/fdaines/[email protected] && arch-go -v"
vendor-install:
@if [ -d "vendor" ]; then echo "Vendor folder already exists. Skip vendor installing."; else docker run --rm -v $(shell pwd):/app -w /app golang:1.20.0 /bin/bash -c "go mod tidy && go mod vendor"; fi
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[![Lint Golangci][lint-golangci-badge]][lint-golangci-url]
[![Lint Architecture][lint-architecture-badge]][lint-architecture-url]
[![Test Unit][test-unit-badge]][test-unit-url]
[![Test Integration][test-integration-badge]][test-integration-url]

# Space Trouble

## Requirements
Expand Down Expand Up @@ -52,15 +57,37 @@ docker-compose -f deployments/docker-compose/docker-compose.yaml run migrations-

## Tests

### Unit

Run tests with generating html coverage report:

```
make test
make test-unit
```

After executing, you can open generated [assets/coverage/coverage.html](https://htmlpreview.github.io/?https://raw.githubusercontent.com/mgerasimchuk/space-trouble/master/assets/coverage/coverage.html)
file in browser for checking coverage

### Integration

```
make test-integration
```

## Linters

### Golangci

```
make lint-golangci
```

### Architecture

```
make lint-architecture
```

## Configuration

See env file: [deployments/docker-compose/.env](deployments/docker-compose/.env)
Expand Down Expand Up @@ -117,3 +144,12 @@ Technical requirements:
* Please, use github or bitbucket.

* Commit your changes often. Do not push the whole project in one commit.

[lint-golangci-badge]: https://github.com/mgerasimchuk/space-trouble/actions/workflows/lint-golangci.yml/badge.svg
[lint-golangci-url]: https://github.com/mgerasimchuk/space-trouble/actions/workflows/lint-golangci.yml
[lint-architecture-badge]: https://github.com/mgerasimchuk/space-trouble/actions/workflows/lint-architecture.yml/badge.svg
[lint-architecture-url]: https://github.com/mgerasimchuk/space-trouble/actions/workflows/lint-architecture.yml
[test-unit-badge]: https://github.com/mgerasimchuk/space-trouble/actions/workflows/test-unit.yml/badge.svg
[test-unit-url]: https://github.com/mgerasimchuk/space-trouble/actions/workflows/test-unit.yml
[test-integration-badge]: https://github.com/mgerasimchuk/space-trouble/actions/workflows/test-integration.yml/badge.svg
[test-integration-url]: https://github.com/mgerasimchuk/space-trouble/actions/workflows/test-integration.yml
2 changes: 1 addition & 1 deletion cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func main() {
logger.Infof("Application has been started")

// Wait for interrupting signal to gracefully shutdown the server with a 5 seconds timeout
quit := make(chan os.Signal)
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
logger.Info("Shutting down server...")
Expand Down
183 changes: 0 additions & 183 deletions cmd/development/main.go

This file was deleted.

7 changes: 5 additions & 2 deletions cmd/verifier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ func main() {
wg.Add(1)
go func() {
defer wg.Done()
bookingUsecase.VerifyFirstAvailableBooking()
err = bookingUsecase.VerifyFirstAvailableBooking()
if err != nil {
logger.Error(err)
}
}()
}
wg.Wait()
Expand All @@ -78,7 +81,7 @@ func main() {
logger.Infof("Application has been started")

// Wait for interrupting signal to gracefully shutdown the server with a 5 seconds timeout
quit := make(chan os.Signal)
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit

Expand Down
Loading

0 comments on commit 2174a45

Please sign in to comment.