diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..1a7bb19 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,33 @@ +name: coverage report upload + +on: + push: + branches: + - restart + pull_request: + branchs: + - 'feature/**' + - 'hotfix/**' + - 'release/**' + +jobs: + coverage: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: '12' + + - name: Install dependencies + run: npm install + + - name: Up firebase + run: make up.firebase + + - name: Make coverage + run: npm run coverage + + - uses: codecov/codecov-action@v1 + with: + file: coverage/coverage-final.json diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..ef90365 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,44 @@ +name: tests + +on: + push: + branches: + - master + - dev + pull_request: + branchs: + - 'feature/**' + - 'hotfix/**' + - 'release/**' + +jobs: + style: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: '12' + + - name: Install dependencies + run: npm install + + - name: check style + run: npm run style:check + + test: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: '12' + + - name: Install dependencies + run: npm install + + - name: Up firebase + run: make up.firebase + + - name: Test + run: npm run test diff --git a/Makefile b/Makefile index 9965f6b..db42978 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,32 @@ -all: - make up build: - docker-compose --build -up: - docker-compose up --detach --force-recreate --renew-anon-volumes --remove-orphans \ No newline at end of file + docker-compose build + +up: + make up $(args) + +up.detach: + docker-compose up --detach --force-recreate --renew-anon-volumes --remove-orphans $(args) + +up.firebase: + docker-compose up --detach idvogados_firebase + +down: + docker-compose down $(args) + +down.volumes: + docker-compose down --volumes + +bash: + docker-compose run idvogados_api bash + +cli: + docker-compose run idvogados_api npm run cli + +tests: + docker-compose run idvogados_api npm run test + +coverage: + docker-compose run idvogados_api npm run coverage + +style.check: + docker-compose run idvogados_api npm run style:check diff --git a/docker-compose.yml b/docker-compose.yml index 1ba8160..b2aa2b7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,8 @@ version: '3.6' +volumes: + node_modules_volume: {} + services: idvogados_api: container_name: idvogados_api @@ -11,6 +14,9 @@ services: API_PORT: 3001 ports: - 3001:3001 + volumes: + - .:/var/app + - node_modules_volume:/var/app/node_modules/ depends_on: - idvogados_firebase diff --git a/docs/orientacoes.md b/docs/orientacoes.md index 4ee1ccb..f55a820 100644 --- a/docs/orientacoes.md +++ b/docs/orientacoes.md @@ -123,7 +123,16 @@ O projeto conta com vários scripts que irão auxiliar no desenvolvimento e pode ### Comandos Make - `make build`: Faz build das imagens docker -- `make up`: Inicializa a api localmente com docker, utilizando as configurações do arquivo [`docker-compose.yml`](https://github.com/idvogados/backend/blob/dev/docker-compose.yml) +- `make up`: Inicializa todos os serviços (é possível passar arugmentos extras utilizando `make up args='arg extra'`) +- `make up.detach`: Inicializa todos os serviços no modo detached e com outros parâmetros (é possível passar arugmentos extras utilizando `make up.detach args='arg extra'`) +- `make up.firebase`: Inicializa apenas o serviço do Firebase +- `make down`: Mata todos os serviços (é possível passar arugmentos extras utilizando `make down args='arg extra'`) +- `make down.volumes`: Mata todos os serviços e remove os volumes nomeados +- `make bash`: Inicia um bash/shell script no container do serviço Node +- `make cli`: Acessa a API em modo terminal na pasta raiz do projeto +- `make tests`: Executa todos os testes (Pasta `test/*`) +- `make coverage`: Executa os testes e gera o arquivo de coverage +- `make style.check`: Verifica se o código fonte segue os padrões de estilo definidos nos arquivos `.eslintrc` e `.prettierrc` ## Configurações do projeto diff --git a/package.json b/package.json index 6400346..61e6163 100644 --- a/package.json +++ b/package.json @@ -33,19 +33,20 @@ }, "scripts": { "deps": "docker-compose -f docker-compose.test.yml up --force-recreate --renew-anon-volumes --remove-orphans", - "eslint": "./node_modules/.bin/eslint --fix .", - "eslint:check": "./node_modules/.bin/eslint .", + "eslint": "eslint --fix .", + "eslint:check": "eslint .", "style:fix": "npm run prettier && npm run eslint", "style:check": "npm run prettier:check && npm run eslint:check", - "prettier": "./node_modules/.bin/prettier --write \"**/{*.js,*.json,bin/**}\"", - "prettier:check": "./node_modules/.bin/prettier --check \"**/{*.js,*.json,bin/**}\"", + "prettier": "prettier --write \"**/{*.js,*.json,bin/**}\"", + "prettier:check": "prettier --check \"**/{*.js,*.json,bin/**}\"", "start": "node ./bin/www", "start:docker": "docker-compose up --force-recreate --renew-anon-volumes --remove-orphans", "debug": "node --inspect-brk ./bin/www", "cli": "node --experimental-repl-await", - "test": "./node_modules/.bin/nyc mocha --reporter spec", + "test": "nyc mocha --reporter spec", "test:acceptance": "npm t test/acceptance/*", - "test:unit": "npm t test/unit/*" + "test:unit": "npm t test/unit/*", + "coverage": "nyc --reporter=json mocha --reporter spec" }, "repository": { "type": "git",