|
| 1 | +name: Accessibility Score |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +jobs: |
| 12 | + lighthouse: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + services: |
| 15 | + postgres: |
| 16 | + image: postgis/postgis:latest |
| 17 | + ports: |
| 18 | + - "5432:5432" |
| 19 | + env: |
| 20 | + POSTGRES_DB: rails_test |
| 21 | + POSTGRES_USER: rails |
| 22 | + POSTGRES_PASSWORD: password |
| 23 | + env: |
| 24 | + RAILS_ENV: development |
| 25 | + DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test" |
| 26 | + steps: |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v3 |
| 29 | + |
| 30 | + # Install ruby and gems |
| 31 | + - name: Install Ruby and gems |
| 32 | + uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 |
| 33 | + with: |
| 34 | + bundler-cache: true |
| 35 | + |
| 36 | + # Clean up old pids |
| 37 | + - name: Clean up any possible previous puma pids |
| 38 | + run: rm -f spec/dummy/tmp/pids/server.pid |
| 39 | + |
| 40 | + # Set up database |
| 41 | + - name: Set up database schema |
| 42 | + run: rails db:schema:load |
| 43 | + |
| 44 | + # RUn rails server |
| 45 | + - name: Run Rails server |
| 46 | + run: rails s -p 3000 -b 0.0.0.0 |
| 47 | + |
| 48 | + - name: Set up Node.js |
| 49 | + uses: actions/setup-node@v2 |
| 50 | + with: |
| 51 | + node-version: '14' |
| 52 | + |
| 53 | + - name: Install Lighthouse |
| 54 | + run: npm install -g lighthouse |
| 55 | + |
| 56 | + - name: Run Lighthouse |
| 57 | + run: | |
| 58 | + URL_TO_TEST="http://localhost:3000" # Adjust this to your app's URL |
| 59 | + lighthouse $URL_TO_TEST --only-categories=accessibility --output=json --output-path=./report.json |
| 60 | +
|
| 61 | + - name: Upload Lighthouse report |
| 62 | + uses: actions/upload-artifact@v2 |
| 63 | + with: |
| 64 | + name: lighthouse-report |
| 65 | + path: ./report.json |
| 66 | + |
| 67 | + - name: Parse Lighthouse report |
| 68 | + run: | |
| 69 | + score=$(cat ./report.json | jq '.categories.accessibility.score') |
| 70 | + if (( $(echo "$score < 0.9" | bc -l) )); then |
| 71 | + echo "Accessibility score is below 90%. Failing the build." |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | + echo "Accessibility score is acceptable." |
0 commit comments