feat: improvement of the web perf #639
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
env: | |
AWS_DEFAULT_REGION: eu-west-2 | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Sets env vars for dev | |
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.${{ env.AWS_DEFAULT_REGION }}.amazonaws.com/${{ github.head_ref }}" >> $GITHUB_ENV | |
echo "BASE_URL=/${{ github.head_ref }}/" >> $GITHUB_ENV | |
echo "ALGOLIA_APP_ID=${{ secrets.ALGOLIA_APP_ID }}" >> $GITHUB_ENV | |
echo "ALGOLIA_INDEX=${{ secrets.ALGOLIA_INDEX_DEV }}" >> $GITHUB_ENV | |
echo "ALGOLIA_API_INDEXING_KEY=${{ secrets.ALGOLIA_API_INDEXING_KEY_DEV }}" >> $GITHUB_ENV | |
echo "ALGOLIA_API_SEARCH_KEY=${{ secrets.ALGOLIA_API_SEARCH_KEY_DEV }}" >> $GITHUB_ENV | |
- 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 | |
echo "BASE_URL=/" >> $GITHUB_ENV | |
echo "ALGOLIA_APP_ID=${{ secrets.ALGOLIA_APP_ID }}" >> $GITHUB_ENV | |
echo "ALGOLIA_INDEX=${{ secrets.ALGOLIA_INDEX_PRODUCTION }}" >> $GITHUB_ENV | |
echo "ALGOLIA_API_INDEXING_KEY=${{ secrets.ALGOLIA_API_INDEXING_KEY_PRODUCTION }}" >> $GITHUB_ENV | |
echo "ALGOLIA_API_SEARCH_KEY=${{ secrets.ALGOLIA_API_SEARCH_KEY_PRODUCTION }}" >> $GITHUB_ENV | |
- name: Setup node | |
uses: actions/setup-node@v3 | |
with: | |
bundler-cache: true | |
node-version: 16 | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- uses: actions/cache@v3 | |
id: yarn-cache | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install modules | |
run: | | |
echo '//npm.pkg.github.com/:_authToken=${NPM_TOKEN}' >> .npmrc | |
yarn install --frozen-lockfile | |
env: | |
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Validate markdown authors and posts | |
run: yarn validate-and-format-markdown | |
env: | |
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Run ESLint | |
run: yarn lint:es | |
env: | |
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Run Stylelint | |
run: yarn lint:style | |
env: | |
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Run Compile TypeScript | |
run: yarn tsc | |
env: | |
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build | |
run: yarn prerender | |
env: | |
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
BASE_URL: ${{ env.BASE_URL }} | |
VITE_ALGOLIA_APP_ID: ${{ env.ALGOLIA_APP_ID }} | |
VITE_ALGOLIA_API_KEY: ${{ env.ALGOLIA_API_SEARCH_KEY }} | |
VITE_ALGOLIA_INDEX: ${{ env.ALGOLIA_INDEX }} | |
- 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: 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 for dev | |
if: github.event_name == 'pull_request' | |
run: aws s3 sync "dist/public/" "s3://dev.blog.eleven-labs.com/${{ github.head_ref }}/" --delete | |
- name: Deploy to S3 for production | |
if: github.ref == 'refs/heads/master' && github.event_name == 'push' | |
run: aws s3 sync "dist/public/" "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 | |
run: yarn indexation:algolia | |
env: | |
ALGOLIA_APP_ID: ${{ env.ALGOLIA_APP_ID }} | |
ALGOLIA_API_INDEXING_KEY: ${{ env.ALGOLIA_API_INDEXING_KEY }} | |
ALGOLIA_INDEX: ${{ env.ALGOLIA_INDEX }} | |
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- 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 }}/fr/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 | |
if: github.event_name == 'pull_request' | |
with: | |
script: | | |
const lighthouseCommentMaker = require('./.github/workflows/lighthouseCommentMaker.cjs'); | |
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 | |
if: github.event_name == 'pull_request' | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
number: ${{ github.event.pull_request.number }} | |
header: lighthouse | |
message: ${{ steps.format_lighthouse_score.outputs.comment }} |