Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyriverain committed Dec 30, 2024
1 parent a208be6 commit 7bb2ce4
Show file tree
Hide file tree
Showing 71 changed files with 460 additions and 9,003 deletions.
9 changes: 0 additions & 9 deletions .env
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# Env file used by docker-compose.yml

########################################################################
# MySQL
########################################################################
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=symfony
MYSQL_USER=symfony
MYSQL_PASSWORD=symfony

########################################################################
# PHP
########################################################################
Expand Down
28 changes: 19 additions & 9 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
name: main
runs-on: ubuntu-22.04
permissions:
contents: 'read'
id-token: 'write'
contents: "read"
id-token: "write"
steps:
- uses: actions/checkout@v4
- name: setup node
Expand All @@ -20,7 +20,7 @@ jobs:
run: |
echo $GITHUB_REF_NAME
echo "branch=$GITHUB_REF_NAME" >> $GITHUB_OUTPUT
- uses: 'google-github-actions/auth@v2'
- uses: "google-github-actions/auth@v2"
with:
project_id: ${{ secrets.GCLOUD_PROJECT_ID_TEST }}
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER_TEST }}
Expand All @@ -29,6 +29,9 @@ jobs:
env:
GCLOUD_PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID_TEST}}
GCLOUD_BUCKET_ID: ${{secrets.GCLOUD_BUCKET_ID_TEST}}
DATABASE_URL: ${{secrets.DATABASE_URL_TEST}}
NEON_API_KEY: ${{secrets.NEON_API_KEY}}
NEON_PROJECT_ID: ${{secrets.NEON_PROJECT_ID_TEST}}
run: |
echo "${{ steps.prepare.outputs.branch }}"
docker compose build --build-arg UID=$(id -u) --build-arg GID=$(id -g) --no-cache
Expand All @@ -37,14 +40,17 @@ jobs:
echo -e "\nGCLOUD_PROJECT_ID=$GCLOUD_PROJECT_ID" >> symfony/.env
echo "GCLOUD_BUCKET_ID=${{github.run_id}}--$GCLOUD_BUCKET_ID" >> symfony/.env
echo "GOOGLE_APPLICATION_CREDENTIALS=/var/www/symfony/google_credentials.json" >> symfony/.env
cat symfony/.env
echo "DATABASE_URL=$DATABASE_URL" >> symfony/.env
touch symfony/.env.test.local
echo "DATABASE_URL=$DATABASE_URL" >> symfony/.env.test.local
echo "NEON_API_KEY=$NEON_API_KEY" >> symfony/.env.test.local
echo "NEON_PROJECT_ID=$NEON_PROJECT_ID" >> symfony/.env.test.local
mv gha-creds*.json symfony/google_credentials.json
docker compose exec -T db bash -c "npm run start"
docker compose exec -T php bash -c "composer install"
docker compose exec -T php bash -c "symfony console doctrine:database:drop --force --if-exists"
docker compose exec -T php bash -c "symfony console doctrine:database:create"
docker compose exec -T php bash -c "symfony console doctrine:schema:drop --full-database --force"
docker compose exec -T php bash -c "symfony console doctrine:migration:migrate --no-interaction"
docker compose exec -T php bash -c "symfony console app:remove-bucket ${{github.run_id}}--$GCLOUD_BUCKET_ID"
docker compose exec -T php bash -c "symfony console app:create-bucket ${{github.run_id}}--$GCLOUD_BUCKET_ID"
Expand All @@ -63,16 +69,19 @@ jobs:
env:
GCLOUD_PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID_TEST}}
GCLOUD_BUCKET_ID: ${{secrets.GCLOUD_BUCKET_ID_TEST}}
DATABASE_URL: ${{secrets.DATABASE_URL_TEST}}
NEON_API_KEY: ${{secrets.NEON_API_KEY}}
NEON_PROJECT_ID: ${{secrets.NEON_PROJECT_ID_TEST}}
run: docker compose exec -T cypress bash -c "npm run cy:run"

- name: prepare deploy
if: steps.prepare.outputs.branch == 'main'
run: echo $HOSTS | base64 -d > deploy_hosts.php
env:
HOSTS : ${{secrets.HOSTS}}
HOSTS: ${{secrets.HOSTS}}
- name: deploy
env:
HOSTS : ${{secrets.HOSTS}}
HOSTS: ${{secrets.HOSTS}}
if: steps.prepare.outputs.branch == 'main'
uses: deployphp/action@v1
with:
Expand All @@ -94,3 +103,4 @@ jobs:
path: |
e2e/cypress/videos
e2e/cypress/screenshots
symfony/var/log
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ git clone git@github.com:jeremyriverain/breizh-blok-back-office.git
cd breizh-blok-back-office
```

2. Renseignez les variables d'environnement `GCLOUD_PROJECT_ID`, `GCLOUD_BUCKET_ID` et `DATABASE_URL` dans le fichier `.env.local`

2. Exécutez le script d'initialisation Docker

```bash
Expand Down Expand Up @@ -51,15 +53,6 @@ Lorsque vous saisissez le mail sur le portail d'authentification, un email est e
docker compose exec php bash
```

## Accéder à la base de données

```bash
docker compose exec db bash
mysql -u root -p
```

Le mot de passe est `root`.

## Lancer l'analyse statique de code

[PHP Stan](https://github.com/phpstan/phpstan) est utilisé pour l'analyse statique de code. Pour la lancer, accéder au conteneur `php` et exécuter le script `composer` approprié:
Expand All @@ -78,7 +71,7 @@ composer run phpunit

## Lancer les tests Cypress

Créez un fichier `.env.test.local` et renseignez les variables d'environnement `GCLOUD_PROJECT_ID` et `GCLOUD_BUCKET_ID`.
Créez un fichier `.env.test.local` et renseignez les variables d'environnement `GCLOUD_PROJECT_ID`, `GCLOUD_BUCKET_ID`, `DATABASE_URL`, `NEON_API_KEY` et `NEON_PROJECT_ID`.

En mode headless:

Expand Down
17 changes: 0 additions & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
version: "3.9"

services:
db:
container_name: db
build:
context: ./mysql
command: ["--default-authentication-plugin=mysql_native_password"]
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- db:/var/lib/mysql
- /home/node_modules
php:
container_name: php-fpm
build:
Expand All @@ -25,8 +12,6 @@ services:
volumes:
- ./symfony:/var/www/symfony:cached
- ~/.config/gcloud:/.config/gcloud
depends_on:
- db

app_test:
container_name: app_test
Expand Down Expand Up @@ -65,5 +50,3 @@ services:
volumes:
- ./e2e:/home/e2e/tests:cached
- /home/e2e/tests/node_modules
volumes:
db:
20 changes: 16 additions & 4 deletions e2e/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { defineConfig } = require("cypress");
const { ofetch } = require("ofetch");

const { v4: uuidv4 } = require("uuid");
const runBaseUrl = "http://app_test";

function getMailCatcherUrl(baseUrl) {
Expand All @@ -9,6 +9,8 @@ function getMailCatcherUrl(baseUrl) {
: "http://localhost:1080";
}

const isCI = !!process.env.CI;
const databaseBranchName = isCI ? uuidv4() : "main";
module.exports = defineConfig({
e2e: {
baseUrl: runBaseUrl,
Expand All @@ -17,14 +19,24 @@ module.exports = defineConfig({
experimentalInteractiveRunEvents: true,
experimentalRunAllSpecs: true,
specPattern: "cypress/integration/**/*.cy.js",
requestTimeout: 10000,
defaultCommandTimeout: 10000,
setupNodeEvents(on, config) {
on("before:run", async () => {
await ofetch(config.baseUrl + "/test/init-db");
return await ofetch(config.baseUrl + "/test/dump-db");
return await ofetch(
config.baseUrl + `/test/init-db/${databaseBranchName}`
);
});
on("after:run", async () => {
return await ofetch(
config.baseUrl + `/test/clean-db/${databaseBranchName}`
);
});
on("task", {
async loadDb() {
return await ofetch(config.baseUrl + "/test/load-db");
return await ofetch(
config.baseUrl + `/test/load-db/${databaseBranchName}`
);
},
async fetchEmails() {
const mailcatcherUrl = getMailCatcherUrl(config.baseUrl);
Expand Down
8 changes: 5 additions & 3 deletions e2e/cypress/integration/admin/Boulder.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ context("Boulders-write as superadmin", () => {
});

it("updatedBy and updatedAt fields are automatically assigned", () => {
cy.contains("Nom").click();
cy.get("tr a.dropdown-toggle").first().takeAction("Consulter");
cy.get(".cy_updated_at").contains("Mis à jour le");
cy.get(".cy_updated_at").should("contain", "Aucun(e)");
cy.get(".cy_updated_by").contains("Mis à jour par");
cy.get(".cy_updated_by").should("contain", "Aucun(e)");
cy.contains("Éditer").click();
cy.get("input[name=Boulder\\[name\\]]").clear().type("Foo");
cy.get("input[name=Boulder\\[name\\]]").clear().type("Zzz");
cy.contains("Sauvegarder les modifications").click();
cy.get("tr a.dropdown-toggle").first().takeAction("Consulter");
cy.contains("Zzz");
cy.get(".cy_updated_at").should("not.contain", "Aucun(e)");
cy.get(".cy_updated_by").should("contain", "super-admin@fixture.com");
});
Expand All @@ -92,7 +94,7 @@ context("Boulders-write as admin", () => {
cy.get("input[name=Boulder\\[name\\]]").should("have.class", "is-invalid");

cy.get("input[name=Boulder\\[name\\]]").type("La route du rhum");
cy.get("select[name=Boulder\\[rock\\]]").chooseOption("Menez Ham #3");
cy.get("select[name=Boulder\\[rock\\]]").chooseOption("Menez Ham");

cy.get("button.action-save").contains("Créer").click();
cy.get("table tbody tr").should("have.length", 5);
Expand Down Expand Up @@ -182,7 +184,7 @@ context("Boulders-write as contributor", () => {
cy.get("h1").should("contain.text", 'Créer "Bloc"');
cy.get("button.action-save").contains("Créer").click();
cy.get("input[name=Boulder\\[name\\]]").type("La route du rhum");
cy.get("select[name=Boulder\\[rock\\]]").chooseOption("Cremiou #1");
cy.get("select[name=Boulder\\[rock\\]]").chooseOption("Cremiou");

cy.get("button.action-save").contains("Créer").click();
cy.get("table tbody tr").should("have.length", 5);
Expand Down
2 changes: 1 addition & 1 deletion e2e/cypress/integration/api/LineBoulder.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ context("LineBoulder-write as contributor", () => {
cy.get("h1").should("contain.text", 'Créer "Bloc"');
cy.get("button.action-save").contains("Créer").click();
cy.get("input[name=Boulder\\[name\\]]").type("La route du rhum");
cy.get("select[name=Boulder\\[rock\\]]").chooseOption("Cremiou #1");
cy.get("select[name=Boulder\\[rock\\]]").chooseOption("Cremiou");

cy.get("button.action-save").contains("Créer").click();
cy.get("table tbody tr").should("have.length", 5);
Expand Down
40 changes: 32 additions & 8 deletions e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"devDependencies": {
"cypress": "^13.6.6",
"cypress-real-events": "^1.12.0",
"ofetch": "^1.3.3"
"ofetch": "^1.3.3",
"uuid": "^11.0.3"
},
"scripts": {
"cy:open": "CYPRESS_baseUrl=http://localhost:3333 cypress open --e2e --browser chrome",
Expand Down
5 changes: 1 addition & 4 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ set -e
docker compose build --build-arg UID=$(id -u) --build-arg GID=$(id -g) # --no-cache --pull

# Lance les conteneurs de l'application
docker compose up -d

# Démarre l'API permettant de sauvegarder et charger la base de données à la volée durant les tests E2E.
docker compose exec db bash -c "npm run start"
docker compose up -d --remove-orphans

# Exécute le script d'initialisation du conteneur php (./symfony/init.sh)
docker compose exec php bash -c "./init.sh"
1 change: 0 additions & 1 deletion mysql/.gitignore

This file was deleted.

18 changes: 0 additions & 18 deletions mysql/Dockerfile

This file was deleted.

18 changes: 0 additions & 18 deletions mysql/app.mjs

This file was deleted.

Loading

0 comments on commit 7bb2ce4

Please sign in to comment.