Unverified Commit 2c1cc583 authored by Ivan Gabriele's avatar Ivan Gabriele Committed by GitHub
Browse files

ci: optimize test and build operations (#952)

parent 5eee0082
__tests__/
.next/
__tests__/
coverage/
node_modules/
tests/
.env
*.md
/db/seeds
/features
.env
jest.config.js
LICENSE
__tests__/
.next/
coverage/
node_modules/
tests/
# /src/libs/generatePassword.js
{
"root": true,
"extends": ["@socialgouv/eslint-config-strict", "prettier"],
"plugins": ["sort-requires", "prettier"],
"env": {
"browser": false,
"node": true
},
"rules": {
"no-console": ["error", { "allow": ["info", "error", "warn"] }],
"prettier/prettier": "error",
"sort-requires/sort-requires": "error"
},
"overrides": [
{
"files": ["packages/app/pages/**/*.js", "packages/app/src/**/*.js"],
"extends": ["@socialgouv/eslint-config-react-strict", "prettier"],
"env": {
"browser": true,
"node": true
},
"rules": {
"jest/no-disabled-tests": "off",
"react/jsx-sort-props": "error",
"react/prop-types": "off"
}
},
{
"files": ["packages/app/src/templates/**/*.js"],
"extends": ["@socialgouv/eslint-config-react-strict", "prettier"],
"env": {
"browser": true,
"node": true
},
"rules": {
"jest/no-disabled-tests": "off",
"react/jsx-sort-props": "error",
"react/prop-types": "error"
}
},
{
"files": ["jest.setup.js", "*.test.js"],
"env": {
"jest": true
}
},
{
"files": ["features/**/*.js"],
"extends": ["plugin:chai-expect/recommended"],
"plugins": ["chai-expect"],
"env": {
"browser": true,
"node": true
},
"rules": {
"jest/no-standalone-expect": "off",
"jest/valid-expect": "off"
}
},
{
"files": ["packages/app/src/**/*.test.js"],
"env": {
"jest": true
},
"globals": {
"testRender": false,
"waitFor": false
}
}
]
}
# https://github.com/JasonEtco/todo#configuring-for-your-project
todo:
autoAssign: "ivangabriele"
caseSensitive: true
label: ":label: todo"
......@@ -127,10 +127,10 @@ Temporary Items
# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# !.vscode/settings.json
# !.vscode/tasks.json
# !.vscode/launch.json
# !.vscode/extensions.json
### VisualStudioCode Patch ###
# Ignore all local history of files
......
......@@ -14,11 +14,10 @@ jobs:
- stage: Test
name: Unit Tests
install:
- yarn --frozen-lockfile
- yarn --frozen-lockfile --ignore-scripts
script:
- yarn test
after_script:
# Push tests coverage data to Codecov:
after_success:
- npx codecov
- stage: Test
......@@ -27,15 +26,15 @@ jobs:
- NODE_ENV=production
services:
- docker
install:
- yarn --frozen-lockfile --production=false --pure-lockfile
before_script:
# Copy default environment variables:
- cp ./.env.example ./.env
- yarn setup:env
# Stop Travis out-of-the-box PostgreSQL services:
- sudo service postgresql stop
# Give execution rights to production script (used by "ci:test:e2e"):
- sudo chmod +x ./scripts/prod/start.sh
# Run production script:
- ./scripts/prod/start.sh
- yarn start:prod
script:
- yarn test:e2e
......
{
"recommendations": [
"alexkrechik.cucumberautocomplete",
"dbaeumer.vscode-eslint",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"jpoissonnier.vscode-styled-components",
"mikestead.dotenv",
"ms-azuretools.vscode-docker"
]
}
{
"coverage-gutters.coverageReportFileName": "packages/contrib/coverage/**/index.html",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.rulers": [100],
"eslint.workingDirectories": [
{
"directory": "./packages/api",
"changeProcessCWD": true
},
{
"directory": "./packages/app",
"changeProcessCWD": true
}
],
"eslint.enable": true
}
# Contributing
We would love for you to contribute to the backoffice of [Code du travail numérique][link-cdtn] and
help make it even better than it is today! As a contributor, here are the guidelines we would like
you to follow:
help make it even better than it is today!
- [Contribute](#contribute)
- [Prerequisites](#prerequisites)
- [Get Started](#get-started)
- [Test](#test)
- [Recommended IDE Settings](#recommended-ide-settings)
- [VS Code](#vs-code)
- [Known Issues](#known-issues)
- [Docker Compose](#docker-compose)
- [Jest Watch](#jest-watch)
- [Naming Guidelines](#naming-guidelines)
- [API-related Actions](#api-related-actions)
- [React Component Actions](#react-component-actions)
- [Commit Message Guidelines](#commit-message-guidelines)
- [Revert](#revert)
- [Type](#type)
- [Scope](#scope)
- [Subject](#subject)
## Contribute
### Prerequisites
- Docker v19+
- Docker Compose v1.25+
- Node v12+
- Yarn v1.22+
You must be able to run `docker` and `docker-compose` [without `sudo`][link-docker-no-sudo].
### Get Started
```bash
git clone https://github.com/SocialGouv/code-du-travail-backoffice.git
cd code-du-travail-backoffice
yarn
yarn setup
yarn dev
```
The website should now be available at: http://localhost:3100.
5 sample users have been generated during setup:
- Administrator:
- Email: `doris@sea.com`<br>
Mot de passe: `Azerty123`
- Regional Administrator:
- Email: `deb@sea.com`<br>
Mot de passe: `Azerty123`
- Contributors:
- Email: `nemo@sea.com`<br>
Mot de passe: `Azerty123`
- Email: `astrid@sea.com`<br>
Mot de passe: `Azerty123`
- Email: `marin@sea.com`<br>
Mot de passe: `Azerty123`
### Test
- All Tests: `yarn test`
- Lint Tests: `yarn test:lint`
- Type Tests: `yarn test:type`
- Unit Tests: `yarn test:unit`
- Unit Tests (watch): `yarn test:watch`
- E2E Tests: `yarn test:e2e`
### Recommended IDE Settings
### VS Code
`settings.json`
```json
{
"coverage-gutters.coverageReportFileName": "packages/contrib/coverage/**/index.html",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.rulers": [100],
"eslint.enable": true
}
```
`extensions.json`
```json
{
"recommendations": [
"alexkrechik.cucumberautocomplete",
"dbaeumer.vscode-eslint",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"jpoissonnier.vscode-styled-components",
"mikestead.dotenv",
"ms-azuretools.vscode-docker",
"ryanluker.vscode-coverage-gutters"
]
}
```
### Known Issues
#### Docker Compose
Under Ubuntu, if you encounter the error `double free or corruption (out)`, the [current
solution][link-issue-1] is to force-remove the related dependency:
```bash
dpkg -r --force-depends golang-docker-credential-helpers
```
- [Contributing](#contributing)
- [Code Naming Guidelines](#code-naming-guidelines)
- [API-related Actions](#api-related-actions)
- [React Component Actions](#react-component-actions)
- [Commit Message Guidelines](#commit-message-guidelines)
- [Revert](#revert)
- [Type](#type)
- [Scope](#scope)
- [Subject](#subject)
#### Jest Watch
## Code Naming Guidelines
Under Ubuntu, if you encounter the error
`Error: ENOSPC: System limit for number of file watchers reached`, the [current
solution][link-issue-2] is to increase the number of file system watchers:
```bash
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
```
---
## Naming Guidelines
### API-related Actions
This includes react components methods as well as redux actions, action types and sagas:
This includes React components methods as well as Redux actions, action types and sagas:
- Any `GET` call-related method should start with the verb **load**.
- Any `POST` call-related method should start with the verb **create**.
- Any `POST` call-related method should start with the verb **create**, or **add** if it targets a
foreign entity (i.e.: `addAnswerComment()`).
- Any `PATCH` call-related method should start with the verb **update**.
- Any `DELETE` call-related method should start with the verb **delete** (or **\_delete**).
- Any `DELETE` call-related method should start with the verb **delete** (or **\_delete**), or
**remove** if it targets a foreign entity (i.e.: `removeAnswerComment()`).
### React Component Actions
- Any method generating components should start with the verb **render**.
- Any method returning a JSX value should start with the verb **render**.
---
## Commit Message Guidelines
......@@ -46,7 +162,7 @@ to read on GitHub as well as in various git tools.
- `docs(changelog): update changelog to 1.12.5`
- `fix(release): need to depend on latest rxjs and zone.js`
- `ci: configure dependabot`
- `ci(codecov): configure dependabot`
Do not hesitate check [existing commits][link-cdtb-commits] to get a better understanding.
......@@ -79,19 +195,7 @@ changelog generated from commit messages.
The following is the list of supported scopes:
- **api**
- **db**
- **admin**
- **contrib**
There are currently a few exceptions to the "use package name" rule:
- **packaging**: Used for changes that change the npm package layout in all of our packages, e.g.
public path changes, package.json changes done to all packages, d.ts file/format changes, changes
to bundles, etc.
- **changelog**: Used for updating the release notes in CHANGELOG.md
- none/empty string: useful for `style`, `test` and `refactor` changes that are done across all
packages (e.g. `style: add missing semicolons`) and for docs changes that are not related to a
specific package (e.g. `docs: fix typo in tutorial`).
- **app**
### Subject
......@@ -104,4 +208,7 @@ The subject contains a succinct description of the change:
---
[link-cdtb-commits]: https://github.com/SocialGouv/code-du-travail-backoffice/commits/master
[link-cdtn]: https://codedutravail.num.social.gouv.fr
[link-cdtn]: https://code.travail.gouv.fr
[link-docker-no-sudo]: https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user
[link-issue-1]: https://github.com/docker/docker-credential-helpers/issues/103#issuecomment-421822269
[link-issue-2]: https://github.com/facebook/jest/issues/3254#issuecomment-297214395
# Master Container for db migrations
# Master Image
FROM igabriele/knex-pg:12.0.7.0
......
# Back-office du code du travail numérique
# CDTN Back-office
[![Travis CI Status][img-travis]][link-travis]
[![Coveralls Code Coverage][img-codecov]][link-codecov]
Ce dépôt regroupe les applications d'administration des données du [code du travail
numérique][link-cdtn].
Data administration portal for the official [Code du travail numérique][link-cdtn] (French Labor
Code and Agreements).
---
## Contribuer au projet
### Pré-requis
- Docker v19+
- Docker Compose v1.24+
- Node v12+
- Yarn v1.21+
### Installation
```bash
git clone https://github.com/SocialGouv/code-du-travail-backoffice.git
cd code-du-travail-backoffice
yarn
# Build, migrate and seed the database (PostgreSQL), as well as the api (PostgREST):
yarn setup
# Start the containers and run packages code in dev mode (with watch & hot reload):
yarn dev
```
> 📓 Si vous ne pouvez exécuter `docker-compose` qu'avec `sudo`, vous devez remplacer tous les
> `docker-compose` par `sudo docker-compose`.
Le site devrait être accessible à l'adresse http://localhost:3100.
3 utilisatrices ont été générées par défaut pendant l'installation :
- Administratrice:
- Email: `doris@sea.com`
- Mot de passe: `Azerty123`
- Administratrice régionale:
- Email: `deb@sea.com`
- Mot de passe: `Azerty123`
- Contributeur:
- Email: `nemo@sea.com`
- Mot de passe: `Azerty123`
**Recommended VS Code settings**
```json
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.formatOnSaveTimeout": 2000,
"eslint.nodePath": "./packages/contrib/node_modules",
"eslint.workingDirectories": [
{
"directory": "./packages/api",
"changeProcessCWD": true
},
{
"directory": "./packages/app",
"changeProcessCWD": true
}
]
}
```
### Démarrer le site localement
Un fois installé, vous pouvez simplement faire tourner le site en exécutant cette commande :
```bash
yarn dev
```
Le site devrait être accessible à l'adresse [http://localhost:3100](http://localhost:3100).
### Tester le code
#### Test unitaires
Durant le développement, vous pouvez soit tester manuellement :
```bash
yarn test:unit
```
soit faire tourner les tests unitaires en continu :
```bash
yarn test:watch
```
#### Analyse statique
Vous pouvez exécuter l'analyse statique du code en exécutant :
```bash
yarn test:lint
```
#### Tests de bout en bout
Vous pouvez exécuter les tests de bout en bout du code en exécutant (votre site doit d'abord être
démarré localement) :
```bash
yarn test:e2e
```
### Problèmes connus
#### Docker Compose
Sous Ubuntu, si vous rencontrez l'erreur `double free or corruption (out)`, la [solution
actuelle][link-issue-1] consiste à forcer la désinstallation de la dépendance concernée :
```bash
dpkg -r --force-depends golang-docker-credential-helpers
```
#### Jest Watch
Sous Ubuntu, si vous rencontrez l'erreur
`Error: ENOSPC: System limit for number of file watchers reached`, la [solution
actuelle][link-issue-2] consiste à augmenter le nombre de watchers du système de fichiers en
exécutant :
## Contribute
```bash
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
```
Please check the [contributing documentation][link-contributing].
### License
Le code source de ce dépôt est distribué sous la [licence Apache 2.0][link-license].
[![licence Apache 2.0][img-license]][link-license]
---
[img-codecov]: https://img.shields.io/codecov/c/github/SocialGouv/code-du-travail-backoffice?style=flat-square
[img-license]: https://img.shields.io/github/license/SocialGouv/code-du-travail-backoffice?style=for-the-badge
[img-travis]: https://img.shields.io/travis/SocialGouv/code-du-travail-backoffice/dev.svg?style=flat-square
[link-cdtn]: https://codedutravail.num.social.gouv.fr
[link-cdtn]: https://code.travail.gouv.fr/
[link-codecov]: https://codecov.io/gh/SocialGouv/code-du-travail-backoffice
[link-issue-1]: https://github.com/docker/docker-credential-helpers/issues/103#issuecomment-421822269
[link-issue-2]: https://github.com/facebook/jest/issues/3254#issuecomment-297214395
[link-contributing]: https://github.com/SocialGouv/code-du-travail-backoffice/blob/master/CONTRIBUTING.md
[link-license]: https://github.com/SocialGouv/code-du-travail-backoffice/blob/master/LICENSE
[link-travis]: https://travis-ci.com/SocialGouv/code-du-travail-backoffice
module.exports = {
babelrcRoots: [".", "packages/*"]
babelrcRoots: [".", "packages/*"],
};
codecov:
notify:
require_ci_to_pass: yes
coverage:
precision: 2
round: down
range: "70...100"
status:
project: no
patch: no
changes: no
parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no
comment: off
const getMigrationQuery = require("../../../scripts/db/getMigrationQuery");
exports.up = async knex => {
await knex.raw(getMigrationQuery("20190311094407_create_get_current_user_agreements_function").up());
await knex.raw(
getMigrationQuery("20190311094407_create_get_current_user_agreements_function").up(),
);
};
exports.down = async knex => {
await knex.raw(getMigrationQuery("20190311094407_create_get_current_user_agreements_function").down());
await knex.raw(
getMigrationQuery("20190311094407_create_get_current_user_agreements_function").down(),
);
};
const getMigrationQuery = require("../../../scripts/db/getMigrationQuery");
exports.up = async knex => {
await knex.raw(getMigrationQuery("20190418101832_add_answers_table_generic_reference_field").up());
await knex.raw(
getMigrationQuery("20190418101832_add_answers_table_generic_reference_field").up(),
);
};
exports.down = async knex => {
await knex.raw(getMigrationQuery("20190418101832_add_answers_table_generic_reference_field").down());
await knex.raw(
getMigrationQuery("20190418101832_add_answers_table_generic_reference_field").down(),
);
};
......@@ -5,5 +5,7 @@ exports.up = async knex => {
};
exports.down = async knex => {
await knex.raw(getMigrationQuery("20190506210704_fix_contributor_answers_view_uniqueness").down());