2023-12-09 21:49:47 +08:00
|
|
|
# Each PR will visual-regression diff that help to check code is work as expect.
|
|
|
|
|
|
|
|
name: 👀 Visual Regression Diff Build
|
|
|
|
|
|
|
|
on:
|
|
|
|
pull_request:
|
2023-12-09 23:54:58 +08:00
|
|
|
branches: [master, feature]
|
2023-12-09 21:49:47 +08:00
|
|
|
types: [opened, synchronize, reopened]
|
|
|
|
|
|
|
|
# Cancel prev CI if new commit come
|
|
|
|
concurrency:
|
|
|
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
# Prepare node modules. Reuse cache if available
|
|
|
|
setup:
|
|
|
|
name: prepare node_modules
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: checkout
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
|
|
|
- name: cache package-lock.json
|
|
|
|
uses: actions/cache@v3
|
|
|
|
with:
|
|
|
|
path: package-temp-dir
|
|
|
|
key: lock-${{ github.sha }}
|
|
|
|
|
|
|
|
- name: create package-lock.json
|
|
|
|
run: npm i --package-lock-only --ignore-scripts
|
|
|
|
|
|
|
|
- name: hack for single file
|
|
|
|
run: |
|
|
|
|
if [ ! -d "package-temp-dir" ]; then
|
|
|
|
mkdir package-temp-dir
|
|
|
|
fi
|
|
|
|
cp package-lock.json package-temp-dir
|
|
|
|
|
|
|
|
- name: cache node_modules
|
|
|
|
id: node_modules_cache_id
|
|
|
|
uses: actions/cache@v3
|
|
|
|
with:
|
|
|
|
path: node_modules
|
|
|
|
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
|
|
|
|
|
|
|
|
- name: install
|
|
|
|
if: steps.node_modules_cache_id.outputs.cache-hit != 'true'
|
|
|
|
run: npm ci
|
|
|
|
|
|
|
|
visual-diff-report:
|
|
|
|
name: visual-diff report
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs: setup
|
|
|
|
steps:
|
|
|
|
- name: checkout
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
|
|
|
- uses: actions/setup-node@v3
|
|
|
|
with:
|
|
|
|
node-version: 18
|
|
|
|
|
|
|
|
- name: restore cache from package-lock.json
|
|
|
|
uses: actions/cache@v3
|
|
|
|
with:
|
|
|
|
path: package-temp-dir
|
|
|
|
key: lock-${{ github.sha }}
|
|
|
|
|
|
|
|
- name: restore cache from node_modules
|
|
|
|
uses: actions/cache@v3
|
|
|
|
with:
|
|
|
|
path: node_modules
|
|
|
|
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
|
|
|
|
|
|
|
|
- name: generate image snapshots
|
|
|
|
id: test-image
|
|
|
|
run: |
|
|
|
|
node node_modules/puppeteer/install.mjs
|
|
|
|
npm run version
|
|
|
|
npm run test-image
|
|
|
|
env:
|
|
|
|
NODE_OPTIONS: "--max_old_space_size=4096"
|
|
|
|
|
|
|
|
# Execute visual regression diff task and zip then
|
|
|
|
# output as visualRegressionReport.tar.gz
|
|
|
|
- name: visual regression diff
|
2023-12-19 11:23:53 +08:00
|
|
|
env:
|
|
|
|
EVENT_NUMBER: ${{ github.event.number }}
|
|
|
|
BASE_REF: ${{ github.base_ref }}
|
2023-12-09 21:49:47 +08:00
|
|
|
run: |
|
2023-12-19 11:23:53 +08:00
|
|
|
npm run visual-regression -- --pr-id=$EVENT_NUMBER --base-ref=$BASE_REF
|
2023-12-09 21:49:47 +08:00
|
|
|
|
|
|
|
# Upload report in `visualRegressionReport`
|
|
|
|
- name: upload report artifact
|
|
|
|
uses: actions/upload-artifact@v3
|
2023-12-18 14:25:40 +08:00
|
|
|
if: ${{ always() }}
|
2023-12-09 21:49:47 +08:00
|
|
|
with:
|
|
|
|
name: visual-regression-report
|
|
|
|
path: visualRegressionReport.tar.gz
|
|
|
|
|
|
|
|
# Upload git ref for next workflow `visual-regression-diff-finish` use
|
|
|
|
- name: Save persist key
|
|
|
|
if: ${{ always() }}
|
2023-12-18 14:25:40 +08:00
|
|
|
# should be pr id
|
2023-12-09 21:49:47 +08:00
|
|
|
run: echo ${{ github.event.number }} > ./visual-regression-pr-id.txt
|
|
|
|
|
|
|
|
- name: Upload persist key
|
|
|
|
if: ${{ always() }}
|
|
|
|
uses: actions/upload-artifact@v3
|
|
|
|
with:
|
|
|
|
name: visual-regression-diff-ref
|
|
|
|
path: ./visual-regression-pr-id.txt
|