Skip to content

MaximeDan is creating a pull request #124

MaximeDan is creating a pull request

MaximeDan is creating a pull request #124

Workflow file for this run

name: Build, Test, and Accessibility
run-name: ${{ github.actor }} is creating a pull request
on: [pull_request]
permissions:
contents: read
checks: write
jobs:
RunTests:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm install
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Run tests and generate report
run: |
npm test
continue-on-error: false
- name: Upload test reports
if: always()
uses: actions/upload-artifact@v3
with:
name: test-reports
path: |
./test-report.html
./reports/junit/js-test-results.xml
- name: Notify Discord on failure
if: failure()
uses: containrrr/shoutrrr-action@v1
with:
url: ${{ secrets.NOTIFICATION_URL }}
title: "Build failed for ${{ github.actor }}"
message: |
Build failed or tests did not pass
Pull request: ${{ github.event.pull_request.html_url }}
accessibility:
name: Accessibility
runs-on: ubuntu-latest
needs: RunTests
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: npm ci
- name: Set up Docker
uses: docker/setup-buildx-action@v3
- 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
until docker exec -i patrigma_db pg_isready -U postgres; do
echo "Waiting for the database to be ready..."
sleep 2
done
echo "Database is ready!"
- 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..."
until curl -s http://localhost:3000 > /dev/null; do
echo "Waiting for Next.js to be ready..."
sleep 2
done
echo "Next.js is ready!"
- 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'
- name: Check Accessibility Score
run: |
# Trouver le fichier JSON généré
REPORT_FILE=$(ls .lighthouseci/*.json | head -n 1)
# Lire le score d'accessibilité
SCORE=$(cat $REPORT_FILE | jq '.categories.accessibility.score * 100')
echo "Accessibility Score: $SCORE"
# Vérifier si le score est inférieur à 90
if [ "$SCORE" -lt 90 ]; then
echo "Accessibility score is below 90. Failing the job."
exit 1
fi
test-report:
name: publish test report
runs-on: ubuntu-latest
needs: RunTests
if: always()
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download test reports
uses: actions/download-artifact@v3
with:
name: test-reports
- name: Publish test results
uses: dorny/test-reporter@v1
with:
name: Jest tests
path: ./reports/junit/js-test-results.xml
reporter: jest-junit