feat: add tuto chromatic #1518
Workflow file for this run
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: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
permissions: write-all | |
environment: ${{ github.ref_name == 'master' && 'production' || github.ref_name }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Sets env vars for dev | |
if: github.event_name == 'pull_request' | |
run: | | |
echo "ENV=${{ github.head_ref }}" >> $GITHUB_ENV | |
echo "ENV_URL=https://${{ vars.AWS_BUCKET_NAME }}/${{ github.head_ref }}" >> $GITHUB_ENV | |
echo "BASE_URL=/${{ github.head_ref }}/" >> $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://${{ vars.AWS_BUCKET_NAME }}" >> $GITHUB_ENV | |
echo "BASE_URL=/" >> $GITHUB_ENV | |
- name: Setup node | |
uses: actions/setup-node@v3 | |
with: | |
bundler-cache: true | |
node-version: 20 | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "yarnCacheDir=$(yarn cache dir)" >> $GITHUB_OUTPUT | |
- uses: actions/cache@v3 | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.yarnCacheDir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install modules | |
run: yarn install --frozen-lockfile | |
- name: Validate markdown authors and posts | |
id: validate_markdown | |
run: yarn validate-markdown --ci | |
- name: Add a comment to the PR after failed markdown validation | |
uses: marocchino/sticky-pull-request-comment@v2 | |
if: github.event_name == 'pull_request' && failure() | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
number: ${{ github.event.pull_request.number }} | |
header: validate-markdown | |
message: | | |
#### Markdown invalid 🖌 | |
The markdown of the file **${{ steps.validate_markdown.outputs.filePath }}** is invalid ! | |
> ${{ steps.validate_markdown.outputs.reason }} | |
- name: Remove a comment to the PR after success markdown validation | |
uses: marocchino/sticky-pull-request-comment@v2 | |
if: github.event_name == 'pull_request' && success() | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
number: ${{ github.event.pull_request.number }} | |
header: validate-markdown | |
delete: true | |
- name: Run ESLint | |
run: yarn lint:es | |
- name: Run Stylelint | |
run: yarn lint:style | |
- name: Run Compile TypeScript | |
run: yarn tsc | |
- name: Run Test | |
run: yarn test | |
- name: Build | |
run: yarn prerender | |
env: | |
NODE_ENV: production | |
BASE_URL: ${{ env.BASE_URL }} | |
VITE_ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }} | |
VITE_ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_SEARCH_KEY }} | |
VITE_ALGOLIA_INDEX: ${{ vars.ALGOLIA_INDEX }} | |
VITE_GTM_ID: ${{ vars.GTM_ID }} | |
- name: Install aws cli | |
id: install-aws-cli | |
uses: unfor19/install-aws-cli-action@v1 | |
- name: Setup aws | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} | |
aws-region: ${{ vars.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 | |
run: aws s3 sync "dist/public/" "s3://${{ vars.AWS_BUCKET_NAME }}${{ env.BASE_URL }}" --delete | |
- name: Clear caches | |
run: aws cloudfront create-invalidation --distribution-id "${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }}" --paths "${{ env.BASE_URL }}*" | |
- name: Indexing on Algolia | |
run: yarn indexation:algolia | |
env: | |
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }} | |
ALGOLIA_API_INDEXING_KEY: ${{ secrets.ALGOLIA_API_INDEXING_KEY }} | |
ALGOLIA_INDEX: ${{ vars.ALGOLIA_INDEX }} | |
- name: Update deployment status | |
uses: bobheadxi/deployments@v1 | |
if: success() | |
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 | |
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 }} |