ant-design/.github/workflows/visual-regression-persist-finish.yml
vagusX 32eccfdd88
ci: make puppeteer works when reusing node_modules (#46107)
* feat: update

* feat: add options as root user

* chore: update

* chore: update

* feat: move puppeteer into node_modules cache

* chore: update

* fix: update

* fix: typo for push

* chore: cleanup

* fix: make persist finish works

* chore: test tar speed

* chore: debug tar files

* fix: clone firstly

* fix: clone with token

* chore: local passed

* fix: commit not cm

* fix: git config --local

* chore: clean up

* chore: update

* fix: replace token to user_id
2023-11-28 19:42:35 +08:00

114 lines
4.1 KiB
YAML

# Each `push on master` will persist image-snapshots that used as compare target in visual regression.
name: 👁️ Visual Regression Persist Finish
on:
workflow_run:
workflows: ["👁️ Visual Regression Persist Start"]
types:
- completed
permissions:
contents: read
jobs:
upstream-workflow-summary:
name: upstream workflow summary
runs-on: ubuntu-latest
outputs:
jobs: ${{ steps.persist_start_job_status.outputs.result }}
build-success: ${{ steps.persist_start_job_status.outputs.build-success }}
build-failure: ${{ steps.persist_start_job_status.outputs.build-failure }}
steps:
- name: summary jobs status
uses: actions/github-script@v6
id: persist_start_job_status
with:
# todo: split it out as github actions
script: |
const response = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
// { [name]: [conclusion] }, e.g. { 'test image': 'success' }
const jobs = (response.data?.jobs ?? []).reduce((acc, job) => {
if(job?.status === 'completed' && 'name' in job && 'conclusion' in job) {
acc[job.name] = job.conclusion;
}
return acc;
}, {});
const total = Object.keys(jobs).length;
if(total === 0) core.setFailed('no jobs found');
// the name here must be the same as `jobs.xxx.{name}` in preview-build.yml
// set output
core.setOutput('build-success', jobs['test image'] === 'success');
core.setOutput('build-failure', jobs['test image'] === 'failure');
return jobs;
persist-image-snapshots:
name: persist image-snapshots
permissions:
actions: read # for dawidd6/action-download-artifact to query and download artifacts
runs-on: ubuntu-latest
needs: upstream-workflow-summary
steps:
# We need get persist key first
- name: Download Visual Regression Ref
uses: dawidd6/action-download-artifact@v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
name: visual-regression-persist-ref
# Save visual-regression ref to output
- name: Extra Visual Regression Ref
id: visuall-regression
run: echo "id=$(<visual-regression-ref.txt)" >> $GITHUB_OUTPUT
- name: Download Visual-Regression Artifact
if: ${{ fromJSON(needs.upstream-workflow-summary.outputs.build-success) }}
uses: dawidd6/action-download-artifact@v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
name: image-snapshots
path: ./
- name: Persist to Snapshot Repo
if: github.ref_name == 'master'
id: persist
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.ANTD_IMAGE_SNAP_REPO_TOKEN }}
# should push to snapshot repo firstly
# push the single folder to the repo
run: |
git clone https://$GITHUB_TOKEN@github.com/ant-design/antd-image-snapshots.git
echo "✅ Clone Finished"
rm antd-image-snapshots/*.txt
mv visual-regression-ref.txt antd-image-snapshots/
rm -rf antd-image-snapshots/imageSnapshots/*
tar -xzvf imageSnapshots.tar.gz -C antd-image-snapshots/imageSnapshots
echo "✅ Changes Finished"
cd antd-image-snapshots
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -a -m 'feat: update snapshot from ${{steps.visuall-regression.outputs.id}}'
echo "✅ Commit Finished"
git push --prune https://vaugsX:$GITHUB_TOKEN@github.com/ant-design/antd-image-snapshots.git +refs/remotes/origin/*:refs/heads/*
echo "✅ Push Finished"