Fix/test pr for chromatic 2 #10
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
# This Source Code Form is subject to the terms of the Mozilla Public | |
# License, v. 2.0. If a copy of the MPL was not distributed with this | |
# file, You can obtain one at https://mozilla.org/MPL/2.0/. | |
# | |
# OpenCRVS is also distributed under the terms of the Civil Registration | |
# & Healthcare Disclaimer located at http://opencrvs.org/license. | |
# | |
# Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. | |
name: 'Chromatic' | |
on: | |
pull_request: | |
branches: | |
- develop | |
jobs: | |
prepare-client-tests: | |
name: Prepare client tests | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checking out git repo | |
uses: actions/checkout@v4 | |
- name: Use Node.js from .nvmrc | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .nvmrc | |
- name: Extract dependencies for client | |
id: extract-dependencies | |
run: | | |
DEPENDENCIES=$(node -e " | |
const { execSync } = require('child_process'); | |
const output = execSync('yarn --silent workspaces info', { encoding: 'utf-8' }); | |
const json = JSON.parse(output.replaceAll('@opencrvs', 'packages')); | |
const getDependencies = (pkg) => | |
json[pkg].workspaceDependencies.concat( | |
json[pkg].workspaceDependencies.flatMap(getDependencies) | |
); | |
console.log( | |
getDependencies('packages/client').join(' ') | |
); | |
") | |
echo "DEPENDENCIES=${DEPENDENCIES}" >> $GITHUB_ENV | |
echo "Found dependencies: $DEPENDENCIES" | |
- name: Remove other package directories | |
run: | | |
for dir in packages/*; do | |
if echo "packages/client $DEPENDENCIES" | grep -q -w "$dir"; then | |
echo "Skipping $dir" | |
else | |
echo "Removing $dir" | |
rm -rf "$dir" | |
fi | |
done | |
- name: Cache Node.js dependencies | |
uses: actions/cache@v4 | |
with: | |
path: | | |
**/node_modules | |
~/.cache/yarn/v6 | |
key: node-${{ hashFiles('**/yarn.lock', format('{0}/{1}','packages/client','package.json')) }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: CI="" yarn install --frozen-lockfile | |
- name: Build common package | |
run: cd packages/commons && yarn build | |
- name: Build components | |
run: | | |
cd packages/components && yarn build | |
- name: Upload filesystem as artifact | |
uses: actions/[email protected] | |
with: | |
name: client | |
include-hidden-files: true | |
path: | | |
. | |
!**/node_modules | |
chromatic: | |
needs: prepare-client-tests | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Download filesystem artifact | |
uses: actions/[email protected] | |
with: | |
name: client | |
path: . | |
- name: Use Node.js from .nvmrc | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .nvmrc | |
- name: Cache Node.js dependencies | |
uses: actions/cache@v4 | |
with: | |
path: | | |
**/node_modules | |
~/.cache/yarn/v6 | |
key: node-${{ hashFiles('**/yarn.lock', format('{0}/{1}','packages/client','package.json')) }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: CI="" yarn install --frozen-lockfile | |
# Without this, the fetch command will fail with | |
# fatal: could not read Username for 'https://github.com': No such device or address | |
- name: Remove extraheader config | |
run: git config --unset http.https://github.com/.extraheader | |
- name: Fetch full Git history | |
run: git fetch --prune --unshallow | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Run Chromatic | |
uses: chromaui/action@latest | |
with: | |
workingDir: packages/client | |
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} |