-
Notifications
You must be signed in to change notification settings - Fork 72
101 lines (85 loc) · 3.34 KB
/
Copy pathvisual-assets-validate.yml
File metadata and controls
101 lines (85 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Validate Visual Assets
on:
workflow_call:
inputs:
files:
description: "List of files to validate"
type: string
required: true
outputs:
report:
description: "Mardown report containing changes"
value: ${{ jobs.check.outputs.report }}
concurrency: visual-assets-${{ github.ref }}
run-name: "Validate visual assets in ${{ github.ref_name }}"
jobs:
check:
name: "Validate"
runs-on: ubuntu-latest
steps:
- name: Count files
id: count
run:
echo "number=$(echo "${{ inputs.files }}" | grep -v "^translated" | grep -v "^.github" | wc -l)" >> $GITHUB_OUTPUT
- name: Trim paths
if: steps.count.outputs.number > 0
id: paths
run: |
echo "files<<EOF" >> $GITHUB_OUTPUT
echo "${{ inputs.files }}" | grep -v "^translated" | grep -v "^.github" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Checkout
if: inputs.files == '' || steps.count.outputs.number > 0
uses: actions/checkout@v4
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
- name: 'Download markdown-figma'
if: inputs.files == '' || steps.count.outputs.number > 0
uses: MiguelDomingues/markdown-figma-action@v1.05
- name: 'Validate visual assets for changed files'
if: steps.count.outputs.number > 0
run: |
while IFS= read -r file; do
if [ -f "${file}" ]; then
echo "Run markdown-figma on ${file}.";
markdown-figma --input "${file}" --api-token ${{ secrets.FIGMA_API_TOKEN }} --export "images" --similarity ${{ vars.FIGMA_SIMILARITY_THRESHOLD }} --svg-visual-check-only --report report.md --report-append --parse-html;
else
echo "${file} does not exist."
fi
done <<< cat << EOF
${{ steps.paths.outputs.files }}
EOF
- name: Check if report exists
if: inputs.files == '' || steps.count.outputs.number > 0
id: check_files
uses: andstor/file-existence-action@v3
with:
files: 'report.md'
- name: Read report.md
if: steps.check_files.outcome == 'success' && steps.check_files.outputs.files_exists == 'true'
id: get-report
uses: juliangruber/read-file-action@v1
with:
path: ./report.md
trim: true
- name: 'Generate Report'
if: steps.check_files.outcome == 'success' && steps.check_files.outputs.files_exists == 'true' && steps.get-report.outputs.content != ''
id: generate-report
run: |
delimiter="$(openssl rand -hex 8)"
echo "body<<$delimiter" >> $GITHUB_OUTPUT
cat .github/visual-assets-pr-intro.md >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "${{ steps.get-report.outputs.content }}" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
cat .github/visual-assets-pr-outro.md >> $GITHUB_OUTPUT
echo "$delimiter" >> $GITHUB_OUTPUT
- name: 'Visual assets validation failed'
if: steps.check_files.outcome == 'success' && steps.check_files.outputs.files_exists == 'true' && steps.get-report.outputs.content != ''
uses: actions/github-script@v8
with:
script: |
core.setFailed('Validation of visual assets failed.');
outputs:
report: ${{ steps.generate-report.outputs.body || ''}}