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 79bdad7
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 40 deletions.
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.50.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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![Test Unit][test-unit-badge]][test-unit-url]
[![Test Integration][test-integration-badge]][test-integration-url]

# Space Trouble

## Requirements
Expand Down Expand Up @@ -117,3 +120,8 @@ Technical requirements:
* Please, use github or bitbucket.

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

[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
47 changes: 20 additions & 27 deletions deployments/docker-compose/.env
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
# see: vendor/github.com/sirupsen/logrus/logrus.go
# 0 - PanicLevel
# 1 - FatalLevel
# 2 - ErrorLevel
# 3 - WarnLevel
# 4 - InfoLevel
# 5 - DebugLevel
# 6 - TraceLevel
LOG_LEVEL: 4


DB_HOST: db
DB_PORT: 5432
DB_NAME: postgres
DB_USER: postgres
DB_PASSWORD: postgres

LAUNCHPAD_API_BASE_URI: "https://api.spacexdata.com"

LANDPAD_API_BASE_URI: "https://api.spacexdata.com"

HTTPSERVER:
HTTP_SERVER_PORT: 8080
# see: vendor/github.com/gin-gonic/gin/mode.go
# 0 - PanicLevel
# 1 - FatalLevel
# 2 - ErrorLevel
# 3 - WarnLevel
# 4 - InfoLevel
# 5 - DebugLevel
# 6 - TraceLevel
LOG_LEVEL=4
DB_HOST=db
DB_PORT=5432
DB_NAME=postgres
DB_USER=postgres
DB_PASSWORD=postgres
LAUNCHPAD_API_BASE_URI="https://api.spacexdata.com"
LANDPAD_API_BASE_URI="https://api.spacexdata.com"
HTTP_SERVER_PORT=8080
# see=vendor/github.com/gin-gonic/gin/mode.go
# debug
# release
# test
HTTP_SERVER_MODE: release

VERIFIER_WORKERS_COUNT: 10
VERIFIER_RUN_WORKERS_EVERY_MILLISECONDS: 500
HTTP_SERVER_MODE=release
VERIFIER_WORKERS_COUNT=10
VERIFIER_RUN_WORKERS_EVERY_MILLISECONDS=500
17 changes: 12 additions & 5 deletions deployments/docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ services:
api:
image: golang:1.20.0
restart: "no"
env_file:
- ./../../deployments/docker-compose/.env
depends_on:
- "db"
env_file:
- ./../../deployments/docker-compose/.env
working_dir: /app
volumes:
- ./../../:/app
ports:
Expand All @@ -16,10 +17,11 @@ services:
verifier:
image: golang:1.20.0
restart: "no"
env_file:
- ./../../deployments/docker-compose/.env
depends_on:
- "db"
env_file:
- ./../../deployments/docker-compose/.env
working_dir: /app
volumes:
- ./../../:/app
entrypoint: bash -c 'while !</dev/tcp/db/5432; do sleep 1; done; go run /app/cmd/verifier/main.go'
Expand Down Expand Up @@ -84,4 +86,9 @@ services:
SERVER_URL: "http://api:8080"
volumes:
- ./../../:/app
entrypoint: "/bin/bash -c 'go test -count=1 -v ./test/integration/api'"
entrypoint: |
/bin/bash -c 'until $$(curl --output /dev/null --silent --fail $$SERVER_URL/v1/bookings); do \
((att++)) && ((att==50)) && echo "waiting timeout" && exit 255;\
printf '.'; sleep 1;\
done &&\
go test -count=1 -v ./test/integration/api'

0 comments on commit 79bdad7

Please sign in to comment.