Skip to content

Commit

Permalink
Mda cicd accessibility (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeDan authored Aug 27, 2024
1 parent ae2f8db commit e0b860d
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 27 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/accessibility-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Accessibility Test
run-name: Checking Accessibility

on: [push]

jobs:
accessibility:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install dependencies
run: npm ci

- name: Set up Docker
uses: docker/setup-buildx-action@v2

- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Build and run Docker Compose for DB
env:
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
run: |
docker-compose -f docker-compose.dev.yml up -d
echo "Waiting for database to be ready..."
sleep 30
- name: Run Prisma migrations
env:
DATABASE_URL: postgres://postgres:${{ secrets.DATABASE_PASSWORD }}@localhost:5433/patrigma_db
run: |
npx prisma migrate dev
npx prisma db seed
- name: Build Next.js application
run: npm run build

- name: Start Next.js application
env:
DATABASE_URL: postgres://postgres:${{ secrets.DATABASE_PASSWORD }}@localhost:5433/patrigma_db
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
NEXTAUTH_URL: http://localhost:3000
run: |
npm run start & # Start the Next.js application in the background
echo "Waiting for Next.js to be ready..."
sleep 10
- name: Install xvfb
run: sudo apt-get install -y xvfb

- name: Run Lighthouse CI with xvfb
uses: treosh/lighthouse-ci-action@v12
with:
urls: http://localhost:3000
uploadArtifacts: true
env:
XVFB_RUN_CMD: xvfb-run --auto-servernum --server-args='-screen 0 1024x768x24'
106 changes: 106 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Build, Test, Release, and Publish
run-name: Release and Publish Docker image

on:
push:
branches:
- tesci

env:
VERSION: "" # Définition initiale de la variable

jobs:
test-app:
name: Test App
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Install dependencies
run: npm install

- name: Run tests
run: npm test

create_release:
name: Create Release
runs-on: ubuntu-latest
needs: test-app
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get version from package.json
id: get_version
run: |
VERSION=$(jq -r .version package.json)
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
with:
tag_name: "v${{ env.VERSION }}"
release_name: "Release v${{ env.VERSION }}"
draft: false
prerelease: false

build-docker-prod:
runs-on: ubuntu-latest
needs: [test-app, create_release]
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/patrigma:v${{ env.VERSION }} # Utilisation de la variable VERSION globale
labels: "version=${{ env.VERSION }},commit=${{ github.sha }}"

notify:
runs-on: ubuntu-latest
needs: build-docker-prod
steps:
- name: Notify Discord on failure
if: failure()
uses: containrrr/shoutrrr-action@v1
with:
url: ${{ secrets.NOTIFICATION_URL }}
title: "Build Failed for Release v${{ env.VERSION }}"
message: |
The build for release v${{ env.VERSION }} has failed.
Commit message: ${{ github.event.head_commit.message }}
Commit SHA: ${{ github.sha }}
- name: Notify Discord on success
if: success()
uses: containrrr/shoutrrr-action@v1
with:
url: ${{ secrets.NOTIFICATION_URL }}
title: "Build Succeeded for Release v${{ env.VERSION }}"
message: |
The build for release v${{ env.VERSION }} was successful.
Commit message: ${{ github.event.head_commit.message }}
Commit SHA: ${{ github.sha }}
The Docker image has been published.
8 changes: 0 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,5 @@ COPY --from=build /patrigma/.next ./.next

EXPOSE 3000

COPY docker/next/docker-entrypoint.sh /usr/local/bin/docker-entrypoint

RUN chmod +x /usr/local/bin/docker-entrypoint


ENTRYPOINT [ "docker-entrypoint" ]


CMD ["npm", "run", "start"]

20 changes: 20 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
patrigma_db:
image: postgres:latest
container_name: patrigma_db
ports:
- "5433:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_DB: patrigma_db
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d patrigma_db -h localhost -p 5432"]
interval: 10s
timeout: 5s
retries: 5

volumes:
postgres_data:
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ services:
- NODE_ENV=${NODE_ENV}
- DATABASE_PASSWORD=${DATABASE_PASSWORD}
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
- BASE_URL=${BASE_URL}
- NEXT_PUBLIC_BASE_URL=${BASE_URL}
ports:
- "3000:3000"
Expand Down
12 changes: 0 additions & 12 deletions docker/next/docker-entrypoint.sh

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-patrigma",
"version": "0.1.0",
"name": "patrigma",
"version": "0.1.1",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
5 changes: 1 addition & 4 deletions src/components/form/journey/JourneyForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ const JourneyForm = () => {
// @ts-ignore
const stepObject: StepWithoutDates[] = parsedSteps.steps.map(
(step, index) => {
// to do : get optional additional location fields (city, country, address, postal code)
return {
puzzle: step.puzzle,
hint: step.hint,
Expand All @@ -98,8 +97,6 @@ const JourneyForm = () => {
},
);

// to do : estimate distance and duration from steps

// get user id from session
const journeyObject: JourneyWithoutDates = {
authorId: Number(session?.user?.id),
Expand All @@ -126,7 +123,7 @@ const JourneyForm = () => {

const token = session?.accessToken;
const res = await fetch(
`${process.env.BASE_URL || "http://localhost:3000"}/api/journeys`,
`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/journeys`,
{
method: "POST",
body: JSON.stringify(body),
Expand Down

0 comments on commit e0b860d

Please sign in to comment.