Skip to content

Commit

Permalink
Merge pull request #906 from eleven-labs/ci/audit-lighthouse
Browse files Browse the repository at this point in the history
👷 Add lighthouse audit to github action
  • Loading branch information
fpasquet authored Feb 8, 2023
2 parents 5e95b51 + 61923d2 commit c5a0d94
Show file tree
Hide file tree
Showing 5 changed files with 399 additions and 63 deletions.
183 changes: 120 additions & 63 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,129 @@
name: Deploy

on:
push:
branches:
- master
pull_request:

env:
AWS_DEFAULT_REGION: eu-west-2
CLOUDFRONT_DISTRIBUTION: E1LGTLFSNFBYPG
push:
branches:
- master
pull_request:

jobs:
deploy:
name: deploy
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2

- name: setup ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: configure
if: github.event_name == 'pull_request'
run: |
sed -i "/^url:/c\url: http:\/\/dev.blog.eleven-labs.com.s3-website.${{ env.AWS_DEFAULT_REGION }}.amazonaws.com" _config.yml
sed -i "/^baseurl:/c\baseurl: \/${{ github.head_ref }}" _config.yml
- name: lint
run: bundle exec rake lint

- name: build with draft
if: github.event_name == 'pull_request'
run: bundle exec jekyll build --drafts --future

- name: build
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: bundle exec rake build

- name: setup aws
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}

- name: deploy
if: github.event_name == 'pull_request'
run: aws s3 sync "_site/" "s3://dev.blog.eleven-labs.com/${{ github.head_ref }}/" --delete

- name: deploy
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: aws s3 sync "_site/" "s3://blog.eleven-labs.com/" --delete

- name: clear caches
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: |
aws configure set preview.cloudfront true
aws cloudfront create-invalidation --distribution-id "${{ env.CLOUDFRONT_DISTRIBUTION }}" --paths "/*"
#- name: notify
# if: github.ref == 'refs/heads/master' && github.event_name == 'push'
# run:

- name: algolia
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: bundle exec rake deploy
env:
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
- name: Checkout
uses: actions/checkout@v2

- name: Sets env vars for production
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: |
echo "ENV=production" >> $GITHUB_ENV
echo "ENV_URL=https://blog.eleven-labs.com" >> $GITHUB_ENV
- name: Sets env vars for dev and configure website
if: github.event_name == 'pull_request'
run: |
echo "ENV=dev-${{ github.head_ref }}" >> $GITHUB_ENV
echo "ENV_URL=http://dev.blog.eleven-labs.com.s3-website.${{ secrets.AWS_REGION }}.amazonaws.com/${{ github.head_ref }}" >> $GITHUB_ENV
sed -i "/^url:/c\url: http:\/\/dev.blog.eleven-labs.com.s3-website.${{ secrets.AWS_REGION }}.amazonaws.com" _config.yml
sed -i "/^baseurl:/c\baseurl: \/${{ github.head_ref }}" _config.yml
- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Lint
run: bundle exec rake lint

- name: Build with draft
if: github.event_name == 'pull_request'
run: bundle exec jekyll build --drafts --future

- name: Build
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: bundle exec rake build

- name: Setup aws
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Start deployment
uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.head_ref }}
env: ${{ env.ENV }}

- name: Deploy to S3
if: github.event_name == 'pull_request'
run: aws s3 sync "_site/" "s3://dev.blog.eleven-labs.com/${{ github.head_ref }}/" --delete

- name: Deploy to S3
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: aws s3 sync "_site/" "s3://blog.eleven-labs.com/" --delete

- name: Clear caches
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: |
aws configure set preview.cloudfront true
aws cloudfront create-invalidation --distribution-id "${{ secrets.CLOUDFRONT_DISTRIBUTION }}" --paths "/*"
- name: Indexing on Algolia
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: bundle exec rake deploy
env:
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}

- name: Update deployment status
uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
env: ${{ steps.deployment.outputs.env }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env_url: ${{ env.ENV_URL }}/

- name: Audit URLs using Lighthouse
id: lighthouse_audit
uses: treosh/lighthouse-ci-action@v9
with:
urls: |
${{ env.ENV_URL }}/
${{ env.ENV_URL }}/authors/ajacquemin/
${{ env.ENV_URL }}/fr/comment-construire-site-web-avec-nextjs/
${{ env.ENV_URL }}/fr/nestjs-le-cycle-de-vie-dune-requete/
configPath: ./.github/workflows/lighthousesrc.json
uploadArtifacts: true
temporaryPublicStorage: true
runs: 3

- name: Format lighthouse score
id: format_lighthouse_score
uses: actions/github-script@v6
with:
script: |
const lighthouseCommentMaker = require('./.github/workflows/lighthouseCommentMaker.js');
const lighthouseOutputs = {
manifest: ${{ steps.lighthouse_audit.outputs.manifest }},
links: ${{ steps.lighthouse_audit.outputs.links }},
assertionResults: ${{ steps.lighthouse_audit.outputs.assertionResults }}
};
const comment = lighthouseCommentMaker({ lighthouseOutputs });
core.setOutput("comment", comment);
- name: Add Lighthouse stats as comment
id: comment_to_pr
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.pull_request.number }}
header: lighthouse
message: ${{ steps.format_lighthouse_score.outputs.comment }}
21 changes: 21 additions & 0 deletions .github/workflows/lighthouse-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
extends: 'lighthouse:default',
settings: {
maxWaitForFcp: 15 * 1000,
maxWaitForLoad: 35 * 1000,
throttling: {
cpuSlowdownMultiplier: 2
},
skipAudits: ['uses-http2'],
},
audits: [
'metrics/first-contentful-paint-3g',
],
categories: {
performance: ({
auditRefs: [
{ id: 'first-contentful-paint-3g', weight: 0 },
],
}),
},
};
Loading

0 comments on commit c5a0d94

Please sign in to comment.