-
Notifications
You must be signed in to change notification settings - Fork 263
113 lines (97 loc) · 3.69 KB
/
pr-checks.yml
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
102
103
104
105
106
107
108
109
110
111
112
113
name: pr-checks
on:
pull_request_target:
branches: ["main"]
workflow_dispatch:
permissions:
pull-requests: write
contents: write
jobs:
changed_files:
runs-on: ubuntu-latest
name: PR automated checks
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v42
- name: Process changed files
id: changes-errors
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo 'errorsStr<<EOF' >> $GITHUB_OUTPUT
# Filter out .yml files
FILTERED_FILES=$(echo "$ALL_CHANGED_FILES" | tr ' ' '\n' | grep -v '\.yml$' | tr '\n' ' ')
for file in $FILTERED_FILES; do
echo "Processing file: $file"
if [[ $file != images/* ]] && [[ $file != platforms/* ]] && [[ $file != chains/* ]] ;
then
errorText="Only additions of token icons (in the /images folder) or platform logos (in the /platforms folder) are permitted"
errorOutputText="- Error with \`$file\`: $errorText"
echo "::error file=$file::$errorText"
echo "$errorOutputText" >> $GITHUB_OUTPUT
fi
# Only check token icon additions, not platform icons which don't have anything automated
if [[ $file == images/assets* ]] ;
then
if [[ $file != *.png ]] ;
then
errorText="The new icon must be a PNG file"
errorOutputText="- Error with \`$file\`: $errorText"
echo "::error file=$file::$errorText"
echo "$errorOutputText" >> $GITHUB_OUTPUT
elif [[ ! $file =~ ^images/assets(-[a-z]+)*/[a-z0-9]+\.png$ ]] ;
then
errorText="The new icon's filename must be entirely lowercase"
errorOutputText="- Error with \`$file\`: $errorText"
echo "::error file=$file::$errorText"
echo "$errorOutputText" >> $GITHUB_OUTPUT
fi
fi
done
echo 'EOF' >> $GITHUB_OUTPUT
- name: Check if errors
id: check-if-errors
env:
ERRORS: ${{ steps.changes-errors.outputs.errorsStr }}
run: |
errorsStrLength=${#ERRORS}
echo "prev output : $ERRORS $errorsStrLength"
if (( errorsStrLength == 0 ));
then
echo 'hasErrors=false'
echo "hasErrors=false" >> "$GITHUB_OUTPUT"
else
echo 'hasErrors=true'
echo "hasErrors=true" >> "$GITHUB_OUTPUT"
fi
- name: Comment on PR if error
env:
ERRORS: ${{ steps.changes-errors.outputs.errorsStr }}
HAS_ERRORS: ${{ steps.check-if-errors.outputs.hasErrors }}
uses: thollander/actions-comment-pull-request@v2
if: ${{ env.HAS_ERRORS == 'true' }}
with:
message: |
Changes are required before your pull request can be reviewed:
${{ env.ERRORS }}
- name: Exit with error
env:
ERRORS: ${{ steps.changes-errors.outputs.errorsStr }}
HAS_ERRORS: ${{ steps.check-if-errors.outputs.hasErrors }}
if: ${{ env.HAS_ERRORS == 'true' }}
run: |
mapfile myarray <<< $ERRORS
for ((i = 0; i < ${#myarray[@]}; ++i)); do
echo "::error::${myarray[i]}"
done
exit 1
update_tokenlist:
uses: ./.github/workflows/upload-tokenlist.yml
needs: changed_files
if: ${{ !failure() }}
secrets: inherit